Here's my solution (code both inlined below and attached). It uses the
cmu pronouncing dictionary directly, since I didn't know about
Lingua::EN. The code is inefficient in theory, but runs fast enough 
Since there were way too many results (most of them uninteresting), I
added the refinement that the senryu should be a complete sentence
(the word just before it, and the last word, should both end with a
full stop). I used Wodehouse's "Right Ho, Jeeves"
[http://www.gutenberg.org/etext/10554] to test it; these are three of
the more amusing ones it found:
You can't get away
from the facts. Somebody stole
her from me at Cannes.
"How? Could Lloyd George do
it, could Winston do it, could
Baldwin do it? No.
"What?" I staggered, and
the left pedal came up and
caught me on the shin.
# -------------------------------------------------------------------------------------------------------------------------------
# get dictionary from The CMU Pronouncing Dictionary
text = IO.read(ARGV[0]).split(" ")
dict = IO.readlines('cmudict.0.7a')
$syllables = {}
dict.each {|line|
word, pron = line.split(/\s+/, 2)
syl = pron.gsub(/[^\d]/, '').length
$syllables[word] = syl
}
senryu = []
count = 0
prev = ''
text.each do |word|
w = word.upcase.gsub(/\W/, '')
syl = syllables\[w\]
if syl
senryu\.push\(\[word, syl\]\)
count \+= syl
if count == 17
five = twelve = nil
n = 0
senryu\.each\_with\_index \{|\(w, i\), ix|
n \+= i
five = ix if \(n == 5\)
twelve = ix if \(n == 12\)
\}
if five and twelve and senryu\[\-1\]\[0\] =\~ /\\\./ and prev =~ /\.$/
[0..five, (five+1)..twelve, (twelve+1)..-1].each {|i|
puts senryu[i].map(&:first).join(" ")
}
puts
end
end
if count >= 17
prev, i = senryu.shift
count -= i
end
else
senryu = []
count = 0
end
end
senryu.rb (980 Bytes)