In[]:=
haiku="Over the wintry\nForest, winds howl in rage\nWith no leaves to blow.";
words=TextWords[haiku];wordparts=PartOfSpeech/@words
Out[]=
,,,,,,,,,,,,,,,,,,,,,,,,,,,
Transpose@{words,Length/@ResourceFunction["WordSyllables"]/@words,Extract[wordparts,Transpose@{Range@Length@wordparts,{-1,1,1,1,1,2,-1,1,1,-1,1,1,2}}]}//TableForm
Out[]//TableForm=
Over | 2 | |
the | 1 | |
wintry | 2 | |
Forest | 2 | |
winds | 1 | |
howl | 1 | |
in | 1 | |
rage | 1 | |
With | 1 | |
no | 1 | |
leaves | 1 | |
to | 1 | |
blow | 1 |
In[]:=
haikudata=
//Transpose;
"Over" | 2 | Capitalize | |
"the" | 1 | "the"& | |
"wintry" | 2 | Identity | |
"Forest" | 2 | Capitalize | |
"winds" | 1 | Pluralize | |
"howl" | 2 | Identity | |
"in" | 1 | Identity | |
"rage" | 1 | Identity | |
"With" | 1 | Capitalize | |
"no" | 1 | Identity | |
"leaves" | 1 | Pluralize | |
"to" | 1 | "to"& | |
"blow" | 1 | Identity |
In[]:=
randomNSyllableWord[n_,type_]:=Module[{newword,iter=0},newword=RandomWord[type];While[Length@ResourceFunction["WordSyllables"]@newword≠n&&iter<10,newword=RandomWord[type]];newword];
StringReplace[haiku,MapThread[Function[{word,syl,POS,transform},wordIf[MatchQ[transform,_Function],transform[],transform@randomNSyllableWord[syl,POS]]],haikudata]]
Out[]=
Outside the duskyKickoff, blokes instill thru blipThwart our torches to swarm.