forked from cltl/OpenDutchWordnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version1_1.py
80 lines (61 loc) · 2.54 KB
/
version1_1.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
import os
import sys
from odwn import Wn_grid_parser
from datetime import datetime
with open('log.txt','w') as outfile:
outfile.close()
def log_it(message):
with open("log.txt","a") as outfile:
outfile.write(str(datetime.now())+"\t"+message+"\n")
#here
cwd = os.path.dirname(os.path.realpath(__file__))
omegawiki = "{cwd}/odwn/resources/wn-omegawiki-nld.txt".format(**locals())
wiktionary = "{cwd}/odwn/resources/wn-wiktionary-nld.txt".format(**locals())
google = "{cwd}/odwn/resources/wn-google-nld.txt".format(**locals())
#load it
log_it("starting")
instance = Wn_grid_parser(Wn_grid_parser.odwn)
log_it("start cleaning")
#clean it
instance.clean()
log_it('done cleaning')
#remove all babelnet + wiktionary + google_api results
for resource in ['babelnet','google_api','wiktionary']:
log_it("removing %s" % resource)
instance.les_remove_a_resource(resource)
#add results antoni + google monosemous results
def add_antoni():
pos_dict = {'n':'noun','v':'verb'}
for results in [omegawiki,wiktionary,google]:
if results.endswith("omegawiki-nld.txt"):
provenance = "omegawiki"
elif results.endswith("wn-wiktionary-nld.txt"):
provenance = "wiktionary"
elif results.endswith("wn-google-nld.txt"):
provenance = "google"
with open(results) as infile:
for counter,line in enumerate(infile):
offset_pos,lemma = line.strip().split("\t")
synset_identifier = "eng-30-{offset_pos}".format(**locals())
short_pos = synset_identifier[-1]
if short_pos not in ['n','v']:
continue
if counter % 100 == 0:
log_it("_".join([provenance,str(counter),synset_identifier,lemma]))
long_pos = pos_dict[short_pos]
instance.les_add_le(lemma,
long_pos,
short_pos,
synset_identifier,
provenance,
definition="",
sense_id=None,
sense_number=None)
log_it("adding antoni and google")
add_antoni()
log_it("gathering stats")
instance.get_stats(verbose=True)
instance.clean()
#export
output_path = os.path.join(cwd,'odwn','resources','odwn','odwn_orbn_gwg-LMF_1.1.xml')
instance.export(output_path)