cambialens / lens-api-doc

10 stars 6 forks source link

Patent Claims & Description #62

Closed sherifgoma1 closed 1 year ago

sherifgoma1 commented 1 year ago

Hi -

Researching patents for the first time & having difficulty extracting patent claims & descriptions. My query returns null for these 2 fields. All other fields are fine. Any insight what I am doing incorrectly?

import requests import json

Read the API key from the file

with open("lensapikey.txt", "r") as file: api_key = file.read().strip()

Define the API endpoint

api_url = "https://api.lens.org/patent/search"

Define the search query and parameters

search_query = { "query": { "multi_match": { "query": "glucose", "fields": ["biblio.invention_title^3", "abstract", "description", "claims"] } }, "size": 5, "from": 0, "include": [ "biblio.invention_title", "biblio.application_reference", "biblio.priority_claims", "legal_status", "claims", "abstract", "description" ], "sort": [ { "created": "desc" }, { "year_published": "asc" } ], "exclude": None, "scroll": None, "scroll_id": None }

print("Starting API call...")

Make the API call

headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } response = requests.post(api_url, headers=headers, json=search_query)

Check if the request was successful

if response.status_code == 200: print("API call successful. Parsing and printing results...")

# Parse and print the results
patents_data = response.json()["data"]

if patents_data:
    for i, patent in enumerate(patents_data):
        print(f"{i+1}. {patent['biblio']['invention_title'][0]['text']}")
        print(f"   Patent ID: {patent['lens_id']}")
        print(f"   Status: {patent['legal_status']['patent_status']}")
        print(f"   Application reference: {patent['biblio']['application_reference'].get('application_reference', 'Not available')}")
        print(f"   Priority claims: {patent['biblio']['priority_claims']['claims']}")
        print(f"   Abstract: {patent['abstract'][0]['text'] if 'abstract' in patent and patent['abstract'] else 'Not available'}")
        print(f"   Description: {patent['description'][0]['text'] if 'description' in patent and patent['description'] else 'Not available'}")
        print(f"   Claims: {patent['claims'][0]['claim_text'] if 'claims' in patent and patent['claims'] else 'Not available'}")

        print()
else:
    print("No patents found.")

else: print(f"Error: {response.status_code}") print(f"Response content: {response.content}")

rosharma9 commented 1 year ago

@sherifgoma1 All the records might not have description and claims. You can filter them using has_claim and has_description in your query.