Improve patent detail view and deduplication
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-06-23 19:26:38 +02:00
parent e476935a5d
commit e78f945f4f
5 changed files with 367 additions and 65 deletions
+27
View File
@@ -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)
@@ -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"]
@@ -7,17 +7,36 @@
} @else {
<div class="patents-container">
@if (showDetail && selectedPatent) {
<button class="back-btn" (click)="showDetail = false">
← Zurück zu den Patenten
</button>
}
<div class="patents-content">
@if (showDetail && selectedPatent) {
<div class="patent-full-detail">
<button type="button" class="back-btn" (click)="closeDetail()">
← Zurück zu den Patenten
</button>
<h3>{{ selectedPatent.title ?? selectedPatent.patent_id }}</h3>
@if (hasPatentMetadata(selectedPatent)) {
<div class="patent-meta patent-meta--inline">
<dl class="patent-meta__list">
@for (row of getPatentMetadataRows(selectedPatent); track row.label) {
<div class="patent-meta__row">
<dt>{{ row.label }}</dt>
<dd>
@if (row.variant === 'source') {
<span class="source-badge source-badge--{{ row.value.toLowerCase() }}">
{{ row.value }}
</span>
} @else {
{{ row.value }}
}
</dd>
</div>
}
</dl>
</div>
}
@if (selectedPatent.abstract) {
<div class="detail-section">
<h4>Abstract</h4>
@@ -45,7 +64,7 @@
</div>
}
@if ((selectedPatent.ipc_descriptions?.length ?? 0) > 0) {
@if (selectedPatent.ipc_descriptions.length > 0) {
<div class="detail-section classification-section classification-section--ipc">
<h4>Klassifikation (IPC)</h4>
<div class="classification-cards">
@@ -102,7 +121,7 @@
</div>
}
@if ((selectedPatent.cpc_descriptions?.length ?? 0) > 0) {
@if (selectedPatent.cpc_descriptions.length > 0) {
<div class="detail-section classification-section classification-section--cpc">
<h4>Klassifikation (CPC)</h4>
<div class="classification-cards">
@@ -159,48 +178,6 @@
</div>
}
@if (selectedPatent.application_number) {
<div class="detail-section">
<h4>Anmeldungsnummer</h4>
<p>{{ selectedPatent.application_number }}</p>
</div>
}
@if (selectedPatent.application_date) {
<div class="detail-section">
<h4>Anmeldedatum</h4>
<p>{{ formatDate(selectedPatent.application_date) }}</p>
</div>
}
@if (selectedPatent.kind) {
<div class="detail-section">
<h4>Patentart</h4>
<p>{{ selectedPatent.kind }}</p>
</div>
}
@if (selectedPatent.application_type) {
<div class="detail-section">
<h4>Anmeldungstyp</h4>
<p>{{ selectedPatent.application_type }}</p>
</div>
}
@if (selectedPatent.number_of_claims) {
<div class="detail-section">
<h4>Anzahl Ansprüche</h4>
<p>{{ selectedPatent.number_of_claims }}</p>
</div>
}
@if (selectedPatent.status) {
<div class="detail-section">
<h4>Status</h4>
<p>{{ selectedPatent.status }}</p>
</div>
}
</div>
}
@@ -232,7 +209,7 @@
</tr>
</thead>
<tbody>
@for (patent of getPagedPatents(); track patent.patent_id) {
@for (patent of getPagedPatents(); track trackPatent($index, patent)) {
<tr
[class.selected]="selectedPatent === patent"
(click)="selectPatent(patent)">
@@ -257,11 +234,11 @@
}
</div>
@if (selectedPatent) {
@if (selectedPatent && !showDetail) {
<div class="patent-detail">
<h3>{{ selectedPatent.title ?? selectedPatent.patent_id }}</h3>
<div class="detail-stats">
<div class="stat stat--clickable" (click)="openDetail()">
<div class="stat">
<span class="stat-label">Quelle</span>
<span class="stat-value">
<span class="source-badge source-badge--{{ selectedPatent.source.toLowerCase() }}">
@@ -277,7 +254,25 @@
<span class="stat-label">Datum</span>
<span class="stat-value">{{ formatDate(selectedPatent.publication_date) }}</span>
</div>
@if (getPublicationStageLabel(selectedPatent); as stageLabel) {
<div class="stat">
<span class="stat-label">Publikationsstufe</span>
<span class="stat-value">{{ stageLabel }}</span>
</div>
}
</div>
@if (getAbstractPreview(selectedPatent.abstract); as abstractPreview) {
<p class="patent-detail-preview">{{ abstractPreview }}</p>
}
<button type="button" class="patent-detail-action" (click)="openDetail()">
<span class="patent-detail-action__label">Patentdetails anzeigen</span>
<span class="material-icons" aria-hidden="true">chevron_right</span>
</button>
<p class="patent-detail-hint">
Abstract, Erfinder, Anmelder und IPC/CPC-Klassifikation
</p>
</div>
} @else {
<div class="patent-detail overview">
@@ -297,7 +292,7 @@
<span class="overview-label">USPTO</span>
</div>
</div>
<p class="overview-hint"> Wähle links ein Patent aus, um die Details zu sehen.</p>
<p class="overview-hint">Wähle links ein Patent aus, um Kurzinfos und Details zu sehen.</p>
</div>
}
</div>
@@ -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;
@@ -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,