Update ✨Entity Linking Application✨.py
Browse files- ✨Entity Linking Application✨.py +39 -39
✨Entity Linking Application✨.py
CHANGED
@@ -475,46 +475,46 @@ def main_cli():
|
|
475 |
|
476 |
my_bar.empty()
|
477 |
st.write(f"✅ Applined Candidate Selection module (4/5) [{number}/{len(list_with_full_names)}]")
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
|
|
|
|
|
|
507 |
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
st.success(f"DBpedia: {dbpedia}")
|
516 |
-
else:
|
517 |
-
st.warning(f"The entity: {o} is NIL.")
|
518 |
else:
|
519 |
st.warning(f"The mention '{input_mention_user}' was NOT found in the sentence.")
|
520 |
else:
|
|
|
475 |
|
476 |
my_bar.empty()
|
477 |
st.write(f"✅ Applined Candidate Selection module (4/5) [{number}/{len(list_with_full_names)}]")
|
478 |
+
with st.spinner(f"Applying Candidate Matching module... (5/5) [{number}/{len(list_with_full_names)}]"):
|
479 |
+
if sorted_data:
|
480 |
+
sorted_top = sorted_data[0]
|
481 |
+
for k, v in sorted_top.items():
|
482 |
+
qid = k.split("/")[-1]
|
483 |
+
|
484 |
+
wikidata2wikipedia = f"""
|
485 |
+
SELECT ?wikipedia
|
486 |
+
WHERE {{
|
487 |
+
?wikipedia schema:about wd:{qid} .
|
488 |
+
?wikipedia schema:isPartOf <https://en.wikipedia.org/> .
|
489 |
+
}}
|
490 |
+
"""
|
491 |
+
results = get_resultss(wikidata2wikipedia)
|
492 |
+
|
493 |
+
for result in results["results"]["bindings"]:
|
494 |
+
for key, value in result.items():
|
495 |
+
wikipedia = value.get("value", "None")
|
496 |
+
|
497 |
+
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
|
498 |
+
wikidata2dbpedia = f"""
|
499 |
+
SELECT ?dbpedia
|
500 |
+
WHERE {{
|
501 |
+
?dbpedia owl:sameAs <http://www.wikidata.org/entity/{qid}>.
|
502 |
+
}}
|
503 |
+
"""
|
504 |
+
sparql.setQuery(wikidata2dbpedia)
|
505 |
+
sparql.setReturnFormat(JSON)
|
506 |
+
results = sparql.query().convert()
|
507 |
+
|
508 |
+
for result in results["results"]["bindings"]:
|
509 |
+
dbpedia = result["dbpedia"]["value"]
|
510 |
|
511 |
+
st.write(f"✅ Applied Candidate Matching module (5/5) [{number}/{len(list_with_full_names)}]")
|
512 |
+
st.text(f"The correct entity for '{o}' is:")
|
513 |
+
st.success(f"Wikipedia: {wikipedia}")
|
514 |
+
st.success(f"Wikidata: {k}")
|
515 |
+
st.success(f"DBpedia: {dbpedia}")
|
516 |
+
else:
|
517 |
+
st.warning(f"The entity: {o} is NIL.")
|
|
|
|
|
|
|
518 |
else:
|
519 |
st.warning(f"The mention '{input_mention_user}' was NOT found in the sentence.")
|
520 |
else:
|