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(it, tag):
    if it == 'subst':
        return test_subst(tag)
    elif it == 'v':
        return test_v(tag)
    elif it == 'ndm':
        return test_ndm(tag)
    elif it == 'adj':
        return test_adj(tag)
    elif it == 'other':
        return test_other(tag)
    else:
        return tag.startswith(it)


if __name__ == '__main__':
    import sys

    it = 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(it, tag):
                    print line
                    state = 'print'
                else:
                    state = 'wait'
            elif state == 'print':
                print line