fix(patents): correct author-institution query and name-matching ambiguity checks for org_patents
LocationBasedServices/smartguide/pipeline/pr-dev There was a failure building this commit
LocationBasedServices/smartguide/pipeline/pr-dev There was a failure building this commit
This commit is contained in:
@@ -2,53 +2,21 @@
|
||||
"""
|
||||
index_org_patents.py — Build the org_patents Elasticsearch index for one institution.
|
||||
|
||||
What this script does
|
||||
---------------------
|
||||
1. Fetches all authors affiliated with the given institution from OpenAlex.
|
||||
2. Searches EPO and USPTO for patents assigned to the institution (institution match).
|
||||
3. Searches EPO and USPTO for patents where an author's name appears as inventor (name match).
|
||||
4. Merges both result sets, deduplicates, and assigns a match_type per patent:
|
||||
- "institution" — found via the institution assignee field only
|
||||
- "name" — found via author name matching only
|
||||
- "both" — found by both methods (highest confidence)
|
||||
5. Deletes any existing org_patents documents for this institution in Elasticsearch.
|
||||
6. Bulk-indexes the new documents into the `org_patents` index.
|
||||
|
||||
Usage
|
||||
-----
|
||||
Run from the smartguide/service directory:
|
||||
Fetches all OpenAlex authors affiliated with the institution, searches EPO/USPTO for
|
||||
patents matched via institution assignee and/or author name (match_type: "institution",
|
||||
"name", or "both"), deletes existing documents for the institution, and reindexes.
|
||||
|
||||
Usage:
|
||||
python scripts/index_org_patents.py --institution-id <OpenAlex-ID>
|
||||
|
||||
Example (University of Duisburg-Essen):
|
||||
|
||||
python scripts/index_org_patents.py --institution-id I62318514
|
||||
|
||||
The OpenAlex institution ID can be found in the app URL when browsing an institution,
|
||||
e.g. /institution/I62318514/overview → ID is I62318514.
|
||||
Requires src/main/inse/.env with PATENT_ELASTICSEARCH_URL/API_KEY (and OpenAlex ES
|
||||
credentials for author lookup). Runtime scales with author count (~30-40 min for UDE's
|
||||
4,740 authors). Re-running is safe: existing documents are deleted before reindexing.
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
- A .env file must exist at src/main/inse/.env with:
|
||||
PATENT_ELASTICSEARCH_URL=...
|
||||
PATENT_ELASTICSEARCH_API_KEY=...
|
||||
OPENALEX_ELASTICSEARCH_URL=... (or equivalent, for author lookups)
|
||||
- The EPO and USPTO Elasticsearch indices (epo_index_1.0, uspto_patents_3.0) must be reachable.
|
||||
|
||||
Runtime
|
||||
-------
|
||||
For the University of Duisburg-Essen (~76,000 patents, ~500 authors) this takes
|
||||
roughly 10–30 minutes depending on network speed and Elasticsearch performance.
|
||||
Smaller institutions finish in a few minutes.
|
||||
|
||||
Re-running the script is safe: existing documents for the institution are deleted
|
||||
before the new ones are indexed (full re-index).
|
||||
|
||||
Future plans
|
||||
------------
|
||||
This script is intended to be integrated into an Admin Panel in a later sprint,
|
||||
so that organisation admins can trigger the indexing as a background job via the UI.
|
||||
For now it must be run manually on the server or locally with VPN access.
|
||||
Future: integrate into an Admin Panel so admins can trigger this via the UI.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
Reference in New Issue
Block a user