[PYTHON] I touched HaikuFinder

Trigger

First of all, it seems that I do not understand from the title, but the trigger was when I was looking for python mode of Processing. There are many people who make Python Mode, but I often look at the Website of the person who created Python Mode that appears in the official module list of Processing. It was. Then he was making something called Haiku Finder. That's why I touched it. By the way, haiku seems to count the number of syllables in English.

I tried to move

Installation

It's just as usual.

$ wget http://MrFeinberg.com/haikufinder-1.1.zip

$ unzip haikufinder-1.1.zip

$ cd haikufinder-1.1

$ python setup.py install

After that, you can write a script like the one in the README. .. .. .. .. .. .. .. .. It was supposed to be, but first we have to find a document that has a syllable sequence of 5 7 5. I managed to find this by wandering around. This is Cinderella (laughs)

script

So it looks like this.

haiku_test.py


from haikufinder import HaikuFinder

text = ''' Once there was a gentleman who married, for his
second wife, the proudest and most haughty woman that
was ever seen. She had, by a former husband, two
daughters of her own humor, who were, ..(Omitted because it is long)'''

haikus = HaikuFinder(text).find_haikus()
for haiku in haikus:
    print haiku[0]
    print "    %s" % haiku[1]
    print haiku[2]
    print

Prepare such a script, place it under haikufinder-1.1 /, and execute it. The result is like this.

$ python haiku_test.py
Nothing was then heard
     but a confused noise of: "Ha!
how handsome she is!

is. Only this. For the time being, you can get a phrase with a good rhythm.

In Japanese

  1. First of all, separate with mecab etc.
  2. Read and estimate the kanji in the text with mecab
  3. Cut Japanese into phrases (is there any tool?)
  4. 5 7 5 Count

Is it? I think there are tools that can be separated by clauses rather than morphemes, but I haven't investigated them in detail. I think that mecab's morphological analysis seems to use the minimum number of clauses heuristically. Then.

Recommended Posts

I touched HaikuFinder
I touched Flask
I touched TensorFlow's Tensorboard
I touched AWS Chalice
I touched the Qiita API
I touched Wagtail (2). Introducing django-extensions.
I touched Tensorflow and keras
I touched PyAutoIt for a moment
I touched something called Touch Designer
I touched "Orator" so I made a note
I touched the data preparation tool Paxata
I touched graph-rcnn which generates a scene graph
I touched some of the new features of Python 3.8 ①