filter_forms.py 1.84 KB
#!/usr/bin/env python
#-*- coding:utf-8 -*-

def test_subst(tag):
    return tag.startswith('subst') and not tag.startswith('subst:ger')


def test_v(tag):
    prefixes = ('verb', 'subst:ger', 'pact', 'ppas', 'pant', 'pcon')
    for prefix in prefixes:
        if tag.startswith(prefix):
            return True
    return False


def test_ndm(tag):
    prefixes = ('adv', 'conj', 'interj', 'prep', 'qub', 'xxx')
    for prefix in prefixes:
        if tag.startswith(prefix):
            return prefix != 'adv' or not tag.endswith(':sup')
    return False


def test_adj(tag):
    return tag.startswith('adj') and not tag.endswith(':sup')


def test_other(tag):
    return not (
    test_subst(tag) or test_v(tag) or test_ndm(tag) or test_adj(tag))


def test(lc, tag):
    if lc == 'subst':
        return test_subst(tag)
    elif lc == 'v':
        return test_v(tag)
    elif lc == 'ndm':
        return test_ndm(tag)
    elif lc == 'adj':
        return test_adj(tag)
    elif lc == 'other':
        return test_other(tag)
    else:
        return tag.startswith(lc)


if __name__ == '__main__':
    import sys

    lc = sys.argv[1]
    with open(sys.argv[2]) as file:
        state = 'query'
        negated = []
        for line in file:
            line = line.rstrip('\n')
            if line == '':
                if state == 'print':
                    print
                    if negated:
                        for line in negated:
                            print line
                        print
                        negated = []
                state = 'query'
            elif state == 'query':
                tag = line.split('\t')[1]
                if test(lc, tag):
                    print line
                    state = 'print'
                else:
                    state = 'wait'
            elif state == 'print':
                print line