Textonyms: Difference between revisions

4,459 bytes added ,  7 years ago
Added Io entry
(Added Io entry)
Line 615:
49376746242 => hydrophobia hydrophobic
2668368466 => contention convention </pre>
 
=={{header|Io}}==
 
<lang Io>main := method(
setupLetterToDigitMapping
 
file := File clone openForReading("./unixdict.txt")
words := file readLines
file close
 
wordCount := 0
textonymCount := 0
dict := Map clone
words foreach(word,
(key := word asPhoneDigits) ifNonNil(
wordCount = wordCount+1
value := dict atIfAbsentPut(key,list())
value append(word)
if(value size == 2,textonymCount = textonymCount+1)
)
)
write("There are ",wordCount," words in ",file name)
writeln(" which can be represented by the digit key mapping.")
writeln("They require ",dict size," digit combinations to represent them.")
writeln(textonymCount," digit combinations represent Textonyms.")
 
samplers := list(maxAmbiquitySampler, noMatchingCharsSampler)
dict foreach(key,value,
if(value size == 1, continue)
samplers foreach(sampler,sampler examine(key,value))
)
samplers foreach(sampler,sampler report)
)
 
setupLetterToDigitMapping := method(
fromChars := Sequence clone
toChars := Sequence clone
list(
list("ABC", "2"), list("DEF", "3"), list("GHI", "4"),
list("JKL", "5"), list("MNO", "6"), list("PQRS","7"),
list("TUV", "8"), list("WXYZ","9")
) foreach( map,
fromChars appendSeq(map at(0), map at(0) asLowercase)
toChars alignLeftInPlace(fromChars size, map at(1))
)
 
Sequence asPhoneDigits := block(
str := call target asMutable translate(fromChars,toChars)
if( str contains(0), nil, str )
) setIsActivatable(true)
)
 
maxAmbiquitySampler := Object clone do(
max := list()
samples := list()
examine := method(key,textonyms,
i := key size - 1
if(i > max size - 1,
max setSize(i+1)
samples setSize(i+1)
)
nw := textonyms size
nwmax := max at(i)
if( nwmax isNil or nw > nwmax,
max atPut(i,nw)
samples atPut(i,list(key,textonyms))
)
)
report := method(
writeln("\nExamples of maximum ambiquity for each word length:")
samples foreach(sample,
sample ifNonNil(
writeln(" ",sample at(0)," -> ",sample at(1) join(" "))
)
)
)
)
 
noMatchingCharsSampler := Object clone do(
samples := list()
examine := method(key,textonyms,
for(i,0,textonyms size - 2 ,
for(j,i+1,textonyms size - 1,
if( _noMatchingChars(textonyms at(i), textonyms at(j)),
samples append(list(textonyms at(i),textonyms at(j)))
)
)
)
)
_noMatchingChars := method(t1,t2,
t1 foreach(i,ich,
if(ich == t2 at(i), return false)
)
true
)
report := method(
write("\nThere are ",samples size," textonym pairs which ")
writeln("differ at each character position.")
if(samples size > 10, writeln("The ten largest are:"))
samples sortInPlace(at(0) size negate)
if(samples size > 10,samples slice(0,10),samples) foreach(sample,
writeln(" ",sample join(" ")," -> ",sample at(0) asPhoneDigits)
)
)
)
 
main</lang>
{{output}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
They require 22903 digit combinations to represent them.
1473 digit combinations represent Textonyms.
 
Examples of maximum ambiquity for each word length:
7 -> p q r s
46 -> gm go ho in io
269 -> amy any bmw bow box boy cow cox coy
2273 -> acre bard bare base cape card care case
42779 -> garry gassy happy harpy harry
723353 -> paddle raffle saddle
2667678 -> comport compost consort
38465649 -> ethology etiology
468376377 -> governess inverness
6388537663 -> mettlesome nettlesome
49376746242 -> hydrophobia hydrophobic
666628676342 -> onomatopoeia onomatopoeic
7244967473642 -> schizophrenia schizophrenic
25287876746242 -> claustrophobia claustrophobic
 
There are 275 textonym pairs which differ at each character position.
The ten largest are:
pistol shrunk -> 747865
hotbed invade -> 468233
aback cabal -> 22225
about bantu -> 22688
adams bebop -> 23267
rival shuck -> 74825
astor crump -> 27867
knack local -> 56225
rice shad -> 7423
ammo coon -> 2666</pre>
 
=={{header|J}}==
Anonymous user