-
Notifications
You must be signed in to change notification settings - Fork 132
/
test_corpus_processor.py
52 lines (36 loc) · 1.44 KB
/
test_corpus_processor.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
#!/usr/bin/env python -*- coding: utf-8 -*-
#
# Python Word Sense Disambiguation (pyWSD): Corpus API tests
#
# Copyright (C) 2014-2015 alvations
# URL:
# For license information, see LICENSE.md
'''
from pywsd.semcor import SemCorpus
semcor = SemCorpus('pywsd/data/semcor3.0_naf')
for filename, sentence in semcor:
context_sent_str = [i.text for i in sentence]
context_sent_pos = [i.term.pos for i in sentence]
#print sentence
######################################################################
from pywsd.semeval import SemEval2007_Coarse_WSD
coarse_wsd = SemEval2007_Coarse_WSD('pywsd/data/semeval2007_coarse_grain_wsd/')
for sentence in coarse_wsd:
print sentence
'''
from collections import defaultdict, namedtuple
from pywsd.semcor_preprocessor import _SemCorpus
import io
import cPickle as pickle
semcor = _SemCorpus('pywsd/data/semcor3.0_naf')
Word = namedtuple('Word', 'text, sense, lemma, pos, paraid, sentid, wordid')
semcor_corpus = defaultdict(defaultdict(list))
for filename, sentence in semcor:
filename = filename.replace('pywsd/data/semcor3.0_naf/', '')
corpus, _, filename = filename.partition('/')
print corpus, filename
sent = [Word(word.text, word.term.sense, word.term.lemma, word.term.pos,
word.paraid, word.sentid, word.id) for word in sentence]
semcor_corpus[corpus][filename].append(sent)
with io.open('semcor-wn30.pk', 'wb') as fin:
pickle.dump(semcor_corpus, fin)