ところてん #5416(2008/01/21 04:15 GMT) [ Python ] Rating1/1=1.00
pythonで書くとこんな感じ。 windows版のlibmecab.dllはshift jisでビルドされているので、 引き渡す際にshift-jisである必要がある。
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
# coding: shift_jis from ctypes import * class mecab(): def __init__(self,path): self.lib = cdll.LoadLibrary(path) argc = c_int(2) argv = (c_char_p * 2)("mecab", "-Ochasen") # 解析器のオブジェクトを作る self.tagger = self.lib.mecab_new(argc, argv) def getChasenStyle(self,word): word = self.lib.mecab_sparse_tostr(self.tagger, word) return c_char_p(word).value def getChasenStyleList(self,word): word = self.lib.mecab_sparse_tostr(self.tagger, word) l = [] for line in c_char_p(word).value.splitlines(): l.append([]) for data in line.split("\t"): l[-1].append(data) return l def __del__(self): self.lib.mecab_destroy(self.tagger) if __name__ == '__main__': tagger = mecab('libmecab.dll') s = "「どう書く?org」へようこそ! このサイトは出されたお題をいかに解くか競い合う、" " プログラマのためのコロシアムです。 投稿を試してみたい方はテスト、" " とりあえず眺めてみたい方は言語の一覧 がおすすめです。" print tagger.getChasenStyleList(s)
Rating1/1=1.00-0+
[ reply ]
ところてん
#5416()
[
Python
]
Rating1/1=1.00
Rating1/1=1.00-0+
[ reply ]