Spaces:
Sleeping
Sleeping
Update genesis/api_clients/bioportal_api.py
Browse files
genesis/api_clients/bioportal_api.py
CHANGED
@@ -38,6 +38,26 @@ def search_ontology(term: str, max_results: int = 5) -> List[Dict]:
|
|
38 |
|
39 |
return terms
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
# -------------------------
|
42 |
# Get Term Details
|
43 |
# -------------------------
|
@@ -84,5 +104,5 @@ def ontology_context(term: str) -> Dict:
|
|
84 |
return {
|
85 |
"ontology_terms": ontology_terms,
|
86 |
"umls_cuis": list(set(cuis)),
|
87 |
-
"literature": pubmed_api.
|
88 |
}
|
|
|
38 |
|
39 |
return terms
|
40 |
|
41 |
+
# -------------------------
|
42 |
+
# Expand Query with Related Ontology Terms
|
43 |
+
# -------------------------
|
44 |
+
def expand_with_bioportal(term: str, max_results: int = 5) -> List[str]:
|
45 |
+
"""
|
46 |
+
Expand a biomedical term into related ontology labels.
|
47 |
+
This is the function called by pipeline.py
|
48 |
+
"""
|
49 |
+
try:
|
50 |
+
results = search_ontology(term, max_results)
|
51 |
+
expanded = []
|
52 |
+
for res in results:
|
53 |
+
if res["prefLabel"] and res["prefLabel"].lower() != term.lower():
|
54 |
+
expanded.append(res["prefLabel"])
|
55 |
+
expanded.extend(res.get("synonyms", []))
|
56 |
+
return list(set(expanded)) # unique terms only
|
57 |
+
except Exception as e:
|
58 |
+
print(f"[BioPortal] Expansion failed for '{term}': {e}")
|
59 |
+
return []
|
60 |
+
|
61 |
# -------------------------
|
62 |
# Get Term Details
|
63 |
# -------------------------
|
|
|
104 |
return {
|
105 |
"ontology_terms": ontology_terms,
|
106 |
"umls_cuis": list(set(cuis)),
|
107 |
+
"literature": pubmed_api.search_pubmed_literature(term) # fixed call name
|
108 |
}
|