filter_forms.py
1.84 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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