fix(patents): drop CPC/IPC topic corroboration from org_patents matching, keeping only the institution-or-personal-assignee identity check
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:
+3
-9
@@ -23,15 +23,9 @@ 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). 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.
|
||||
(`institution`, `name`, or `both`, the latter being highest confidence). An
|
||||
inventor-name match counts only if the assignee is the institution itself or the
|
||||
person themselves — this avoids pulling in unrelated patents via a shared name.
|
||||
|
||||
```bash
|
||||
python scripts/patents/index_org_patents.py --institution-id <OpenAlex-ID>
|
||||
|
||||
@@ -4,13 +4,9 @@ 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.
|
||||
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 — 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.
|
||||
"name", or "both"), deletes existing documents for the institution, and reindexes. An
|
||||
inventor-name match counts only if the assignee is the institution itself or the
|
||||
person themselves, to avoid pulling in unrelated patents via a shared name.
|
||||
|
||||
Usage:
|
||||
python scripts/patents/index_org_patents.py --institution-id <OpenAlex-ID>
|
||||
|
||||
@@ -14,8 +14,8 @@ from inse.models.openalex.author import Author
|
||||
from inse.patents.authors.identity import (
|
||||
author_institution_names,
|
||||
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
|
||||
@@ -26,12 +26,10 @@ 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,
|
||||
@@ -219,68 +217,6 @@ def org_patent_to_es_document(patent: OrgPatentEntry) -> dict:
|
||||
}
|
||||
|
||||
|
||||
MIN_CORROBORATING_TOPIC_OVERLAP = 2
|
||||
|
||||
|
||||
def primary_classification_codes(patent: PatentEntry) -> list[str]:
|
||||
"""Returns only the patent's primary IPC/CPC code(s) (marked "AFI" in the
|
||||
raw EPO/USPTO string), falling back to all codes if none are marked.
|
||||
|
||||
Patents can carry dozens of secondary/incidental classification codes
|
||||
(marked "ALI") alongside their real subject. Resolving OpenAlex topics
|
||||
from *all* of them gives some patents a huge, unfocused topic cloud —
|
||||
confirmed against a real org_patents rebuild, where a 20-code patent
|
||||
picked up 70+ unrelated topics, making a coincidental two-topic overlap
|
||||
with an unrelated same-named author far more likely than intended.
|
||||
"""
|
||||
all_codes = [*patent.ipc, *patent.cpc]
|
||||
primary = [code for code in all_codes if "AFI" in code]
|
||||
return primary or all_codes
|
||||
|
||||
|
||||
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,
|
||||
@@ -315,48 +251,18 @@ async def _search_patents_by_author(
|
||||
return []
|
||||
|
||||
# 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
|
||||
# a match only counts if the assignee is the institution itself or the
|
||||
# person themselves — a bare name match on inventors is too weak a
|
||||
# signal on its own once several same-named people are possible. 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.
|
||||
# in EPO/USPTO.
|
||||
inst_names = [institution_name] if institution_name else []
|
||||
strong_identity_matched = [
|
||||
return [
|
||||
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()
|
||||
primary_only = [
|
||||
patent.model_copy(update={
|
||||
"ipc": primary_classification_codes(patent),
|
||||
"cpc": [],
|
||||
})
|
||||
for patent in remaining
|
||||
]
|
||||
patent_topic_map = await resolver.resolve_topics_for_patents(primary_only)
|
||||
topic_matched = topic_corroborated_patents(remaining, author, patent_topic_map)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"OpenAlex topic corroboration failed for author %s",
|
||||
author_name,
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
return strong_identity_matched + topic_matched
|
||||
|
||||
|
||||
async def build_org_patents_for_institution(
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
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,
|
||||
primary_classification_codes,
|
||||
resolve_match_type,
|
||||
topic_corroborated_patents,
|
||||
)
|
||||
from inse.patents.org.model import MatchedAuthor
|
||||
|
||||
@@ -107,108 +102,3 @@ 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 _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 _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."""
|
||||
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 == []
|
||||
|
||||
|
||||
def test_primary_classification_codes_keeps_only_afi_marked_codes() -> None:
|
||||
"""A patent with many secondary ("ALI") codes alongside its one primary
|
||||
("AFI") code must only contribute the primary one — otherwise a large
|
||||
secondary-code topic cloud makes coincidental multi-topic overlaps with
|
||||
an unrelated same-named author far too easy (confirmed against a real
|
||||
org_patents rebuild: a 20-code patent picked up 70+ topics)."""
|
||||
patent = _patent("EP1")
|
||||
patent.ipc = [
|
||||
"G06V 10/776 20220101AFI20250422BHUS",
|
||||
"G01N 33/569 20060101ALI20250422BHUS",
|
||||
"G06T 5/20 20060101ALI20250422BHUS",
|
||||
]
|
||||
patent.cpc = ["G16H 30/40 20180101ALI20250422BHUS"]
|
||||
|
||||
result = primary_classification_codes(patent)
|
||||
|
||||
assert result == ["G06V 10/776 20220101AFI20250422BHUS"]
|
||||
|
||||
|
||||
def test_primary_classification_codes_falls_back_to_all_codes_without_afi_marker() -> None:
|
||||
patent = _patent("EP2")
|
||||
patent.ipc = ["G06V 10/776 20220101ALI20250422BHUS"]
|
||||
patent.cpc = ["G01N 33/569 20060101ALI20250422BHUS"]
|
||||
|
||||
result = primary_classification_codes(patent)
|
||||
|
||||
assert result == patent.ipc + patent.cpc
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user