RosettaCodeData/Task/I-before-E-except-after-C/Icon/i-before-e-except-after-c-2.icon
Ingy döt Net 776bba907c Sync
2013-10-27 22:24:23 +00:00

25 lines
903 B
Text

import Utils # To get the FindFirst class
procedure main(a)
WS := " \t"
showCounts := "--showcounts" == !a
phrases := ["cei","cie","ei","ie"]
ff := FindFirst(phrases)
totals := table(0)
every map(!&input) ? {
w := (tab(many(WS)),tab(upto(WS))) # word
(tab(many(WS)),tab(upto(WS))) # Skip part of speech
n := integer((tab(many(WS)),tab(upto(WS)|0))) | next # frequency?
\w ? while totals[2(tab(ff.locate()), ff.moveMatch(), move(-1))] +:= n
}
eiP := totals["cei"] > 2* totals["cie"]
ieP := (totals["ie"]+totals["cei"]) > 2* totals["ei"]
write("phrase is ",((\ieP & \eiP),"plausible")|"not plausible")
write("ie is ",(\ieP,"plausible")|"not plausible")
write("ei is ",(\eiP,"plausible")|"not plausible")
if \showCounts then every write(phrase := !phrases,": ",totals[phrase])
end