Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,12 +71,14 @@ def get_wikidata_id(entity_string):
|
|
| 71 |
|
| 72 |
def get_entity_data(entity_link):
|
| 73 |
try:
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
return response.json()
|
| 76 |
except Exception as e:
|
| 77 |
print(f"Exception when fetching data for entity: {entity_link}. Exception: {e}")
|
| 78 |
return None
|
| 79 |
-
|
| 80 |
# Create the form
|
| 81 |
with st.form(key='my_form'):
|
| 82 |
text_input = st.text_area(label='Enter a sentence')
|
|
@@ -127,6 +129,10 @@ if text_input:
|
|
| 127 |
|
| 128 |
# Replace each entity in the text with its annotated version
|
| 129 |
for entity_string, entity_info in entities_map.items():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
entity_data = entities_data.get(entity_string, None)
|
| 131 |
entity_type = None
|
| 132 |
if entity_data is not None:
|
|
@@ -152,7 +158,8 @@ if text_input:
|
|
| 152 |
|
| 153 |
# Add the entity to JSON-LD data
|
| 154 |
entity_json_ld = combined_entity_info_dictionary[entity_string][1]
|
| 155 |
-
|
|
|
|
| 156 |
|
| 157 |
# Split the modified text_input into a list
|
| 158 |
text_list = text_input.split("{")
|
|
|
|
| 71 |
|
| 72 |
def get_entity_data(entity_link):
|
| 73 |
try:
|
| 74 |
+
# Ensure that the URL format is correct
|
| 75 |
+
formatted_link = entity_link.replace("https://", "").replace("http://", "")
|
| 76 |
+
response = requests.get(f'https://api.wordlift.io/id/{formatted_link}')
|
| 77 |
return response.json()
|
| 78 |
except Exception as e:
|
| 79 |
print(f"Exception when fetching data for entity: {entity_link}. Exception: {e}")
|
| 80 |
return None
|
| 81 |
+
|
| 82 |
# Create the form
|
| 83 |
with st.form(key='my_form'):
|
| 84 |
text_input = st.text_area(label='Enter a sentence')
|
|
|
|
| 129 |
|
| 130 |
# Replace each entity in the text with its annotated version
|
| 131 |
for entity_string, entity_info in entities_map.items():
|
| 132 |
+
# Check if the entity has a valid Wikidata link
|
| 133 |
+
if entity_info["link"] is None or entity_info["link"] == "None":
|
| 134 |
+
continue # skip this entity
|
| 135 |
+
|
| 136 |
entity_data = entities_data.get(entity_string, None)
|
| 137 |
entity_type = None
|
| 138 |
if entity_data is not None:
|
|
|
|
| 158 |
|
| 159 |
# Add the entity to JSON-LD data
|
| 160 |
entity_json_ld = combined_entity_info_dictionary[entity_string][1]
|
| 161 |
+
if entity_json_ld and entity_json_ld.get("link") != "None":
|
| 162 |
+
json_ld_data["mentions"].append(entity_json_ld)
|
| 163 |
|
| 164 |
# Split the modified text_input into a list
|
| 165 |
text_list = text_input.split("{")
|