From 807a32eb5aa01f12f3b3149bddddb8c384527eca Mon Sep 17 00:00:00 2001 From: Khuder Khalti Date: Fri, 17 Jul 2026 00:03:18 +0200 Subject: [PATCH] fix(patents): fix moved script's path resolution and stop gating org_patents identity checks behind the now-loosened is_ambiguous_name so a locally-unique name can't bypass institution/topic verification Co-Authored-By: Claude Sonnet 5 --- service/README.md | 21 ++++----- service/scripts/patents/index_org_patents.py | 23 +++++----- service/src/main/inse/patents/org/logic.py | 47 ++++++-------------- 3 files changed, 36 insertions(+), 55 deletions(-) diff --git a/service/README.md b/service/README.md index 5785d883..6cdeceaf 100644 --- a/service/README.md +++ b/service/README.md @@ -23,23 +23,24 @@ Run tests: `./gradlew :service:test` Builds the `org_patents` Elasticsearch index for a given institution: fetches its OpenAlex authors, searches EPO/USPTO for patents matched via institution assignee and/or inventor name, and reindexes. Each patent is tagged with a `match_type` -(`institution`, `name`, or `both`, the latter being highest confidence). For rare enough -names, an inventor-name match counts on its own. For common names (shared by several -real people in OpenAlex), a match counts outright only if the assignee is the -institution itself; everything else matched on name alone — a personal-assignee match -or a third-party assignee (e.g. an industry partner on a co-invented patent) — only -counts if the patent's primary IPC/CPC classification also maps to OpenAlex research -topics that appear on the author's own profile — since first/last names collide across -many real people, this confirms the patent's subject matter actually matches theirs. +(`institution`, `name`, or `both`, the latter being highest confidence). Every +inventor-name match counts outright only if the assignee is the institution itself; +everything else matched on name alone — a personal-assignee match or a third-party +assignee (e.g. an industry partner on a co-invented patent) — only counts if the +patent's primary IPC/CPC classification also maps to OpenAlex research topics that +appear on the author's own profile. This applies regardless of how common the name +looks in our local OpenAlex data — a name can appear unique there while still being +common globally in EPO/USPTO, so a bare name match alone is never a strong enough +signal on its own. ```bash -python scripts/index_org_patents.py --institution-id +python scripts/patents/index_org_patents.py --institution-id ``` **Example — University of Duisburg-Essen:** ```bash -python scripts/index_org_patents.py --institution-id I62318514 +python scripts/patents/index_org_patents.py --institution-id I62318514 ``` The OpenAlex institution ID appears in the app URL, e.g. `/institution/I62318514/overview`. diff --git a/service/scripts/patents/index_org_patents.py b/service/scripts/patents/index_org_patents.py index 7aa2bf28..21023ca2 100644 --- a/service/scripts/patents/index_org_patents.py +++ b/service/scripts/patents/index_org_patents.py @@ -4,19 +4,19 @@ index_org_patents.py — Build the org_patents Elasticsearch index for one insti 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. For -rare enough names, an inventor-name match counts on its own. For common names, a match -counts outright only if the assignee is the institution itself; everything else -matched on name alone (a personal-assignee match or a third-party assignee) only +"name", or "both"), deletes existing documents for the institution, and reindexes. +Every inventor-name match counts outright only if the assignee is the institution +itself; everything else (a personal-assignee match or a third-party assignee) only counts if the patent's primary IPC/CPC classification also maps to OpenAlex research -topics that appear on the author's own profile — since first/last names collide across -many real people, to avoid pulling in unrelated patents via a shared name. +topics that appear on the author's own profile — applied regardless of how common the +name looks in our local OpenAlex data, since a name can appear unique there while +still being common globally in EPO/USPTO. Usage: - python scripts/index_org_patents.py --institution-id + python scripts/patents/index_org_patents.py --institution-id Example (University of Duisburg-Essen): - python scripts/index_org_patents.py --institution-id I62318514 + python scripts/patents/index_org_patents.py --institution-id 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 @@ -33,11 +33,12 @@ import sys from pathlib import Path current_dir = Path(__file__).resolve().parent -sys.path.insert(0, str(current_dir.parent / "src" / "main")) +service_dir = current_dir.parent.parent +sys.path.insert(0, str(service_dir / "src" / "main")) from dotenv import load_dotenv -load_dotenv(dotenv_path=current_dir.parent / "src" / "main" / "inse" / ".env") +load_dotenv(dotenv_path=service_dir / "src" / "main" / "inse" / ".env") from inse.patents.org.logic import index_org_patents_for_institution @@ -49,7 +50,7 @@ async def main() -> None: parser = argparse.ArgumentParser( description="Build the org_patents index for one institution.", formatter_class=argparse.RawDescriptionHelpFormatter, - epilog="Example: python scripts/index_org_patents.py --institution-id I62318514", + epilog="Example: python scripts/patents/index_org_patents.py --institution-id I62318514", ) parser.add_argument( "--institution-id", diff --git a/service/src/main/inse/patents/org/logic.py b/service/src/main/inse/patents/org/logic.py index d2d5d3d0..561ae554 100644 --- a/service/src/main/inse/patents/org/logic.py +++ b/service/src/main/inse/patents/org/logic.py @@ -13,7 +13,6 @@ from inse.institutions.institutions_search_client import InstitutionsSearchClien from inse.models.openalex.author import Author from inse.patents.authors.identity import ( author_institution_names, - is_ambiguous_name, patent_institution_match, ) from inse.patents.authors.ipc_openalex_mapping import normalize_openalex_id @@ -311,43 +310,23 @@ async def _search_patents_by_author( patents = parse_epo_hits(epo_data) + parse_uspto_hits(uspto_data) patents = deduplicate_patents(patents) - patent_hit_count = len(patents) name_matched = filter_patents_by_author_name(patents, author_name) if not name_matched: return [] - from inse.persons import logic as person_logic - from inse.patents.authors.name_variants import parse_person_name - - full_name_count = await person_logic.count_authors_by_display_name(author_name) - parsed_for_last = parse_person_name(author_name) - last_name_count: int | None = None - if parsed_for_last and not parsed_for_last.is_single_token: - last_name_count = await person_logic.count_authors_by_last_name( - parsed_for_last.last_name - ) - is_ambiguous = is_ambiguous_name( - author_name, - patent_hit_count=patent_hit_count, - openalex_full_name_count=full_name_count, - openalex_last_name_count=last_name_count, - ) - - if not is_ambiguous: - # A rare enough name that a bare inventor-field match is already a - # reliable signal — no other same-named person is realistically - # going to show up in the search results. - return name_matched - - # Common names (Zhang, Li, Wang): the institution itself being the - # assignee is the only unambiguous case — accepted outright. Everything - # else matched on name alone, including a personal-assignee match - # (several different same-named people could each be listed as their - # own patent's assignee) or a third-party assignee (e.g. an industry - # partner on a co-invented patent — the normal case for academic - # patents, not a red flag by itself), only counts if the patent's - # IPC/CPC-derived OpenAlex topics also overlap with the author's own - # research topics. + # Applied to every name-based hit, not gated behind an ambiguity check: + # the institution itself being the assignee is the only unambiguous + # case — accepted outright. Everything else matched on name alone, + # including a personal-assignee match (several different same-named + # people could each be listed as their own patent's assignee) or a + # third-party assignee (e.g. an industry partner on a co-invented + # patent — the normal case for academic patents, not a red flag by + # itself), only counts if the patent's IPC/CPC-derived OpenAlex topics + # also overlap with the author's own research topics. This + # intentionally does not rely on is_ambiguous_name: a name can look + # unique in our local OpenAlex slice while still being common globally + # in EPO/USPTO, so a bare name-on-inventor match alone is never a + # strong enough signal on its own. inst_names = [institution_name] if institution_name else [] strong_identity_matched = [ p for p in name_matched -- 2.56.1