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
|
#!/usr/bin/env python
import fileinput
from itertools import izip
from operator import itemgetter
from sentences import sentenceIterator, makeWindow
from common import *
def main(args):
for sentence in sentenceIterator(fileinput.input()):
for i, token in enumerate(sentence):
features = []
#if i == 0:
# features.append("FIRST")
#elif i + 1 == len(sentence):
# features.append("LAST")
#else:
# features.append("MIDDLE")
# window of words
features.extend(makeWindow(sentence, i, 2, 2, itemgetter(FORM)))
# window of pos tags
features.extend(makeWindow(sentence, i, 2, 2, itemgetter(POSTAG)))
# window of word-tag conjunctions
features.extend(makeWindow(sentence, i, 2, 2, lambda x: "%s^%s" % (x[FORM], x[POSTAG])))
# pos conjunctions
features.append("^".join(makeWindow(sentence, i, 1, 0, itemgetter(POSTAG))))
features.append("^".join(makeWindow(sentence, i, 0, 1, itemgetter(POSTAG))))
#features.append("^".join(makeWindow(sentence, i, 2, 0, itemgetter(POSTAG))))
#features.append("^".join(makeWindow(sentence, i, 0, 2, itemgetter(POSTAG))))
#features.append(token[FEATS])
features.extend(makeWindow(sentence, i, 1, 1, itemgetter(FEATS)))
if token[HEAD] == "0":
dir = "ROOT"
else:
dir = ["LEFT", "RIGHT"][int(token[ID]) < int(token[HEAD])]
print " ".join(features), dir
print
if __name__ == "__main__":
import sys
main(sys.argv[1:])
|