fix(patents): disambiguate author patents with patents_openalex_keywords index
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:
@@ -32,17 +32,19 @@ def is_ambiguous_name(
|
||||
openalex_full_name_count: int | None = None,
|
||||
openalex_last_name_count: int | None = None,
|
||||
) -> bool:
|
||||
"""Decide whether a name is ambiguous using only internal project data.
|
||||
"""Decide whether a name is strictly ambiguous using internal project data.
|
||||
|
||||
A name is treated as ambiguous (and therefore handled strictly) when:
|
||||
A name is treated as strictly ambiguous when:
|
||||
- it is a mononym / cannot be parsed into given + family name, or
|
||||
- several authors in the local OpenAlex index share the exact name, or
|
||||
- many authors in the local OpenAlex index share the family name, or
|
||||
- the patent name search returns a very large number of hits.
|
||||
- several authors in the local OpenAlex index share the exact full name.
|
||||
|
||||
Ambiguous names need a strong identity signal (institution/assignee or a
|
||||
full given-name match with a matching research field) before a patent is
|
||||
attributed to the person.
|
||||
A frequent last name alone does **not** make a uniquely named author
|
||||
strictly ambiguous (``openalex_full_name_count == 1``). In that case
|
||||
personal-assignee identity can count when inventor and assignee both
|
||||
match the full OpenAlex name.
|
||||
|
||||
When the full-name count is unknown, last-name frequency and patent-hit
|
||||
volume remain as safety fallbacks.
|
||||
"""
|
||||
parsed = parse_person_name(display_name)
|
||||
if parsed is None or parsed.is_single_token:
|
||||
@@ -54,6 +56,9 @@ def is_ambiguous_name(
|
||||
):
|
||||
return True
|
||||
|
||||
if openalex_full_name_count == 1:
|
||||
return False
|
||||
|
||||
if (
|
||||
openalex_last_name_count is not None
|
||||
and openalex_last_name_count >= OPENALEX_LAST_NAME_COUNT_THRESHOLD
|
||||
@@ -105,6 +110,29 @@ def patent_institution_match(
|
||||
return False
|
||||
|
||||
|
||||
def patent_personal_assignee_full_match(
|
||||
patent: model.PatentEntry,
|
||||
display_name: str,
|
||||
) -> bool:
|
||||
"""True when a personal assignee matches the author's full given name."""
|
||||
if not display_name or not display_name.strip():
|
||||
return False
|
||||
for assignee in patent.assignees:
|
||||
if assignee and first_name_match_kind_for_person(assignee, display_name) == "full":
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def patent_full_personal_identity_match(
|
||||
patent: model.PatentEntry,
|
||||
display_name: str,
|
||||
) -> bool:
|
||||
"""Strong personal identity: full inventor name and full personal assignee."""
|
||||
if best_name_match_kind(patent, display_name) != "full":
|
||||
return False
|
||||
return patent_personal_assignee_full_match(patent, display_name)
|
||||
|
||||
|
||||
def patent_personal_assignee_match(
|
||||
patent: model.PatentEntry,
|
||||
display_name: str,
|
||||
|
||||
@@ -30,7 +30,7 @@ def test_full_name_collision_makes_name_ambiguous() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_last_name_collision_makes_name_ambiguous() -> None:
|
||||
def test_last_name_collision_makes_name_ambiguous_without_full_name_count() -> None:
|
||||
assert (
|
||||
is_ambiguous_name(
|
||||
"Christian Weber",
|
||||
@@ -43,7 +43,27 @@ def test_last_name_collision_makes_name_ambiguous() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_many_patent_hits_make_name_ambiguous() -> None:
|
||||
def test_last_name_collision_not_ambiguous_when_full_name_unique() -> None:
|
||||
assert (
|
||||
is_ambiguous_name(
|
||||
"Pedro José Marrón",
|
||||
openalex_full_name_count=1,
|
||||
openalex_last_name_count=OPENALEX_LAST_NAME_COUNT_THRESHOLD,
|
||||
patent_hit_count=PATENT_HIT_COUNT_THRESHOLD,
|
||||
)
|
||||
is False
|
||||
)
|
||||
|
||||
|
||||
def test_many_patent_hits_not_ambiguous_when_full_name_unique() -> None:
|
||||
assert (
|
||||
is_ambiguous_name(
|
||||
"Pedro José Marrón",
|
||||
openalex_full_name_count=1,
|
||||
patent_hit_count=PATENT_HIT_COUNT_THRESHOLD,
|
||||
)
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
is_ambiguous_name("Christian Weber", patent_hit_count=PATENT_HIT_COUNT_THRESHOLD)
|
||||
is True
|
||||
|
||||
@@ -11,8 +11,13 @@ from inse.patents.authors.ipc_openalex_mapping import (
|
||||
patent_topics_match_author,
|
||||
resolve_mapped_topics_for_code,
|
||||
)
|
||||
from inse.patents.authors.identity import (
|
||||
patent_full_personal_identity_match,
|
||||
patent_personal_assignee_full_match,
|
||||
)
|
||||
from inse.patents.authors.topic_filter import filter_patents_by_ipc_topic_mapping
|
||||
from inse.patents.common import model
|
||||
from inse.patents.common.parsing import patent_map_key
|
||||
|
||||
|
||||
def _author_with_topic(
|
||||
@@ -172,19 +177,12 @@ def test_filter_rejects_ambiguous_name_on_fuzzy_label_only_match() -> None:
|
||||
[tire_patent],
|
||||
author,
|
||||
is_ambiguous=True,
|
||||
patent_topic_map={"USPTO:US12508845": [spurious_cardiac]},
|
||||
patent_topic_map={patent_map_key(tire_patent): [spurious_cardiac]},
|
||||
)
|
||||
assert filtered == []
|
||||
|
||||
|
||||
def test_filter_keeps_ambiguous_name_on_legacy_ipc_subclass_match() -> None:
|
||||
custom = _custom_mapping()
|
||||
custom["subclass"]["C07K"] = mapping_module.MappedOpenAlexTopic(
|
||||
topic_id="https://openalex.org/T10158",
|
||||
topic_display_name="Cancer Immunotherapy and Biomarkers",
|
||||
ipc_level="subclass",
|
||||
ipc_symbol="C07K",
|
||||
)
|
||||
def test_filter_keeps_ambiguous_name_on_keywords_index_topic_match() -> None:
|
||||
author = _author_with_topic(
|
||||
"https://openalex.org/T10158",
|
||||
"Cancer Immunotherapy and Biomarkers",
|
||||
@@ -199,21 +197,124 @@ def test_filter_keeps_ambiguous_name_on_legacy_ipc_subclass_match() -> None:
|
||||
ipc=["C07K 14/705"],
|
||||
inventors=["Schadendorf, Dirk"],
|
||||
)
|
||||
spurious = mapping_module.MappedOpenAlexTopic(
|
||||
topic_id="https://openalex.org/T99999",
|
||||
topic_display_name="Antimicrobial Peptides and Activities",
|
||||
index_mapped = mapping_module.MappedOpenAlexTopic(
|
||||
topic_id="https://openalex.org/T10158",
|
||||
topic_display_name="Cancer Immunotherapy and Biomarkers",
|
||||
subfield_id="https://openalex.org/subfields/2705",
|
||||
field_id="https://openalex.org/fields/27",
|
||||
field_name="Medicine",
|
||||
)
|
||||
filtered = filter_patents_by_ipc_topic_mapping(
|
||||
[patent],
|
||||
author,
|
||||
is_ambiguous=True,
|
||||
mapping=custom,
|
||||
patent_topic_map={"EPO:EP1555271": [spurious]},
|
||||
patent_topic_map={patent_map_key(patent): [index_mapped]},
|
||||
)
|
||||
assert len(filtered) == 1
|
||||
|
||||
|
||||
def test_filter_rejects_ambiguous_personal_assignee_without_keywords_match() -> None:
|
||||
author = _author_with_topic(
|
||||
"https://openalex.org/T12345",
|
||||
"Millimeter-Wave Propagation and Modeling",
|
||||
subfield_id="https://openalex.org/subfields/2208",
|
||||
field_id="https://openalex.org/fields/22",
|
||||
domain_id="https://openalex.org/domains/3",
|
||||
)
|
||||
grill_patent = model.PatentEntry(
|
||||
patent_id="EP999",
|
||||
source="EPO",
|
||||
title="FIRE BASIN",
|
||||
ipc=["A47J 37/07"],
|
||||
assignees=["Kaiser, Thomas"],
|
||||
inventors=["Kaiser, Thomas"],
|
||||
)
|
||||
unrelated = mapping_module.MappedOpenAlexTopic(
|
||||
topic_id="https://openalex.org/T88888",
|
||||
topic_display_name="Food Science and Culinary Arts",
|
||||
subfield_id="https://openalex.org/subfields/1106",
|
||||
field_id="https://openalex.org/fields/11",
|
||||
field_name="Agricultural and Biological Sciences",
|
||||
)
|
||||
filtered = filter_patents_by_ipc_topic_mapping(
|
||||
[grill_patent],
|
||||
author,
|
||||
is_ambiguous=True,
|
||||
patent_topic_map={patent_map_key(grill_patent): [unrelated]},
|
||||
)
|
||||
assert filtered == []
|
||||
|
||||
|
||||
def test_filter_keeps_unique_name_on_full_personal_identity_without_topic_match() -> None:
|
||||
author = _author_with_topic(
|
||||
"https://openalex.org/T12345",
|
||||
"Energy Efficient Wireless Sensor Networks",
|
||||
subfield_id="https://openalex.org/subfields/1706",
|
||||
field_id="https://openalex.org/fields/17",
|
||||
domain_id="https://openalex.org/domains/3",
|
||||
)
|
||||
author.display_name = "Pedro José Marrón"
|
||||
patent = model.PatentEntry(
|
||||
patent_id="EP1542159",
|
||||
source="EPO",
|
||||
title="Card and reader/writer apparatus for cards",
|
||||
ipc=["G06K 19/077"],
|
||||
assignees=["Marron, Pedro José, Dr."],
|
||||
inventors=["Marron, Pedro José"],
|
||||
)
|
||||
unrelated = mapping_module.MappedOpenAlexTopic(
|
||||
topic_id="https://openalex.org/T88888",
|
||||
topic_display_name="Advanced Image Processing Techniques",
|
||||
subfield_id="https://openalex.org/subfields/1704",
|
||||
field_id="https://openalex.org/fields/17",
|
||||
field_name="Computer Science",
|
||||
)
|
||||
assert patent_full_personal_identity_match(patent, author.display_name) is True
|
||||
filtered = filter_patents_by_ipc_topic_mapping(
|
||||
[patent],
|
||||
author,
|
||||
is_ambiguous=False,
|
||||
patent_topic_map={patent_map_key(patent): [unrelated]},
|
||||
)
|
||||
assert len(filtered) == 1
|
||||
assert filtered[0].personal_assignee_match is True
|
||||
|
||||
|
||||
def test_filter_rejects_initial_only_personal_assignee_without_topic_match() -> None:
|
||||
author = _author_with_topic(
|
||||
"https://openalex.org/T12345",
|
||||
"Energy Efficient Wireless Sensor Networks",
|
||||
subfield_id="https://openalex.org/subfields/1706",
|
||||
field_id="https://openalex.org/fields/17",
|
||||
domain_id="https://openalex.org/domains/3",
|
||||
)
|
||||
author.display_name = "Pedro José Marrón"
|
||||
patent = model.PatentEntry(
|
||||
patent_id="EP999",
|
||||
source="EPO",
|
||||
title="Card reader",
|
||||
ipc=["G06K 19/077"],
|
||||
assignees=["Marron, P. J."],
|
||||
inventors=["Marron, P. J."],
|
||||
)
|
||||
unrelated = mapping_module.MappedOpenAlexTopic(
|
||||
topic_id="https://openalex.org/T88888",
|
||||
topic_display_name="Advanced Image Processing Techniques",
|
||||
subfield_id="https://openalex.org/subfields/1704",
|
||||
field_id="https://openalex.org/fields/17",
|
||||
field_name="Computer Science",
|
||||
)
|
||||
assert patent_personal_assignee_full_match(patent, author.display_name) is False
|
||||
assert patent_full_personal_identity_match(patent, author.display_name) is False
|
||||
filtered = filter_patents_by_ipc_topic_mapping(
|
||||
[patent],
|
||||
author,
|
||||
is_ambiguous=False,
|
||||
patent_topic_map={patent_map_key(patent): [unrelated]},
|
||||
)
|
||||
assert filtered == []
|
||||
|
||||
|
||||
def test_custom_mapping_table() -> None:
|
||||
custom = _custom_mapping()
|
||||
author = Author(
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
"""Filter name-matched patents using precomputed IPC/CPC → OpenAlex topic mappings."""
|
||||
"""Filter name-matched patents using IPC/CPC → OpenAlex topic mappings."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from inse.models.openalex.author import Author
|
||||
from inse.patents.authors.identity import (
|
||||
patent_full_personal_identity_match,
|
||||
patent_institution_match,
|
||||
patent_personal_assignee_match,
|
||||
)
|
||||
@@ -14,6 +15,7 @@ from inse.patents.authors.ipc_openalex_mapping import (
|
||||
load_ipc_openalex_mapping,
|
||||
mapped_topics_match_author,
|
||||
mapped_topics_match_author_for_ambiguous,
|
||||
mapped_topics_match_author_strict,
|
||||
patent_topics_match_author,
|
||||
resolve_mapped_topics_for_patent,
|
||||
)
|
||||
@@ -70,7 +72,15 @@ def filter_patents_by_ipc_topic_mapping(
|
||||
mapping=None,
|
||||
patent_topic_map: dict[str, list[MappedOpenAlexTopic]] | None = None,
|
||||
) -> list[TopicFilterResult]:
|
||||
"""Filter patents by comparing IPC/CPC codes with the author's OpenAlex topics.
|
||||
|
||||
When ``patent_topic_map`` is provided (from the ``patents_openalex_keywords``
|
||||
index via :class:`PatentOpenAlexMappingResolver`), that mapping is the primary
|
||||
signal: patents must share a topic or subfield with the author, unless the
|
||||
assignee matches one of the author's institutions.
|
||||
"""
|
||||
table = mapping if mapping is not None else load_ipc_openalex_mapping()
|
||||
using_keywords_index = patent_topic_map is not None
|
||||
institution_names = [
|
||||
name
|
||||
for institution in author.last_known_institutions or []
|
||||
@@ -87,17 +97,31 @@ def filter_patents_by_ipc_topic_mapping(
|
||||
for patent in patents:
|
||||
institution_match = patent_institution_match(patent, institution_names)
|
||||
personal_assignee_match = patent_personal_assignee_match(patent, display_name)
|
||||
strong_identity = institution_match or personal_assignee_match
|
||||
if using_keywords_index:
|
||||
if is_ambiguous:
|
||||
strong_identity = institution_match
|
||||
else:
|
||||
strong_identity = institution_match or patent_full_personal_identity_match(
|
||||
patent,
|
||||
display_name,
|
||||
)
|
||||
else:
|
||||
strong_identity = institution_match or personal_assignee_match
|
||||
|
||||
mapped_topics = _resolve_patent_topics(patent, table, patent_topic_map)
|
||||
if is_ambiguous:
|
||||
|
||||
if using_keywords_index:
|
||||
matched_via_mapping = mapped_topics_match_author_strict(
|
||||
mapped_topics,
|
||||
author,
|
||||
)
|
||||
elif is_ambiguous:
|
||||
matched_via_mapping = mapped_topics_match_author_for_ambiguous(
|
||||
patent,
|
||||
author,
|
||||
mapped_topics,
|
||||
table,
|
||||
)
|
||||
elif patent_topic_map is not None:
|
||||
matched_via_mapping = mapped_topics_match_author(mapped_topics, author)
|
||||
else:
|
||||
matched_via_mapping = patent_topics_match_author(patent, author, table)
|
||||
|
||||
@@ -113,17 +137,22 @@ def filter_patents_by_ipc_topic_mapping(
|
||||
)
|
||||
continue
|
||||
|
||||
if is_ambiguous:
|
||||
if matched_via_mapping:
|
||||
filtered.append(
|
||||
TopicFilterResult(
|
||||
patent=patent,
|
||||
decision="keep",
|
||||
matched_via_mapping=True,
|
||||
institution_match=False,
|
||||
personal_assignee_match=False,
|
||||
)
|
||||
if matched_via_mapping:
|
||||
filtered.append(
|
||||
TopicFilterResult(
|
||||
patent=patent,
|
||||
decision="keep",
|
||||
matched_via_mapping=True,
|
||||
institution_match=False,
|
||||
personal_assignee_match=False,
|
||||
)
|
||||
)
|
||||
continue
|
||||
|
||||
if using_keywords_index:
|
||||
continue
|
||||
|
||||
if is_ambiguous:
|
||||
continue
|
||||
|
||||
if _topic_conflict(mapped_topics, author):
|
||||
|
||||
Reference in New Issue
Block a user