-
Notifications
You must be signed in to change notification settings - Fork 0
/
nlprouter.py
122 lines (93 loc) · 3.2 KB
/
nlprouter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import sys
import json
import dotenv
import webpage_process
import api_freebase
import api_googlemaps
import api_twitter
import api_wikipedia
import api_yelp
import api_youtube
dotenv.load_dotenv(
os.path.join(os.path.dirname(__file__),
'./.env')
)
def main():
_, payload = sys.argv
try:
payload = json.loads(payload)
except BaseException:
return []
if "webpageText" not in payload:
return []
content = payload["webpageText"]
content = webpage_process.cleanse_tags(content)
ner_tuple_list = webpage_process.ner_tagging(content)
ner_tuple_list = webpage_process.reduce_neighbors(ner_tuple_list)
picked_ner_tuple_list = webpage_process.pick_most_important(ner_tuple_list, 20)
result_list = []
for ner_tuple in picked_ner_tuple_list:
term, entity_type = ner_tuple
if entity_type == "PERSON":
result = api_freebase.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_youtube.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_wikipedia.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_twitter.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
elif entity_type == "LOCATION":
result = api_freebase.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_googlemaps.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_youtube.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_yelp.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_twitter.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_wikipedia.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
elif entity_type == "ORGANIZATION":
result = api_freebase.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_twitter.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_youtube.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
result = api_wikipedia.obtain(term, entity_type)
if result is not None:
result_list.append(json.dumps(result))
result = None
print json.dumps(result_list)
if __name__ == "__main__":
main()