-
Notifications
You must be signed in to change notification settings - Fork 0
/
q052_morph_class.py
52 lines (42 loc) · 1.36 KB
/
q052_morph_class.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
46
47
48
49
50
51
52
#!/usr/bin/env python
# coding: utf-8
#
# Author: Peinan ZHANG
# Created at: 2014-12-12
import CaboCha, sys
from q051_cabocha import cabochaParse
class Morph:
def __init__(self, sentence):
self.sentence = sentence
self.cabochaResult = cabochaParse(sentence)
self.parsedMorphs = []
for line in self.cabochaResult.splitlines():
if line[:2] != '* ' and line.strip() != 'EOS':
srf, result = line.split('\t')
results = result.split(',')
base = results[6]
pos = results[0]
pos1 = results[1]
self.parsedMorphs.append(\
{'srf':srf, 'base':base, 'pos':pos, 'pos1':pos1})
def getParsedMorphs(self):
return self.parsedMorphs
def getSurfaces(self):
return [ morph['srf'] for morph in self.parsedMorphs ]
def getBases(self):
return [ morph['base'] for morph in self.parsedMorphs ]
def getPoses(self):
return [ morph['pos'] for morph in self.parsedMorphs ]
def getPos1s(self):
return [ morph['pos1'] for morph in self.parsedMorphs ]
def getCabochaResult(self):
return self.cabochaResult
if __name__ == '__main__':
for line in sys.stdin.readlines():
newMorph = Morph(line)
print newMorph.getCabochaResult()
print newMorph.getParsedMorphs()
print newMorph.getSurfaces()
print newMorph.getPoses()
print newMorph.getPos1s()
print newMorph.getBases()