added patent linking from projects to patents page
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Business logic for global patent listing."""
|
||||
import asyncio
|
||||
|
||||
from datetime import datetime
|
||||
import httpx
|
||||
from fastapi import HTTPException
|
||||
from starlette.status import HTTP_404_NOT_FOUND
|
||||
@@ -19,6 +19,10 @@ from inse.patents.ipc_search_client import IpcSearchClient
|
||||
from inse.patents.search_client import PatentSearchClient
|
||||
|
||||
|
||||
|
||||
def normalize_patent_date(date_str: str) -> str:
|
||||
return datetime.strptime(date_str.strip(), "%Y-%m-%d").strftime("%Y%m%d")
|
||||
|
||||
async def get_all_patents(
|
||||
page: int = 0,
|
||||
size: int = 10,
|
||||
@@ -85,58 +89,49 @@ async def get_all_patents(
|
||||
patents=patents,
|
||||
)
|
||||
|
||||
|
||||
def _parse_patent_id(patent_id: str) -> tuple[str, str]:
|
||||
normalized = patent_id.strip().upper()
|
||||
if normalized.startswith("EP"):
|
||||
return "EPO", normalized.removeprefix("EP")
|
||||
if normalized.startswith("US"):
|
||||
return "USPTO", normalized.removeprefix("US")
|
||||
raise HTTPException(
|
||||
status_code=HTTP_404_NOT_FOUND,
|
||||
detail="Patent not found.",
|
||||
)
|
||||
|
||||
|
||||
async def _search_by_id(
|
||||
client: AllPatentsSearchClient,
|
||||
patent_id: str,
|
||||
prefix: str | None = None,
|
||||
filling_date: str | None = None
|
||||
) -> list[model.PatentEntry]:
|
||||
try:
|
||||
source, number = _parse_patent_id(patent_id)
|
||||
except HTTPException:
|
||||
return []
|
||||
|
||||
if source == "EPO":
|
||||
data = await client.search_epo(client.epo_detail_query(number))
|
||||
return parse_epo_hits(data)
|
||||
data = await client.search_uspto(client.uspto_detail_query(number))
|
||||
return parse_uspto_hits(data)
|
||||
if prefix == "US":
|
||||
data = await client.search_uspto(client.uspto_detail_query(patent_id, filling_date=filling_date))
|
||||
return parse_uspto_hits(data)
|
||||
data = await client.search_epo(client.epo_detail_query(patent_id, filling_date=filling_date))
|
||||
return parse_epo_hits(data)
|
||||
|
||||
|
||||
async def _search_by_title(
|
||||
client: AllPatentsSearchClient,
|
||||
title: str,
|
||||
prefix: str | None = None,
|
||||
filling_date: str | None = None
|
||||
) -> list[model.PatentEntry]:
|
||||
epo_data, uspto_data = await asyncio.gather(
|
||||
client.search_epo(client.epo_title_query(title)),
|
||||
client.search_uspto(client.uspto_title_query(title)),
|
||||
client.search_epo(client.epo_title_query(title, filling_date=filling_date)),
|
||||
client.search_uspto(client.uspto_title_query(title,filling_date=filling_date)),
|
||||
)
|
||||
return parse_epo_hits(epo_data) + parse_uspto_hits(uspto_data)
|
||||
|
||||
|
||||
async def get_patent_by_id(
|
||||
patent_id: str,
|
||||
title: str | None = None,
|
||||
prefix: str | None = None,
|
||||
filling_date: str | None = None,
|
||||
ipc_client: IpcSearchClient | None = None,
|
||||
) -> model.PatentEntry:
|
||||
all_patents_client = AllPatentsSearchClient()
|
||||
ipc_search_client = ipc_client or IpcSearchClient()
|
||||
|
||||
if filling_date:
|
||||
filling_date = normalize_patent_date(filling_date)
|
||||
try:
|
||||
patents = await _search_by_id(all_patents_client, patent_id)
|
||||
patents = await _search_by_id(all_patents_client, patent_id,prefix=prefix, filling_date=filling_date)
|
||||
|
||||
if not patents:
|
||||
patents = await _search_by_title(all_patents_client, patent_id)
|
||||
patents = await _search_by_title(all_patents_client, title,prefix=prefix,filling_date=filling_date) if title else []
|
||||
|
||||
if not patents:
|
||||
raise HTTPException(
|
||||
|
||||
@@ -41,5 +41,5 @@ async def get_all_patents(
|
||||
response_model=model.PatentEntry,
|
||||
summary="Get a single patent by its identifier.",
|
||||
)
|
||||
async def get_patent_by_id(patent_id: str):
|
||||
return await logic.get_patent_by_id(patent_id)
|
||||
async def get_patent_by_id(patent_id: str, title: str | None = None, prefix: str | None = None, filling_date: str | None = None):
|
||||
return await logic.get_patent_by_id(patent_id, title=title, prefix=prefix, filling_date=filling_date)
|
||||
@@ -94,7 +94,10 @@ class AllPatentsSearchClient:
|
||||
],
|
||||
"query": query,
|
||||
}
|
||||
|
||||
|
||||
def remove_year(self, patent_id: str) -> str:
|
||||
return patent_id[4:].strip()
|
||||
def uspto_query(
|
||||
self,
|
||||
page: int = 0,
|
||||
@@ -154,7 +157,21 @@ class AllPatentsSearchClient:
|
||||
"query": query,
|
||||
}
|
||||
|
||||
def epo_detail_query(self, doc_number: str) -> dict[str, Any]:
|
||||
def epo_detail_query(self, doc_number: str,filling_date: str | None = None) -> dict[str, Any]:
|
||||
query: dict[str, Any] = {
|
||||
"bool": {
|
||||
"should": [
|
||||
{"term": {"doc_number": doc_number}},
|
||||
{"term": {"doc_number": self.remove_year(doc_number)}},
|
||||
{"term": {"application_number": self.remove_year(doc_number)}},
|
||||
{"term": {"application_number": doc_number}},
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
}
|
||||
if filling_date:
|
||||
query["bool"]["must"] = [{"term": {"application_filing_date": filling_date}}]
|
||||
|
||||
return {
|
||||
"size": 1,
|
||||
"_source": [
|
||||
@@ -163,18 +180,24 @@ class AllPatentsSearchClient:
|
||||
"application_filing_date", "title_en", "title_de",
|
||||
"abstract", "inventors_name", "applicants_name", "ipc", "cpc",
|
||||
],
|
||||
"query": {
|
||||
"bool": {
|
||||
"should": [
|
||||
{"term": {"doc_number": doc_number}},
|
||||
{"term": {"application_number": doc_number}},
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
},
|
||||
"query": query,
|
||||
}
|
||||
|
||||
def uspto_detail_query(self, number: str) -> dict[str, Any]:
|
||||
def uspto_detail_query(self, number: str,filling_date: str | None = None) -> dict[str, Any]:
|
||||
query: dict[str, Any] = {
|
||||
"bool": {
|
||||
"should": [
|
||||
{"term": {"publication_number": number}},
|
||||
{"term": {"publication_number": self.remove_year(number)}},
|
||||
{"term": {"application_number": number}},
|
||||
{"term": {"application_number": self.remove_year(number)}},
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
}
|
||||
if filling_date:
|
||||
query["bool"]["must"] = [{"term": {"application_date": filling_date}}]
|
||||
|
||||
return {
|
||||
"size": 1,
|
||||
"_source": [
|
||||
@@ -183,18 +206,22 @@ class AllPatentsSearchClient:
|
||||
"application_type", "title", "abstract", "inventors_names",
|
||||
"assignees_orgs", "ipcr", "cpc", "number_of_claims", "status",
|
||||
],
|
||||
"query": {
|
||||
"bool": {
|
||||
"should": [
|
||||
{"term": {"publication_number": number}},
|
||||
{"term": {"application_number": number}},
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
},
|
||||
"query": query,
|
||||
}
|
||||
|
||||
def epo_title_query(self, title: str) -> dict[str, Any]:
|
||||
def epo_title_query(self, title: str,filling_date: str | None = None) -> dict[str, Any]:
|
||||
query: dict[str, Any] = {
|
||||
"bool": {
|
||||
"should": [
|
||||
{"match_phrase": {"title_en": title}},
|
||||
{"match_phrase": {"title_de": title}},
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
}
|
||||
if filling_date:
|
||||
query["bool"]["must"] = [{"term": {"application_filing_date": filling_date}}]
|
||||
|
||||
return {
|
||||
"size": 1,
|
||||
"_source": [
|
||||
@@ -203,18 +230,19 @@ class AllPatentsSearchClient:
|
||||
"application_filing_date", "title_en", "title_de",
|
||||
"abstract", "inventors_name", "applicants_name", "ipc", "cpc",
|
||||
],
|
||||
"query": {
|
||||
"bool": {
|
||||
"should": [
|
||||
{"match_phrase": {"title_en": title}},
|
||||
{"match_phrase": {"title_de": title}},
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
},
|
||||
"query": query,
|
||||
}
|
||||
|
||||
def uspto_title_query(self, title: str) -> dict[str, Any]:
|
||||
def uspto_title_query(self, title: str,filling_date: str | None = None) -> dict[str, Any]:
|
||||
query: dict[str, Any] = {
|
||||
"bool": {
|
||||
"should": [{"match_phrase": {"title": title}}],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
}
|
||||
if filling_date:
|
||||
query["bool"]["must"] = [{"term": {"application_date": filling_date}}]
|
||||
|
||||
return {
|
||||
"size": 1,
|
||||
"_source": [
|
||||
@@ -223,9 +251,9 @@ class AllPatentsSearchClient:
|
||||
"application_type", "title", "abstract", "inventors_names",
|
||||
"assignees_orgs", "ipcr", "cpc", "number_of_claims", "status",
|
||||
],
|
||||
"query": {"match_phrase": {"title": title}},
|
||||
"query": query,
|
||||
}
|
||||
|
||||
|
||||
async def search_epo(self, payload: dict[str, Any]) -> dict[str, Any]:
|
||||
return await self._search(EPO_INDEX, payload)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import json
|
||||
import httpx
|
||||
import pytest
|
||||
from inse.model import ESIndex
|
||||
from inse.patents.elastic_search_all_patents_client import AllPatentsSearchClient
|
||||
from inse.patents.elastic_search_client import (
|
||||
DEFAULT_SEARCH_SIZE,
|
||||
PatentSearchClient,
|
||||
@@ -50,6 +51,16 @@ def test_uspto_query_by_assignee_uses_assignees_orgs_field():
|
||||
assert "assignees_orgs" in str(payload["query"])
|
||||
|
||||
|
||||
def test_detail_and_title_queries_skip_empty_date_filters():
|
||||
client = AllPatentsSearchClient(api_key="test-key")
|
||||
|
||||
epo_payload = client.epo_title_query("method for generating and using a map")
|
||||
uspto_payload = client.uspto_detail_query("US12508845")
|
||||
|
||||
assert "must" not in epo_payload["query"]["bool"]
|
||||
assert "must" not in uspto_payload["query"]["bool"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_search_epo_posts_to_correct_index():
|
||||
captured: list[dict] = []
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
"ngVersion": "21.2.14",
|
||||
"providedInRoot": true,
|
||||
"serviceSuffix": "Service",
|
||||
"withInterfaces": true,
|
||||
"withInterfaces": false,
|
||||
"enumPropertyNaming": "original",
|
||||
"fileNaming": "kebab-case"
|
||||
"fileNaming": "camelCase"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,10 @@ import { BaseService } from '../api.base.service';
|
||||
import { PatentEntry } from '../model/patentEntry';
|
||||
import { PatentsByAuthorResponse } from '../model/patentsByAuthorResponse';
|
||||
import { PatentsByInstitutionResponse } from '../model/patentsByInstitutionResponse';
|
||||
import { OrgPatentsResponse, OrgPatentMatchTypeFilter } from '../model/orgPatentsResponse';
|
||||
import {
|
||||
OrgPatentsResponse,
|
||||
OrgPatentMatchTypeFilter,
|
||||
} from '../model/orgPatentsResponse';
|
||||
|
||||
export interface AllPatentsResponse {
|
||||
total: number;
|
||||
@@ -265,16 +268,28 @@ export class PatentsService extends BaseService {
|
||||
|
||||
let localVarQueryParameters = new HttpParams();
|
||||
if (options?.matchType) {
|
||||
localVarQueryParameters = localVarQueryParameters.set('match_type', options.matchType);
|
||||
localVarQueryParameters = localVarQueryParameters.set(
|
||||
'match_type',
|
||||
options.matchType,
|
||||
);
|
||||
}
|
||||
if (options?.page !== undefined) {
|
||||
localVarQueryParameters = localVarQueryParameters.set('page', String(options.page));
|
||||
localVarQueryParameters = localVarQueryParameters.set(
|
||||
'page',
|
||||
String(options.page),
|
||||
);
|
||||
}
|
||||
if (options?.size !== undefined) {
|
||||
localVarQueryParameters = localVarQueryParameters.set('size', String(options.size));
|
||||
localVarQueryParameters = localVarQueryParameters.set(
|
||||
'size',
|
||||
String(options.size),
|
||||
);
|
||||
}
|
||||
if (options?.source) {
|
||||
localVarQueryParameters = localVarQueryParameters.set('source', options.source);
|
||||
localVarQueryParameters = localVarQueryParameters.set(
|
||||
'source',
|
||||
options.source,
|
||||
);
|
||||
}
|
||||
|
||||
let localVarHeaders = this.defaultHeaders;
|
||||
@@ -371,9 +386,18 @@ export class PatentsService extends BaseService {
|
||||
);
|
||||
}
|
||||
|
||||
public getPatentById(patentId: string): Observable<PatentEntry> {
|
||||
public getPatentById(
|
||||
patentId: string,
|
||||
title?: string,
|
||||
prefix?: string,
|
||||
fillingDate?: string,
|
||||
): Observable<PatentEntry> {
|
||||
const localVarHeaders = this.defaultHeaders;
|
||||
const { basePath, withCredentials } = this.configuration;
|
||||
let params = new HttpParams();
|
||||
if (title) params = params.set('title', title);
|
||||
if (prefix) params = params.set('prefix', prefix);
|
||||
if (fillingDate) params = params.set('filling_date', fillingDate);
|
||||
const localVarPath = `/api/inse-service/patents/${this.configuration.encodeParam(
|
||||
{
|
||||
name: 'patentId',
|
||||
@@ -387,6 +411,7 @@ export class PatentsService extends BaseService {
|
||||
)}`;
|
||||
|
||||
return this.httpClient.get<PatentEntry>(`${basePath}${localVarPath}`, {
|
||||
params,
|
||||
...(withCredentials ? { withCredentials } : {}),
|
||||
headers: localVarHeaders,
|
||||
});
|
||||
|
||||
@@ -55,7 +55,14 @@ export class PatentDetailComponent implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
this.loadPatent(patentId);
|
||||
const title =
|
||||
this.route.snapshot.queryParamMap.get('title') ?? undefined;
|
||||
const prefix =
|
||||
this.route.snapshot.queryParamMap.get('prefix') ?? undefined;
|
||||
const fillingDate =
|
||||
this.route.snapshot.queryParamMap.get('fillingDate') ?? undefined;
|
||||
|
||||
this.loadPatent(patentId, title, prefix, fillingDate);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,14 +113,19 @@ export class PatentDetailComponent implements OnInit {
|
||||
return getDescriptionPreview(text);
|
||||
}
|
||||
|
||||
private loadPatent(patentId: string): void {
|
||||
private loadPatent(
|
||||
patentId: string,
|
||||
title?: string,
|
||||
prefix?: string,
|
||||
fillingDate?: string,
|
||||
): void {
|
||||
this.loading = true;
|
||||
this.notFound = false;
|
||||
this.patent = null;
|
||||
this.expandedClassificationKeys.clear();
|
||||
|
||||
this.patentsService
|
||||
.getPatentById(patentId)
|
||||
.getPatentById(patentId, title, prefix, fillingDate)
|
||||
.pipe(finalize(() => (this.loading = false)))
|
||||
.subscribe({
|
||||
next: (patent) => {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<h2>Intellectual Property Rights ({{ patents.length }})</h2>
|
||||
</div>
|
||||
<div class="patents-list">
|
||||
@for (ipr of patents; track ipr.title) {
|
||||
@for (ipr of patents; track ipr.applicationIdentifier) {
|
||||
<div class="ipr-item" (click)="searchForPatent(ipr)">
|
||||
<div class="ipr-icon">
|
||||
@if (ipr.type === 'PATENT') {
|
||||
|
||||
+4
-2
@@ -16,9 +16,11 @@ export class PatentsCardsComponent {
|
||||
@Input() headerTitle: string = 'IPRs';
|
||||
private router = inject(Router);
|
||||
searchForPatent(patent: Fp7ProjectIPR): void {
|
||||
this.router.navigate(['/patents'], {
|
||||
this.router.navigate([`/patent/${patent.applicationIdentifier}`], {
|
||||
queryParams: {
|
||||
search: patent.title,
|
||||
prefix: patent.applicationPrefix,
|
||||
title: patent.title,
|
||||
fillingDate: patent.applicationDate,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user