-
Notifications
You must be signed in to change notification settings - Fork 187
/
iepy_rules_runner.py
59 lines (44 loc) · 1.46 KB
/
iepy_rules_runner.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
"""
Run IEPY rule-based extractor
Usage:
iepy_rules_runner.py
iepy_rules_runner.py -h | --help | --version
Picks from rules.py the relation to work with, and the rules definitions and
proceeds with the extraction.
Options:
-h --help Show this screen
--version Version number
"""
import sys
import logging
from django.core.exceptions import ObjectDoesNotExist
import iepy
iepy.setup(__file__)
from iepy.extraction.rules import load_rules
from iepy.extraction.rules_core import RuleBasedCore
from iepy.data import models, output
from iepy.data.db import CandidateEvidenceManager
def run_from_command_line():
logging.basicConfig(level=logging.INFO, format='%(message)s')
try:
relation_name = iepy.instance.rules.RELATION
except AttributeError:
logging.error("RELATION not defined in rules file")
sys.exit(1)
try:
relation = models.Relation.objects.get(name=relation_name)
except ObjectDoesNotExist:
logging.error("Relation {!r} not found".format(relation_name))
sys.exit(1)
# Load rules
rules = load_rules()
# Load evidences
evidences = CandidateEvidenceManager.candidates_for_relation(relation)
# Run the pipeline
iextractor = RuleBasedCore(relation, rules)
iextractor.start()
iextractor.process()
predictions = iextractor.predict(evidences)
output.dump_output_loop(predictions)
if __name__ == u'__main__':
run_from_command_line()