feat(patents): corroborate ambiguous inventor-name matches via shared OpenAlex topics
LocationBasedServices/smartguide/pipeline/pr-dev There was a failure building this commit
LocationBasedServices/smartguide/pipeline/pr-dev There was a failure building this commit
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+4
-1
@@ -25,7 +25,10 @@ OpenAlex authors, searches EPO/USPTO for patents matched via institution assigne
|
||||
and/or inventor name, and reindexes. Each patent is tagged with a `match_type`
|
||||
(`institution`, `name`, or `both`, the latter being highest confidence). For common
|
||||
inventor names, a name match is only kept if the assignee is the institution itself or
|
||||
the person, to avoid pulling in unrelated patents via a shared name.
|
||||
the person, or if the patent's IPC/CPC-derived OpenAlex topics share at least two exact
|
||||
topic IDs with the author's own research topics — a single shared topic isn't reliable
|
||||
enough, since broad, common topics coincidentally show up on unrelated patents and
|
||||
profiles alike. This avoids pulling in unrelated patents via a shared name.
|
||||
|
||||
```bash
|
||||
python scripts/index_org_patents.py --institution-id <OpenAlex-ID>
|
||||
|
||||
@@ -4,7 +4,10 @@ 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.
|
||||
"name", or "both"), deletes existing documents for the institution, and reindexes. For
|
||||
common inventor names, a name match is only kept with institution/assignee evidence or
|
||||
at least two shared OpenAlex topic IDs between the patent (via IPC/CPC) and the
|
||||
author's own research topics.
|
||||
|
||||
Usage:
|
||||
python scripts/index_org_patents.py --institution-id <OpenAlex-ID>
|
||||
|
||||
@@ -17,6 +17,7 @@ from inse.patents.authors.identity import (
|
||||
patent_institution_match,
|
||||
patent_personal_assignee_match,
|
||||
)
|
||||
from inse.patents.authors.ipc_openalex_mapping import normalize_openalex_id
|
||||
from inse.patents.authors.name_matching import filter_patents_by_author_name
|
||||
from inse.patents.common.elastic_search_client import MissingApiKeyError
|
||||
from inse.patents.common.model import PatentEntry
|
||||
@@ -27,10 +28,12 @@ from inse.patents.common.parsing import (
|
||||
parse_epo_hits,
|
||||
parse_uspto_hits,
|
||||
patent_dedup_key,
|
||||
patent_map_key,
|
||||
)
|
||||
from inse.patents.institutions.logic import get_patents_by_institution_id
|
||||
from inse.patents.ipc_search_client import IpcSearchClient
|
||||
from inse.patents.patents_openalex_keywords.client import PatentsOpenAlexKeywordsClient
|
||||
from inse.patents.patents_openalex_keywords.resolver import PatentOpenAlexMappingResolver
|
||||
from inse.patents.org.elastic_search_client import (
|
||||
OrgPatentsSearchClient,
|
||||
fetch_authors_by_institution_name,
|
||||
@@ -218,6 +221,52 @@ def org_patent_to_es_document(patent: OrgPatentEntry) -> dict:
|
||||
}
|
||||
|
||||
|
||||
MIN_CORROBORATING_TOPIC_OVERLAP = 2
|
||||
|
||||
|
||||
def topic_corroborated_patents(
|
||||
patents: list[PatentEntry],
|
||||
author: Author,
|
||||
patent_topic_map: dict[str, list],
|
||||
) -> list[PatentEntry]:
|
||||
"""Keeps only patents whose IPC/CPC-derived OpenAlex topics share at
|
||||
least MIN_CORROBORATING_TOPIC_OVERLAP exact topic IDs with the author's
|
||||
own research topics — used to disambiguate common inventor names where
|
||||
institution/self-assignee matching alone isn't enough.
|
||||
|
||||
Requiring a single shared topic ID was still too loose: broad,
|
||||
genuinely common topics (e.g. "Image Processing Techniques") show up on
|
||||
many unrelated patents *and* on many unrelated researchers' profiles, so
|
||||
one coincidental overlap doesn't mean much (confirmed against a real
|
||||
org_patents rebuild: match_type=name patents still ballooned to ~2000).
|
||||
Two independent topic overlaps happening by chance is far less likely,
|
||||
while a patent genuinely invented by the author would typically share
|
||||
more than one topic with their own body of work. If the author has no
|
||||
topic profile at all, there is nothing to corroborate against.
|
||||
"""
|
||||
author_topic_ids = {
|
||||
normalize_openalex_id(topic.id)
|
||||
for topic in (author.topics or [])
|
||||
if topic.id
|
||||
}
|
||||
author_topic_ids.discard(None)
|
||||
if not author_topic_ids:
|
||||
return []
|
||||
|
||||
kept: list[PatentEntry] = []
|
||||
for patent in patents:
|
||||
mapped_topics = patent_topic_map.get(patent_map_key(patent), [])
|
||||
patent_topic_ids = {
|
||||
normalize_openalex_id(topic.topic_id)
|
||||
for topic in mapped_topics
|
||||
if topic.topic_id
|
||||
}
|
||||
patent_topic_ids.discard(None)
|
||||
if len(patent_topic_ids & author_topic_ids) >= MIN_CORROBORATING_TOPIC_OVERLAP:
|
||||
kept.append(patent)
|
||||
return kept
|
||||
|
||||
|
||||
async def _search_patents_by_author(
|
||||
author: Author,
|
||||
institution_name: str | None,
|
||||
@@ -273,13 +322,34 @@ async def _search_patents_by_author(
|
||||
if is_ambiguous:
|
||||
# Common names (Zhang, Li, Wang): only keep if the assignee matches the
|
||||
# institution we're building this index for (not any institution from
|
||||
# the author's whole affiliation history) or the person themselves.
|
||||
# the author's whole affiliation history), the person themselves, or
|
||||
# their own OpenAlex research topics share at least
|
||||
# MIN_CORROBORATING_TOPIC_OVERLAP exact topic IDs with the patent's
|
||||
# IPC/CPC-derived topics.
|
||||
inst_names = [institution_name] if institution_name else []
|
||||
return [
|
||||
strong_identity_matched = [
|
||||
p for p in name_matched
|
||||
if patent_institution_match(p, inst_names)
|
||||
or patent_personal_assignee_match(p, author_name)
|
||||
]
|
||||
matched_keys = {patent_dedup_key(p) for p in strong_identity_matched}
|
||||
remaining = [p for p in name_matched if patent_dedup_key(p) not in matched_keys]
|
||||
if not remaining:
|
||||
return strong_identity_matched
|
||||
|
||||
topic_matched: list[PatentEntry] = []
|
||||
try:
|
||||
resolver = PatentOpenAlexMappingResolver()
|
||||
patent_topic_map = await resolver.resolve_topics_for_patents(remaining)
|
||||
topic_matched = topic_corroborated_patents(remaining, author, patent_topic_map)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"OpenAlex topic corroboration failed for ambiguous name %s",
|
||||
author_name,
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
return strong_identity_matched + topic_matched
|
||||
else:
|
||||
return name_matched
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
from inse.models.openalex.author import Author
|
||||
from inse.models.openalex.work_topic import WorkTopic
|
||||
from inse.patents.authors.ipc_openalex_mapping import MappedOpenAlexTopic
|
||||
from inse.patents.common.model import PatentEntry
|
||||
from inse.patents.common.parsing import patent_map_key
|
||||
from inse.patents.org.logic import (
|
||||
merge_org_patents,
|
||||
org_patent_document_id,
|
||||
resolve_match_type,
|
||||
topic_corroborated_patents,
|
||||
)
|
||||
from inse.patents.org.model import MatchedAuthor
|
||||
from inse.models.openalex.author import Author
|
||||
|
||||
|
||||
def _patent(
|
||||
@@ -27,6 +31,14 @@ def _author(author_id: str, name: str) -> Author:
|
||||
)
|
||||
|
||||
|
||||
def _author_with_topics(author_id: str, name: str, topic_ids: list[str]) -> Author:
|
||||
return Author(
|
||||
id=f"https://openalex.org/{author_id}",
|
||||
display_name=name,
|
||||
topics=[WorkTopic(id=tid, display_name=f"Topic {tid}") for tid in topic_ids],
|
||||
)
|
||||
|
||||
|
||||
def test_resolve_match_type() -> None:
|
||||
assert resolve_match_type(True, True) == "both"
|
||||
assert resolve_match_type(True, False) == "institution"
|
||||
@@ -102,3 +114,71 @@ def test_org_patent_document_id_is_stable() -> None:
|
||||
doc_id = org_patent_document_id("I62318514", patent)
|
||||
|
||||
assert doc_id == "I62318514_EPO_EP1234567_20240101_A1"
|
||||
|
||||
|
||||
def _mapped_topics(*topic_ids: str) -> list[MappedOpenAlexTopic]:
|
||||
return [
|
||||
MappedOpenAlexTopic(topic_id=tid, topic_display_name=f"Topic {tid}")
|
||||
for tid in topic_ids
|
||||
]
|
||||
|
||||
|
||||
def test_topic_corroborated_patents_keeps_two_overlapping_topics() -> None:
|
||||
author = _author_with_topics(
|
||||
"A123", "Wei Zhang",
|
||||
["https://openalex.org/T1", "https://openalex.org/T2"],
|
||||
)
|
||||
patent = _patent("EP1")
|
||||
patent_topic_map = {
|
||||
patent_map_key(patent): _mapped_topics(
|
||||
"https://openalex.org/T1", "https://openalex.org/T2", "https://openalex.org/T3"
|
||||
),
|
||||
}
|
||||
|
||||
result = topic_corroborated_patents([patent], author, patent_topic_map)
|
||||
|
||||
assert result == [patent]
|
||||
|
||||
|
||||
def test_topic_corroborated_patents_drops_single_coincidental_overlap() -> None:
|
||||
"""A single shared topic isn't enough — broad, common topics show up on
|
||||
many unrelated patents and profiles by coincidence. Confirmed against a
|
||||
real org_patents rebuild where single-topic matching still let through
|
||||
~2000 mostly-unrelated "name"-matched patents."""
|
||||
author = _author_with_topics(
|
||||
"A123", "Xin Wang",
|
||||
["https://openalex.org/T1", "https://openalex.org/T9"],
|
||||
)
|
||||
patent = _patent("EP2")
|
||||
patent_topic_map = {
|
||||
patent_map_key(patent): _mapped_topics(
|
||||
"https://openalex.org/T1", "https://openalex.org/T2", "https://openalex.org/T3"
|
||||
),
|
||||
}
|
||||
|
||||
result = topic_corroborated_patents([patent], author, patent_topic_map)
|
||||
|
||||
assert result == []
|
||||
|
||||
|
||||
def test_topic_corroborated_patents_drops_patent_without_mapped_topics() -> None:
|
||||
author = _author_with_topics("A123", "Wei Zhang", ["https://openalex.org/T1"])
|
||||
patent = _patent("EP3")
|
||||
|
||||
result = topic_corroborated_patents([patent], author, {})
|
||||
|
||||
assert result == []
|
||||
|
||||
|
||||
def test_topic_corroborated_patents_rejects_everything_without_author_topic_profile() -> None:
|
||||
author = Author(id="https://openalex.org/A999", display_name="Wei Zhang")
|
||||
patent = _patent("EP4")
|
||||
patent_topic_map = {
|
||||
patent_map_key(patent): _mapped_topics(
|
||||
"https://openalex.org/T1", "https://openalex.org/T2"
|
||||
),
|
||||
}
|
||||
|
||||
result = topic_corroborated_patents([patent], author, patent_topic_map)
|
||||
|
||||
assert result == []
|
||||
|
||||
Reference in New Issue
Block a user