emanuelaboros
commited on
Commit
•
9f3ce07
1
Parent(s):
80a6ddf
Update generic_nel.py
Browse files- generic_nel.py +21 -7
generic_nel.py
CHANGED
@@ -20,14 +20,25 @@ def get_wikipedia_page_props(input_str: str):
|
|
20 |
Returns:
|
21 |
str: The QID or "NIL" if the QID is not found.
|
22 |
"""
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# Preprocess the input string
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
wikipedia_url = f"https://{language}.wikipedia.org/w/api.php"
|
32 |
wikipedia_params = {
|
33 |
"action": "query",
|
@@ -50,11 +61,14 @@ def get_wikipedia_page_props(input_str: str):
|
|
50 |
page_props = data["query"]["pages"][page_id]["pageprops"]
|
51 |
|
52 |
if "wikibase_item" in page_props:
|
|
|
53 |
return page_props["wikibase_item"], language
|
54 |
else:
|
55 |
return qid, language
|
56 |
else:
|
57 |
return qid, language
|
|
|
|
|
58 |
except Exception as e:
|
59 |
return qid, language
|
60 |
|
|
|
20 |
Returns:
|
21 |
str: The QID or "NIL" if the QID is not found.
|
22 |
"""
|
23 |
+
# print(f"Input string: {input_str}")
|
24 |
+
if ">>" not in input_str:
|
25 |
+
page_name = input_str
|
26 |
+
language = "en"
|
27 |
+
print(
|
28 |
+
f"<< was not found in {input_str} so we are checking with these values: Page name: {page_name}, Language: {language}"
|
29 |
+
)
|
30 |
+
else:
|
31 |
# Preprocess the input string
|
32 |
+
try:
|
33 |
+
page_name, language = input_str.split(">>")
|
34 |
+
page_name = page_name.strip()
|
35 |
+
language = language.strip()
|
36 |
+
except:
|
37 |
+
page_name = input_str
|
38 |
+
language = "en"
|
39 |
+
print(
|
40 |
+
f"<< was not found in {input_str} so we are checking with these values: Page name: {page_name}, Language: {language}"
|
41 |
+
)
|
42 |
wikipedia_url = f"https://{language}.wikipedia.org/w/api.php"
|
43 |
wikipedia_params = {
|
44 |
"action": "query",
|
|
|
61 |
page_props = data["query"]["pages"][page_id]["pageprops"]
|
62 |
|
63 |
if "wikibase_item" in page_props:
|
64 |
+
# print(page_props["wikibase_item"], language)
|
65 |
return page_props["wikibase_item"], language
|
66 |
else:
|
67 |
return qid, language
|
68 |
else:
|
69 |
return qid, language
|
70 |
+
else:
|
71 |
+
return qid, language
|
72 |
except Exception as e:
|
73 |
return qid, language
|
74 |
|