This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_extractors.py
61 lines (47 loc) · 1.8 KB
/
test_extractors.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
import time
from api_pkg import dandelion, dbspotlight, opencalais, babelfy, adel, meaning_cloud, alchemy, textrazor
def getErrors(text, lang=None, model_setting='default'):
extractors_list = [
alchemy.ALCHEMY(),
adel.ADEL(),
dbspotlight.DBSPOTLIGHT(),
opencalais.OPENCALAIS(),
meaning_cloud.MEANINGCLOUD(),
dandelion.DANDELION(),
babelfy.BABELFY(),
textrazor.TEXTRAZOR()
]
# print(strftime("%H:%M:%S", gmtime()))
limit_failures = 3
waiting_secs = 7
extractors_errors = {}
for ext in extractors_list:
print(ext.name)
counter_failures = 0
while counter_failures >= 0 and counter_failures < limit_failures:
try:
if ext.name == 'adel':
ext.extract(text, lang=lang, setting=model_setting)
else:
ext.extract(text, lang=lang)
counter_failures = -1
except:
print(sys.exc_info()[1])
counter_failures += 1
if counter_failures == limit_failures:
extractors_errors[ext.name] = str(sys.exc_info()[1])
else:
time.sleep(waiting_secs)
# print(strftime("%H:%M:%S", gmtime()))
extractors_responses = {ext.name: ext.get_annotations() for ext in extractors_list}
return extractors_responses, extractors_errors
lang = 'en'
text = "In Italy the rector is the head of the university and Rappresentante Legale (Legal representative) of the university. He or she is elected by an electoral body."
extractors_responses, extractors_errors = getErrors(text, lang=lang)
print(extractors_errors)
input()
for ext in extractors_responses:
print(ext)
input()
print(extractors_responses[ext])
input()