-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrun_jws_example.py
62 lines (41 loc) · 1.83 KB
/
run_jws_example.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
from utils.triplereadertriples import *
from pipeline.datareader import TRExDataReader
from pipeline.placeholdertagger import TypePlaceholderTagger
from pipeline.triplealigner import *
from pipeline.filter import *
from pipeline.writer import *
from pipeline.placeholdertagger import *
# Reading the T-REx premade dataset folder
reader = TRExDataReader('./out/', titles='./datasets/bibliography_titles.tsv')
trip_read_trip = TripleReaderTriples('./datasets/wikidata/sample-wikidata-triples.csv')
# filters and limiters
filter_entities = ['http://www.wikidata.org/entity/Q4167410', 'http://www.wikidata.org/entity/Q13406463']
entity_filter = EntityTypeFilter(trip_read_trip, filter_entities)
# limiting sentences
sen_lim = SentenceLimiter()
# checking if main entity of the document is found by an entity linker
main_ent_lim = MainEntityLimiter()
# placholder creation
placeholder_tagger = TypePlaceholderTagger('./datasets/datatypes/wikidata_datatypes.csv')
prop_tag = PropertyPlaceholderTagger()
# adding triples from a knowledge base
noalign = NoAligner(trip_read_trip)
# writer = JsonWriter('./out-test', "", 1000)
writer_triples = CustomeWriterTriples('./out-test', "jws", 1000)
writer_entities = CustomeWriterEntities('./out-test', "jws", 1000)
for d in reader.read_documents():
# try:
if not entity_filter.run(d):
continue
d = sen_lim.run(d, 1)
if not main_ent_lim.run(d):
continue
d = placeholder_tagger.run(d)
d = noalign.run(d)
d = prop_tag.run(d)
writer_triples.run(d)
writer_entities.run(d)
# writer.run(d)
print "Document Title: %s \t Number of Annotated Entities %s \t Number of Annotated Triples %s" % (d.title, len(d.entities), len(d.triples))
# except Exception as e:
# print "error Processing document %s" % d.title