Skip to content

Instantly share code, notes, and snippets.

@ma8ma
Created November 27, 2016 08:33
Show Gist options
  • Save ma8ma/f34aa50c5f0973f1ae88cb51fdf2c4cf to your computer and use it in GitHub Desktop.
Save ma8ma/f34aa50c5f0973f1ae88cb51fdf2c4cf to your computer and use it in GitHub Desktop.
mecab-python test.py patch
diff --git a/mecab/python/test.py b/mecab/python/test.py
index b8ba949..00f8473 100644
--- a/mecab/python/test.py
+++ b/mecab/python/test.py
@@ -1,26 +1,27 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
+from __future__ import print_function
-import MeCab
import sys
-import string
+
+import MeCab
+
sentence = "太郎はこの本を二郎を見た女性に渡した。"
try:
+ print(MeCab.VERSION)
- print MeCab.VERSION
+ t = MeCab.Tagger(" ".join(sys.argv))
- t = MeCab.Tagger (" ".join(sys.argv))
-
- print t.parse(sentence)
+ print(t.parse(sentence))
m = t.parseToNode(sentence)
while m:
- print m.surface, "\t", m.feature
- m = m.next
- print "EOS"
-
+ print(m.surface, m.feature, sep="\t")
+ m = m.next
+ print("EOS")
+
lattice = MeCab.Lattice()
t.parse(lattice)
lattice.set_sentence(sentence)
@@ -29,24 +30,22 @@ try:
b = lattice.begin_nodes(i)
e = lattice.end_nodes(i)
while b:
- print "B[%d] %s\t%s" % (i, b.surface, b.feature)
- b = b.bnext
+ print("B[%d] %s\t%s" % (i, b.surface, b.feature))
+ b = b.bnext
while e:
- print "E[%d] %s\t%s" % (i, e.surface, e.feature)
- e = e.bnext
- print "EOS";
+ print("E[%d] %s\t%s" % (i, e.surface, e.feature))
+ e = e.bnext
+ print("EOS")
d = t.dictionary_info()
while d:
- print "filename: %s" % d.filename
- print "charset: %s" % d.charset
- print "size: %d" % d.size
- print "type: %d" % d.type
- print "lsize: %d" % d.lsize
- print "rsize: %d" % d.rsize
- print "version: %d" % d.version
+ print("filename: %s" % d.filename)
+ print("charset: %s" % d.charset)
+ print("size: %d" % d.size)
+ print("type: %d" % d.type)
+ print("lsize: %d" % d.lsize)
+ print("rsize: %d" % d.rsize)
+ print("version: %d" % d.version)
d = d.next
-
-except RuntimeError, e:
- print "RuntimeError:", e;
-
+except RuntimeError as e:
+ print("RuntimeError:", e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment