Project

ikku

0.03
No commit activity in last 3 years
No release in over 3 years
Discover haiku from text.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
>= 0
~> 10.0
= 3.2.0

Runtime

>= 0
 Project Readme

Ikku

Discover haiku from text.

Requirements

  • Ruby 2.0.0+
  • MeCab with IPADIC (e.g. brew install mecab mecab-ipadic)

Example

Ikku::Reviewer

Ikku::Reviewer class is the main interface for this library.

require "ikku"
reviewer = Ikku::Reviewer.new

Ikku::Reviewer#judge

Judge if given text is valid song or not.

reviewer.judge("古池や蛙飛び込む水の音") #=> true
reviewer.judge("ああ古池や蛙飛び込む水の音ああ") #=> false

Ikku::Reviewer#find

Find one valid song from given text.

reviewer.find("ああ古池や蛙飛び込む水の音ああ")
#=> #<Ikku::Song>

Ikku::Reviewer#search

Search all valid songs from given text.

reviewer.search("ああ古池や蛙飛び込む水の音ああ天秤や京江戸かけて千代の春ああ")
#=> [
#     #<Ikku::Song>,
#     #<Ikku::Song>,
#   ]

Ikku::Song#phrases

Return an Array of phrases of Ikku::Node.

song.phrases #=> [["古池", "や"], ["蛙", "飛び込む"], ["水", "の", "音"]]

Rule option

Pass :rule option to change the measure rule (default: [5, 7, 5]).

reviewer = Ikku::Reviewer.new(rule: [4, 3, 5])
reviewer.judge("古池や蛙飛び込む水の音") #=> false
reviewer.judge("すもももももももものうち") #=> true