Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created November 26, 2010 08:19
Show Gist options
  • Select an option

  • Save mizchi/716413 to your computer and use it in GitHub Desktop.

Select an option

Save mizchi/716413 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python
# -*- encoding:utf8 -*-
"""
要:mecab-python bindings
before こんな朝にすごい幸せそうなギャルとギャル男がいたので多分事後だろうな
after こんな意識の高い朝にすごい意識の高い幸せそうな意識の高いギャルと意識の高いギャル男がいたので多分意識の高い事後だろうな
"""
import MeCab
m = MeCab.Tagger("-Ochasen")
txt= "こんな朝にすごい幸せそうなギャルとギャル男がいたので多分事後だろうな"
def higher(txt):
print txt
n = m.parseToNode(txt).next
wakati = []
header = 0
result=""
while n.next:
if n.feature.split(",")[0] in ("名詞", "数詞") and not header and n.feature.split(",")[1] != "非自立":
result+= "意識の高い"+n.surface
header = 1
else:
result += n.surface
header = 0
n = n.next
return result
print higer(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment