Spaces:
Runtime error
Runtime error
Commit
·
1f51646
1
Parent(s):
5ace436
Update main.py
Browse files
main.py
CHANGED
@@ -9,6 +9,7 @@ from comparativesIdentification import comparatives_binding
|
|
9 |
from earthquaqeIdentification import identify_earthquake_event
|
10 |
|
11 |
|
|
|
12 |
def process_final_dict(final_dictionary):
|
13 |
"""
|
14 |
Function to convert each one of the error codes from each component into a relevant code number to be handled by the SF
|
@@ -101,8 +102,6 @@ def natural_language_module(sentence):
|
|
101 |
if comparative:
|
102 |
final_dictionary.append(comparative)
|
103 |
|
104 |
-
print(final_dictionary)
|
105 |
-
|
106 |
# identify the target date in the sentence
|
107 |
date = dates_binding(sentence)
|
108 |
|
@@ -141,17 +140,30 @@ def natural_language_module(sentence):
|
|
141 |
return "\n\n=== AN UNEXPECTED ERROR HAS OCCURED. PLEASE EXECUTE AGAIN THE SCRIPT OR COMMUNICATE WITH THE DEVELOPER TEAM === \n\n"
|
142 |
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
def process_json_sf(nl_json, sentence):
|
146 |
"""
|
147 |
Function to conver the captured information an a relevant json format
|
148 |
"""
|
149 |
try:
|
|
|
150 |
sf_json_format = {
|
151 |
"text": sentence,
|
152 |
"page": "1",
|
153 |
"nlp": {"event": nl_json['event'], "city": nl_json['city'][0], "country": nl_json['country'][0], "year": int(nl_json['date']['year']), "month": int(nl_json['date']['month']),
|
154 |
-
"day": int(nl_json['date']['day']), "magnitude": nl_json['Number'], "comparative": nl_json['comparative'], "point": False, "latitude":
|
155 |
}
|
156 |
|
157 |
return sf_json_format
|
@@ -169,5 +181,6 @@ def main(sentence):
|
|
169 |
|
170 |
nl_data = natural_language_module(sentence)
|
171 |
nl_json = process_json_sf(nl_data, sentence)
|
|
|
172 |
|
173 |
-
return
|
|
|
9 |
from earthquaqeIdentification import identify_earthquake_event
|
10 |
|
11 |
|
12 |
+
|
13 |
def process_final_dict(final_dictionary):
|
14 |
"""
|
15 |
Function to convert each one of the error codes from each component into a relevant code number to be handled by the SF
|
|
|
102 |
if comparative:
|
103 |
final_dictionary.append(comparative)
|
104 |
|
|
|
|
|
105 |
# identify the target date in the sentence
|
106 |
date = dates_binding(sentence)
|
107 |
|
|
|
140 |
return "\n\n=== AN UNEXPECTED ERROR HAS OCCURED. PLEASE EXECUTE AGAIN THE SCRIPT OR COMMUNICATE WITH THE DEVELOPER TEAM === \n\n"
|
141 |
|
142 |
|
143 |
+
def replace_zero_with_null(d):
|
144 |
+
"""
|
145 |
+
This is a small helper function to convert the 0 references on the final json to be sent, into None, as needed by the SF
|
146 |
+
"""
|
147 |
+
for k, v in d.items():
|
148 |
+
if isinstance(v, dict):
|
149 |
+
replace_zero_with_null(v)
|
150 |
+
elif v == 0 and k != "point":
|
151 |
+
d[k] = "null"
|
152 |
+
return d
|
153 |
+
|
154 |
+
|
155 |
|
156 |
def process_json_sf(nl_json, sentence):
|
157 |
"""
|
158 |
Function to conver the captured information an a relevant json format
|
159 |
"""
|
160 |
try:
|
161 |
+
|
162 |
sf_json_format = {
|
163 |
"text": sentence,
|
164 |
"page": "1",
|
165 |
"nlp": {"event": nl_json['event'], "city": nl_json['city'][0], "country": nl_json['country'][0], "year": int(nl_json['date']['year']), "month": int(nl_json['date']['month']),
|
166 |
+
"day": int(nl_json['date']['day']), "magnitude": nl_json['Number'], "comparative": nl_json['comparative'], "point": False, "latitude": "null", "lognitude": "null"}
|
167 |
}
|
168 |
|
169 |
return sf_json_format
|
|
|
181 |
|
182 |
nl_data = natural_language_module(sentence)
|
183 |
nl_json = process_json_sf(nl_data, sentence)
|
184 |
+
nl_json_with_null = replace_zero_with_null(nl_json)
|
185 |
|
186 |
+
return nl_json_with_null
|