-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeatures_p.py
45 lines (34 loc) · 1000 Bytes
/
features_p.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
44
45
#!/usr/bin/python3
from typing import List
def gp_verb_proportion(text, tags):
"""Anteil der Verben"""
verb_count = 0
total = len(tags)
for word, tag in tags:
if tag["pos"][0] == "V":
verb_count += 1
return verb_count / total
with open("data/names.txt") as inf:
names = inf.read().split("\n")
def li_contains_neper_global(text, tags):
"""Überprüft ob ein irgendein Personenname im Text vorkommt"""
global names
for word, tag in tags:
if tag["pos"] == "N":
if word.upper() in names or ("type" in tag and tag["type"] == "Name"):
return True
return False
if __name__ == "__main__":
import pickle
import inspect
import sys
with open("test.test", "rb") as testfile:
tags = pickle.load(testfile)
text = pickle.load(testfile)
res = []
functions = [obj for name, obj in inspect.getmembers(sys.modules[__name__]) if inspect.isfunction(obj)]
for f in functions:
res.append((f.__name__, f(text, tags)))
print(text)
for elem in res:
print(elem[0], elem[1])