Spaces:
Runtime error
Runtime error
Commit ·
b491c91
1
Parent(s): bc6dfdb
Update main.py
Browse files
main.py
CHANGED
|
@@ -73,66 +73,61 @@ def process_final_dict(final_dictionary):
|
|
| 73 |
|
| 74 |
|
| 75 |
def natural_language_module(sentence):
|
| 76 |
-
|
| 77 |
-
Function to execute the complete natural language module pipeline
|
| 78 |
-
"""
|
| 79 |
-
try:
|
| 80 |
final_dictionary = []
|
| 81 |
-
|
| 82 |
# identify whether the sentence is referred on earthquake events
|
| 83 |
earth_event = identify_earthquake_event(sentence)
|
| 84 |
-
|
| 85 |
if earth_event:
|
| 86 |
final_dictionary.append(earth_event)
|
| 87 |
-
|
| 88 |
# identify the target country and city in the sentence
|
| 89 |
location = identify_locations(sentence)
|
| 90 |
-
|
| 91 |
if location:
|
| 92 |
final_dictionary.append(location)
|
| 93 |
-
|
| 94 |
# identify the target comparative in the sentence
|
| 95 |
comparative = comparatives_binding(sentence)
|
| 96 |
-
|
| 97 |
if comparative:
|
| 98 |
final_dictionary.append(comparative)
|
| 99 |
-
|
| 100 |
# identify the target date in the sentence
|
| 101 |
date = dates_binding(sentence)
|
| 102 |
-
|
| 103 |
if isinstance(date, list):
|
| 104 |
-
|
| 105 |
date_dict = date[0]
|
| 106 |
date_replc = date[1]
|
| 107 |
-
|
| 108 |
if date_dict:
|
| 109 |
final_dictionary.append(date_dict[0])
|
| 110 |
-
|
| 111 |
# we also delete the date reference from the sentence so that there will
|
| 112 |
# not be any confusion with it for the magnitude identification module
|
| 113 |
if len(date_replc) == 1:
|
| 114 |
sentence = sentence.replace(date_replc[0], " ")
|
| 115 |
-
|
| 116 |
# in case it is a tuple we add it as it is and we do not substitute something in the sentence
|
| 117 |
elif isinstance(date, tuple):
|
| 118 |
final_dictionary.append(date)
|
| 119 |
-
|
| 120 |
# identify the target magnitude number in the sentence
|
| 121 |
magnitude = magnitude_binding(sentence)
|
| 122 |
-
|
| 123 |
if magnitude:
|
| 124 |
final_dictionary.append(magnitude)
|
| 125 |
-
|
| 126 |
clean_final_dictionary = process_final_dict(final_dictionary)
|
| 127 |
-
|
| 128 |
result = {}
|
| 129 |
for d in clean_final_dictionary:
|
| 130 |
result.update(d)
|
| 131 |
-
|
| 132 |
return result
|
| 133 |
|
| 134 |
-
except:
|
| 135 |
-
return "\n\n=== AN UNEXPECTED ERROR HAS OCCURED. PLEASE EXECUTE AGAIN THE SCRIPT OR COMMUNICATE WITH THE DEVELOPER TEAM === \n\n"
|
| 136 |
|
| 137 |
|
| 138 |
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
def natural_language_module(sentence):
|
| 76 |
+
|
|
|
|
|
|
|
|
|
|
| 77 |
final_dictionary = []
|
| 78 |
+
|
| 79 |
# identify whether the sentence is referred on earthquake events
|
| 80 |
earth_event = identify_earthquake_event(sentence)
|
| 81 |
+
|
| 82 |
if earth_event:
|
| 83 |
final_dictionary.append(earth_event)
|
| 84 |
+
|
| 85 |
# identify the target country and city in the sentence
|
| 86 |
location = identify_locations(sentence)
|
| 87 |
+
|
| 88 |
if location:
|
| 89 |
final_dictionary.append(location)
|
| 90 |
+
|
| 91 |
# identify the target comparative in the sentence
|
| 92 |
comparative = comparatives_binding(sentence)
|
| 93 |
+
|
| 94 |
if comparative:
|
| 95 |
final_dictionary.append(comparative)
|
| 96 |
+
|
| 97 |
# identify the target date in the sentence
|
| 98 |
date = dates_binding(sentence)
|
| 99 |
+
|
| 100 |
if isinstance(date, list):
|
| 101 |
+
|
| 102 |
date_dict = date[0]
|
| 103 |
date_replc = date[1]
|
| 104 |
+
|
| 105 |
if date_dict:
|
| 106 |
final_dictionary.append(date_dict[0])
|
| 107 |
+
|
| 108 |
# we also delete the date reference from the sentence so that there will
|
| 109 |
# not be any confusion with it for the magnitude identification module
|
| 110 |
if len(date_replc) == 1:
|
| 111 |
sentence = sentence.replace(date_replc[0], " ")
|
| 112 |
+
|
| 113 |
# in case it is a tuple we add it as it is and we do not substitute something in the sentence
|
| 114 |
elif isinstance(date, tuple):
|
| 115 |
final_dictionary.append(date)
|
| 116 |
+
|
| 117 |
# identify the target magnitude number in the sentence
|
| 118 |
magnitude = magnitude_binding(sentence)
|
| 119 |
+
|
| 120 |
if magnitude:
|
| 121 |
final_dictionary.append(magnitude)
|
| 122 |
+
|
| 123 |
clean_final_dictionary = process_final_dict(final_dictionary)
|
| 124 |
+
|
| 125 |
result = {}
|
| 126 |
for d in clean_final_dictionary:
|
| 127 |
result.update(d)
|
| 128 |
+
|
| 129 |
return result
|
| 130 |
|
|
|
|
|
|
|
| 131 |
|
| 132 |
|
| 133 |
|