-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_test.py
More file actions
30 lines (23 loc) · 967 Bytes
/
parse_test.py
File metadata and controls
30 lines (23 loc) · 967 Bytes
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
import codecs
import sys
from utils.parsed_sentences_loader import ParsedSentencesLoader
from utils.stanford_format import StanfordParseLoader
from utils.conll_format import CONNL
from alignment.context_evidence import ContextEvidence
with codecs.open('data_test/test.parse', 'r', 'utf8') as f:
text = f.read()
loader = ParsedSentencesLoader()
sentences = loader.load(text)
parsed = []
for sentence in sentences['sentences']:
parsed.append(StanfordParseLoader.process_parse_result(sentence))
sys.exit()
parsed = CONNL.load('/home/marina/workspace/data/TRJuly/txtfile.output.tok.parse')
print(str(len(parsed)))
with codecs.open('data_test/test.parse.out', 'w', 'utf8') as o:
for i, sentence in enumerate(parsed):
o.write('Sentence: {}\n'.format(i + 1))
for word in sentence:
o.write('{}\t{}\t{}\t{}\n'.format(word.index, word.form, word.dep, -1 if word.head is None else word.head.index))
o.write('\n')
o.close()