Skip to content

Commit

Permalink
fix nameResolution (the API response format changed)
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Nov 8, 2023
1 parent 5c05596 commit f671a52
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
18 changes: 9 additions & 9 deletions backend/app/api/ner.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ async def get_entities_relations(
status_code=400,
detail="the SRI NameResolution API is down (https://name-resolution-sri.renci.org)",
)
if len(name_res.keys()) > 0:
if len(name_res) > 0:
# entity['curies'] = name_res
for curie, labels in name_res.items():
for match in name_res:
alt_label = None
if len(labels) > 1:
alt_label = labels[1]
if len(match["synonyms"]) > 1:
alt_label = match["synonyms"][0]
entity["curies"].append(
{
"curie": curie,
"label": labels[0],
"curie": match["curie"],
"label": match["label"],
"altLabel": alt_label,
}
)
entity["id_curie"] = list(name_res.keys())[0]
entity["id_label"] = name_res[list(name_res.keys())[0]][0]
entity["id_uri"] = curie_to_uri(list(name_res.keys())[0])
entity["id_curie"] = entity["curies"][0]["curie"]
entity["id_label"] = entity["curies"][0]["label"]
entity["id_uri"] = curie_to_uri(entity["id_curie"])

# else:
# If not ID found with NCATS API, check RXCUIS: https://rxnav.nlm.nih.gov/REST/rxcui.json?name=Xyrem
Expand Down
30 changes: 15 additions & 15 deletions frontend/src/pages/annotate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ export default function AnnotateText() {
}
const entityCuries: any = await getEntityCuries(label)
ent['curies'] = []
if (entityCuries && Object.keys(entityCuries).length > 0) {
Object.keys(entityCuries).map((curie: any) => {
if (entityCuries.length > 0) {
entityCuries.map((match: any) => {
const addEnt: any = {
curie: curie,
label: entityCuries[curie][0],
altLabel: entityCuries[curie][1]
curie: match["curie"],
label: match["label"],
altLabel: match["synonyms"][0]
}
ent['curies'].push(addEnt)
})
Expand Down Expand Up @@ -586,12 +586,12 @@ export default function AnnotateText() {
props: []
}
const entityCuries = await getEntityCuries(text)
if (entityCuries && Object.keys(entityCuries).length > 0) {
Object.keys(entityCuries).map((curie: any) => {
if (entityCuries.length > 0) {
entityCuries.map((match: any) => {
const addEnt: any = {
curie: curie,
label: entityCuries[curie][0],
altLabel: entityCuries[curie][1]
curie: match["curie"],
label: match["label"],
altLabel: match["synonyms"][0]
}
newEntity['curies'].push(addEnt)
})
Expand Down Expand Up @@ -836,13 +836,13 @@ export default function AnnotateText() {
// and update the "curies" options from the result for the autocomplete
if (newInputValue && typeof newInputValue === 'string' && newInputValue.length > 2) {
const entityCuries = await getEntityCuries(newInputValue)
if (entityCuries && Object.keys(entityCuries).length > 0) {
if (entityCuries.length > 0) {
tagSelected.curies = []
Object.keys(entityCuries).map((curie: any) => {
entityCuries.map((match: any) => {
const addEnt: any = {
curie: curie,
label: entityCuries[curie][0],
altLabel: entityCuries[curie][1]
curie: match["curie"],
label: match["label"],
altLabel: match["synonyms"][0]
}
tagSelected.curies.push(addEnt)
})
Expand Down

0 comments on commit f671a52

Please sign in to comment.