forked from hideaki-t/igo-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
39 lines (31 loc) · 912 Bytes
/
test.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
# coding: utf-8
import os
import sys
import igo.tagger
if sys.version_info[0] < 3:
u = lambda s: s.decode('utf-8')
import codecs
sys.stdout = codecs.lookup('utf-8').streamwriter(sys.stdout)
else:
u = str
def pp(sf, ft, st):
sys.stdout.write(u("%s: %s at %d\n") % (sf, ft, st))
t = igo.tagger.Tagger('ipadic_gae', gae=True)
for m in t.parse(u('私の名前は中野です。')):
pp(m.surface, m.feature, m.start)
print('\n')
t = igo.tagger.Tagger('ipadic')
for m in t.parse(u('こんにちは世界')):
pp(m.surface, m.feature, m.start)
print('\n')
# test if the dictionary exists
try:
os.symlink(os.path.join(os.getcwd(), 'ipadic'), 'igo/dic')
if os.path.exists('igo/dic'):
t = igo.tagger.Tagger()
for m in t.parse(u('こんにちは世界')):
pp(m.surface, m.feature, m.start)
print('\n')
os.remove('igo/dic')
except:
pass