Created
November 30, 2010 06:30
-
-
Save masahitojp/721261 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from igo.Tagger import Tagger | |
class ZenraIgo(object): | |
def __init__(self, dataDir, position=u'動詞', text=u'全裸で'): | |
self.dataDir = dataDir | |
self.position = position | |
self.text = text | |
def zenrize(self, sentence): | |
if ( len(sentence) == 0 ): | |
raise Exception('Japanese sentece is necessary!') | |
result = u'' | |
for m in Tagger(self.dataDir).parse(sentence): | |
# 形態素の品詞を取得 | |
position = m.feature.split(',')[0] | |
if position == self.position : | |
# ターゲットとなる品詞なら文字列を前に追加 | |
result += self.text | |
result += m.surface | |
return result | |
if __name__ == "__main__": | |
z = ZenraIgo('ipadic') | |
print z.zenrize(u'お腹がすいたのでスパゲッティが食べたい') | |
n = ZenraIgo('ipadic',position=u'名詞', text=u'夜の') | |
print n.zenrize(u'お腹がすいたのでスパゲッティが食べたい') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment