-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeniatagger.py
More file actions
66 lines (52 loc) · 1.72 KB
/
geniatagger.py
File metadata and controls
66 lines (52 loc) · 1.72 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
#!/usr/bin/env python
from __future__ import print_function
from builtins import object
import argparse
import subprocess
import os.path
class GeniaTagger(object):
"""
"""
def __init__(self, path_to_tagger):
"""
Arguments:
- `path_to_tagger`:
"""
self._path_to_tagger = path_to_tagger
self._dir_to_tagger = os.path.dirname(path_to_tagger)
self._tagger = subprocess.Popen('./'+os.path.basename(path_to_tagger),
cwd=self._dir_to_tagger,
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
def parse(self, text):
"""
Arguments:
- `self`:
- `text`:
"""
results = list()
for oneline in text.split('\n'):
try:
self._tagger.stdin.write(oneline+'\n')
while True:
r = self._tagger.stdout.readline()[:-1]
if not r:
break
results.append(tuple(r.split('\t')))
except:
continue
return results
def callgenia(text):
tagger = GeniaTagger("./genia/geniatagger")
return (tagger.parse(text))
def _main():
parser = argparse.ArgumentParser(description="GeniaTagger python binding")
parser.add_argument('input_text')
parser.add_argument('--tagger', help='Path to geniatagger', default='./genia/geniatagger')
options = parser.parse_args()
print(options.tagger)
print(options.input_text)
tagger = GeniaTagger(options.tagger)
print(tagger.parse(options.input_text))
pass
if __name__ == '__main__':
_main()