-
Notifications
You must be signed in to change notification settings - Fork 0
/
brown_gd_to_dot_ccg.py
43 lines (40 loc) · 1.32 KB
/
brown_gd_to_dot_ccg.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
# -*- coding: utf-8 -*-
import pickle
import sys
from gd_tools.acainn import Lemmatizer, Retagger, Subcat, Typer
def tidy_word(string):
"""outputs string suitable for XMLification further down the pipeline"""
if string == '''"''':
return """
return string.replace("&", "&")
brownfile = open(sys.argv[1], 'rb')
corpus = pickle.load(brownfile)
brownfile.close()
output = open(sys.argv[2], 'w')
# features
with open("resources/features.txt") as file:
for line in file:
output.write(line)
# type-changing and type-raising rules
with open("resources/rules.txt") as rules:
for line in rules:
output.write(line)
retagger = Retagger()
typer = Typer()
families = set()
words = set()
# assumes a single list rather than a list of lists (need to think about this)
for surface, pos in corpus:
if pos != "":
tags = retagger.retag(surface, pos)
for tag in tags:
newtagtype = typer.type(surface, pos, tag)
newtag = newtagtype[0]
newtype = newtagtype[1]
families.add("family %s { entry: %s; }" % (newtag, newtype))
words.add('word "%s_%s":%s; # %s' % (tidy_word(surface), newtag, newtag, pos))
for family in sorted(families):
output.write(family + '\n')
for word in sorted(words):
output.write(word + '\n')
output.close()