-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_for_subject.py
140 lines (123 loc) · 4.85 KB
/
run_for_subject.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import time
from rq import get_current_job
from quasimodo.data_structures.inputs import Inputs
from quasimodo.data_structures.module_reference_interface import ModuleReferenceInterface
from quasimodo.data_structures.subject import Subject
from quasimodo.default_submodule_factory import DefaultSubmoduleFactory
def run_for_subject(subject):
job = get_current_job()
factory = DefaultSubmoduleFactory()
submodule_generation_names = [
"google-autocomplete",
"bing-autocomplete",
"yahoo-questions",
"answerscom-questions",
"quora-questions",
"reddit-questions",
"fact-combinor",
]
submodule_normalization_names = [
"lower-case",
"tbc-cleaner",
"only-subject",
"filter-object",
"no-personal",
"singular-subject",
"cleaning-predicate",
"basic-modality",
"present-continuous",
"are-transformation",
"can-transformation",
"be-normalization",
"identical-subj-obj",
"present-conjugate"
]
submodule_normalization_global_names = [
"similar-object-remover",
"fact-combinor"
]
submodule_validation_names = [
"google-book",
"flickr-clusters",
"imagetag",
"wikipedia-cooccurrence",
"simple-wikipedia-cooccurrence",
"conceptual-captions",
"what-questions"
]
empty_input = Inputs()
empty_input = empty_input.add_subjects({Subject(subject.lower())})
module_reference = ModuleReferenceInterface("")
pattern_submodule = factory.get_submodule("manual-patterns-google", module_reference)
empty_input = pattern_submodule.process(empty_input)
result = []
result.append(dict())
result[-1]["step name"] = "Assertion Generation"
result[-1]["steps"] = []
job.meta = result
job.save_meta()
generated_facts = []
for submodule_name in submodule_generation_names:
submodule = factory.get_submodule(submodule_name, module_reference)
begin_time = time.time()
input_temp = submodule.process(empty_input)
generated_facts += input_temp.get_generated_facts()
step_info = dict()
step_info["name"] = submodule.get_name()
step_info["facts"] = [x.to_dict() for x in input_temp.get_generated_facts()]
step_info["time"] = time.time() - begin_time
result[-1]["steps"].append(step_info)
job.meta = result
job.save_meta()
new_input = empty_input.add_generated_facts(generated_facts)
result.append(dict())
result[-1]["step name"] = "Assertion Normalization"
result[-1]["steps"] = []
for submodule_name in submodule_normalization_names:
submodule = factory.get_submodule(submodule_name, module_reference)
step_info = dict()
begin_time = time.time()
step_info["name"] = submodule.get_name()
step_info["modifications"] = []
for generated_fact in new_input.get_generated_facts():
input_temp = empty_input.add_generated_facts([generated_fact])
input_temp = submodule.process(input_temp)
if len(input_temp.get_generated_facts()) != 1 or input_temp.get_generated_facts()[0] != generated_fact:
modification = {
"from": generated_fact.to_dict(),
"to": [x.to_dict() for x in input_temp.get_generated_facts()]
}
step_info["modifications"].append(modification)
step_info["time"] = time.time() - begin_time
result[-1]["steps"].append(step_info)
job.meta = result
job.save_meta()
new_input = submodule.process(new_input)
result.append(dict())
result[-1]["step name"] = "Assertion Normalization Global"
result[-1]["steps"] = []
for submodule_name in submodule_normalization_global_names:
submodule = factory.get_submodule(submodule_name, module_reference)
begin_time = time.time()
new_input = submodule.process(new_input)
step_info = dict()
step_info["name"] = submodule.get_name()
step_info["facts"] = [x.to_dict() for x in new_input.get_generated_facts()]
step_info["time"] = time.time() - begin_time
result[-1]["steps"].append(step_info)
job.meta = result
job.save_meta()
result.append(dict())
result[-1]["step name"] = "Assertion Validation"
result[-1]["steps"] = []
begin_time = time.time()
for submodule_name in submodule_validation_names:
submodule = factory.get_submodule(submodule_name, module_reference)
new_input = submodule.process(new_input)
step_info = dict()
step_info["name"] = "All validations"
step_info["facts"] = [x.to_dict() for x in new_input.get_generated_facts()]
step_info["time"] = time.time() - begin_time
result[-1]["steps"].append(step_info)
job.meta = result
job.save_meta()