diff --git a/service/src/main/inse/patents/logic.py b/service/src/main/inse/patents/logic.py index ed9b270e..65765f1f 100644 --- a/service/src/main/inse/patents/logic.py +++ b/service/src/main/inse/patents/logic.py @@ -67,6 +67,8 @@ async def get_patents_by_author_id( if first_name and last_name: all_patents = _filter_patents_by_name(all_patents, first_name, last_name) + all_patents = _deduplicate_patents(all_patents) + await _enrich_patents_classifications(all_patents, ipc_search_client) return model.PatentsByAuthorResponse( @@ -201,6 +203,31 @@ def _filter_patents_by_name( ] +def _deduplicate_patents(patents: list[model.PatentEntry]) -> list[model.PatentEntry]: + """Remove exact duplicate hits while keeping distinct publication stages.""" + seen: set[tuple[str, str, str, str]] = set() + deduplicated: list[model.PatentEntry] = [] + + for patent in patents: + key = _patent_dedup_key(patent) + if key in seen: + continue + seen.add(key) + deduplicated.append(patent) + + return deduplicated + + +def _patent_dedup_key(patent: model.PatentEntry) -> tuple[str, str, str, str]: + stage = patent.kind or patent.application_type or "" + return ( + patent.source, + patent.patent_id, + patent.publication_date or "", + stage, + ) + + def _get_author(author_id: str) -> Author | None: short_id = author_id.replace("https://openalex.org/", "") result = person_logic.search_persons(author_id=short_id) diff --git a/service/src/main/inse/patents/test_logic.py b/service/src/main/inse/patents/test_logic.py new file mode 100644 index 00000000..6c81e218 --- /dev/null +++ b/service/src/main/inse/patents/test_logic.py @@ -0,0 +1,91 @@ +from inse.patents import logic, model + + +def _uspto_patent( + patent_id: str = "US12508845", + publication_date: str = "20251230", + application_type: str | None = None, +) -> model.PatentEntry: + return model.PatentEntry( + patent_id=patent_id, + source="USPTO", + title="Vehicle pneumatic tyre and rubber mixture for a tread", + publication_date=publication_date, + publication_year="2025", + application_type=application_type, + ) + + +def _epo_patent( + patent_id: str = "EP2867692", + publication_date: str = "20180411", + kind: str | None = None, +) -> model.PatentEntry: + return model.PatentEntry( + patent_id=patent_id, + source="EPO", + title="METHOD FOR GENERATING AND USING A MAP", + publication_date=publication_date, + publication_year="2018", + kind=kind, + ) + + +def test_deduplicate_patents_removes_exact_duplicates() -> None: + patents = [_uspto_patent(), _uspto_patent(), _uspto_patent()] + + result = logic._deduplicate_patents(patents) + + assert len(result) == 1 + assert result[0].patent_id == "US12508845" + + +def test_deduplicate_patents_keeps_distinct_publication_numbers() -> None: + patents = [_uspto_patent("US12508845"), _uspto_patent("US12303461")] + + result = logic._deduplicate_patents(patents) + + assert len(result) == 2 + assert [patent.patent_id for patent in result] == ["US12508845", "US12303461"] + + +def test_deduplicate_patents_keeps_first_occurrence_of_exact_duplicate() -> None: + first = _uspto_patent() + first.abstract = "First abstract" + duplicate = _uspto_patent() + duplicate.abstract = "Second abstract" + + result = logic._deduplicate_patents([first, duplicate]) + + assert len(result) == 1 + assert result[0].abstract == "First abstract" + + +def test_deduplicate_patents_keeps_epo_application_and_grant_stages() -> None: + application = _epo_patent(publication_date="20161005", kind="A1") + grant = _epo_patent(publication_date="20180411", kind="B1") + + result = logic._deduplicate_patents([application, grant]) + + assert len(result) == 2 + assert [patent.kind for patent in result] == ["A1", "B1"] + + +def test_deduplicate_patents_keeps_same_patent_number_with_different_dates() -> None: + earlier = _uspto_patent(publication_date="20241230") + later = _uspto_patent(publication_date="20251230") + + result = logic._deduplicate_patents([earlier, later]) + + assert len(result) == 2 + assert [patent.publication_date for patent in result] == ["20241230", "20251230"] + + +def test_deduplicate_patents_keeps_same_patent_number_with_different_uspto_types() -> None: + utility = _uspto_patent(application_type="utility") + reissue = _uspto_patent(application_type="reissue") + + result = logic._deduplicate_patents([utility, reissue]) + + assert len(result) == 2 + assert [patent.application_type for patent in result] == ["utility", "reissue"] diff --git a/webapp/src/app/modules/person-patents/person-patents.component.html b/webapp/src/app/modules/person-patents/person-patents.component.html index fe51cb23..b8389633 100644 --- a/webapp/src/app/modules/person-patents/person-patents.component.html +++ b/webapp/src/app/modules/person-patents/person-patents.component.html @@ -7,17 +7,36 @@ } @else {
{{ selectedPatent.application_number }}
-{{ formatDate(selectedPatent.application_date) }}
-{{ selectedPatent.kind }}
-{{ selectedPatent.application_type }}
-{{ selectedPatent.number_of_claims }}
-{{ selectedPatent.status }}
-{{ abstractPreview }}
+ } + + ++ Abstract, Erfinder, Anmelder und IPC/CPC-Klassifikation +
Wähle links ein Patent aus, um die Details zu sehen.
+Wähle links ein Patent aus, um Kurzinfos und Details zu sehen.
} diff --git a/webapp/src/app/modules/person-patents/person-patents.component.scss b/webapp/src/app/modules/person-patents/person-patents.component.scss index 9bce06a7..37cac10f 100644 --- a/webapp/src/app/modules/person-patents/person-patents.component.scss +++ b/webapp/src/app/modules/person-patents/person-patents.component.scss @@ -225,14 +225,47 @@ } } -.stat--clickable { +.patent-detail-preview { + margin: 14px 0 0; + font-size: 13px; + line-height: 1.55; + color: #555; +} + +.patent-detail-action { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + width: 100%; + margin-top: 16px; + padding: 12px 14px; + border: 1px solid #bdd4ff; + border-radius: 10px; + background: linear-gradient(180deg, #f8fbff 0%, #eef4ff 100%); + color: #0b63ce; + font-size: 14px; + font-weight: 600; cursor: pointer; - transition: border-color 0.15s, background 0.15s; + transition: border-color 0.15s, background 0.15s, box-shadow 0.15s; &:hover { border-color: #0b63ce; background: #f0f6ff; + box-shadow: 0 2px 8px rgba(11, 99, 206, 0.12); } + + .material-icons { + font-size: 20px; + } +} + +.patent-detail-hint { + margin: 8px 0 0; + font-size: 12px; + line-height: 1.4; + color: #888; + text-align: center; } .patent-full-detail { @@ -243,7 +276,7 @@ background: #fafafa; h3 { - margin: 0 0 16px 0; + margin: 0 0 4px 0; font-size: 16px; color: #333; line-height: 1.4; @@ -265,17 +298,40 @@ } .back-btn { - border: none; - background: none; - color: #333; + display: inline-flex; + align-items: center; + gap: 0.4rem; + + width: auto; + margin-bottom: 1rem; + padding: 0.5rem 0.85rem; + + border: 1px solid #d6e3f8; + border-radius: 999px; + + background: #f8fbff; + color: #2563eb; + + font-size: 0.9rem; + font-weight: 600; + cursor: pointer; - font-size: 14px; - font-weight: 400; - padding: 0; - align-self: flex-start; + transition: + background-color 0.15s ease, + border-color 0.15s ease, + color 0.15s ease, + box-shadow 0.15s ease; &:hover { - text-decoration: underline; + background: #eef5ff; + border-color: #bcd3f7; + color: #1d4ed8; + box-shadow: 0 1px 4px rgba(37, 99, 235, 0.12); + } + + &:focus-visible { + outline: 2px solid #93c5fd; + outline-offset: 2px; } } @@ -285,6 +341,51 @@ border-top: 1px solid #eee; } +.patent-meta { + &--inline { + margin: 12px 0 20px; + } + + &__list { + margin: 0; + border: 1px solid #e2e8f4; + border-radius: 12px; + background: linear-gradient(180deg, #fff 0%, #f8faff 100%); + box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04); + overflow: hidden; + } + + &__row { + display: grid; + grid-template-columns: minmax(130px, 38%) 1fr; + gap: 12px 16px; + align-items: center; + padding: 11px 16px; + border-top: 1px solid #eef2f8; + + &:first-child { + border-top: 0; + } + + dt { + margin: 0; + font-size: 12px; + font-weight: 500; + color: #64748b; + line-height: 1.35; + } + + dd { + margin: 0; + font-size: 14px; + font-weight: 600; + color: #1e293b; + line-height: 1.35; + word-break: break-word; + } + } +} + .tag-list { display: flex; flex-wrap: wrap; diff --git a/webapp/src/app/modules/person-patents/person-patents.component.ts b/webapp/src/app/modules/person-patents/person-patents.component.ts index fc3f86bb..e4cb9912 100644 --- a/webapp/src/app/modules/person-patents/person-patents.component.ts +++ b/webapp/src/app/modules/person-patents/person-patents.component.ts @@ -16,6 +16,12 @@ interface ClassificationCard { hierarchy: { label: string; value: string }[]; } +interface PatentMetadataRow { + label: string; + value: string; + variant?: 'source'; +} + const DESCRIPTION_PREVIEW_LENGTH = 140; @Component({ @@ -103,6 +109,11 @@ export class PersonPatentsComponent implements OnInit { this.expandedClassificationKeys.clear(); } + closeDetail(): void { + this.showDetail = false; + this.expandedClassificationKeys.clear(); + } + private applyFilter(): void { let patents = this.patents; @@ -174,6 +185,83 @@ export class PersonPatentsComponent implements OnInit { return this.patents.filter((p) => p.source === 'USPTO').length; } + trackPatent(_index: number, patent: PatentEntry): string { + return [ + patent.source, + patent.patent_id, + patent.publication_date ?? '', + patent.kind ?? patent.application_type ?? '', + ].join('|'); + } + + getAbstractPreview(abstract: string | null | undefined): string | null { + if (!abstract?.trim()) { + return null; + } + const text = abstract.trim(); + if (text.length <= 160) { + return text; + } + return `${text.slice(0, 160).trimEnd()}…`; + } + + getPublicationStageLabel(patent: PatentEntry): string | null { + if (patent.kind) { + return patent.kind; + } + if (patent.application_type) { + return patent.application_type; + } + return null; + } + + hasPatentMetadata(_patent: PatentEntry): boolean { + return true; + } + + getPatentMetadataRows(patent: PatentEntry): PatentMetadataRow[] { + const rows: PatentMetadataRow[] = []; + + rows.push({ label: 'Quelle', value: patent.source, variant: 'source' }); + rows.push({ label: 'Patent-Nr.', value: patent.patent_id }); + + if (patent.publication_date) { + rows.push({ + label: 'Veröffentlichungsdatum', + value: this.formatDate(patent.publication_date), + }); + } + if (patent.application_number) { + rows.push({ label: 'Anmeldungsnummer', value: patent.application_number }); + } + if (patent.application_date) { + rows.push({ label: 'Anmeldedatum', value: this.formatDate(patent.application_date) }); + } + + const stageLabel = this.getPublicationStageLabel(patent); + if (stageLabel) { + rows.push({ + label: patent.kind ? 'Publikationsstufe' : 'Anmeldungstyp', + value: patent.kind ? stageLabel : this.formatMetadataLabel(stageLabel), + }); + } + if (patent.number_of_claims != null) { + rows.push({ label: 'Ansprüche', value: String(patent.number_of_claims) }); + } + if (patent.status) { + rows.push({ label: 'Status', value: this.formatMetadataLabel(patent.status) }); + } + + return rows; + } + + private formatMetadataLabel(value: string): string { + return value + .replace(/_/g, ' ') + .toLowerCase() + .replace(/\b\w/g, (char) => char.toUpperCase()); + } + getClassificationCards( entries: IpcClassification[] | undefined, system: ClassificationSystem,