Textonyms: Difference between revisions
Content added Content deleted
(Add Factor) |
(→{{header|REXX}}: added/changed comments and whitespace, added commas to numbers being displayed, aligned numbers, changed wording for the output text(s),) |
||
Line 2,032: | Line 2,032: | ||
parse arg iFID . /*obtain optional fileID from the C.L. */ |
parse arg iFID . /*obtain optional fileID from the C.L. */ |
||
if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT' /*Not specified? Then use the default.*/ |
if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT' /*Not specified? Then use the default.*/ |
||
@.= |
@.= 0 /*the placeholder of digit combinations*/ |
||
!.=; |
!.=; $.= /*sparse array of textonyms; words. */ |
||
alphabet= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*the supported alphabet to be used. */ |
alphabet= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*the supported alphabet to be used. */ |
||
digitKey= 22233344455566677778889999 /*translated alphabet to digit keys. */ |
digitKey= 22233344455566677778889999 /*translated alphabet to digit keys. */ |
||
digKey=0; |
digKey= 0; #word= 0 /*number digit combinations; word count*/ |
||
ills=0; dups=0; longest=0; mostus= |
ills= 0 ; dups= 0; longest= 0; mostus= 0 /*illegals; duplicated words; longest..*/ |
||
first=.; last=.; long=0; |
first=. ; last= .; long= 0; most= 0 /*first, last, longest, most counts. */ |
||
call linein iFID, 1, 0 /*point to the first char in dictionary*/ |
|||
#= 0 /*number of textonyms in file (so far).*/ |
|||
do |
do while lines(iFID)\==0; x= linein(iFID) /*keep reading the file until exhausted*/ |
||
x |
y= x; upper x /*save a copy of X; uppercase X. */ |
||
if \datatype(x,'U') then do; ills=ills + 1; iterate; end |
if \datatype(x, 'U') then do; ills=ills + 1; iterate; end /*Not legal? Skip.*/ |
||
if $.x==. then do; dups=dups + 1; iterate; end |
if $.x==. then do; dups=dups + 1; iterate; end /*Duplicate? Skip.*/ |
||
$.x= |
$.x= . /*indicate that it's a righteous word. */ |
||
#word= #word + 1 /*bump the word count (for the file). */ |
|||
z=translate(x, digitKey, alphabet) |
z= translate(x, digitKey, alphabet) /*build a translated digit key word. */ |
||
@.z=@.z + 1 |
@.z= @.z + 1 /*flag that the digit key word exists. */ |
||
!.z=!.z y; |
!.z= !.z y; _= words(!.z) /*build list of equivalent digit key(s)*/ |
||
if _>most then do; mostus=z; most=_; end /*remember the "mostus" digit keys. */ |
if _>most then do; mostus=z; most=_; end /*remember the "mostus" digit keys. */ |
||
if @.z==2 then do; #=# + 1 |
if @.z==2 then do; #= # + 1 /*bump the count of the textonyms. */ |
||
if first==. then first=z /*the first textonym found. */ |
if first==. then first=z /*the first textonym found. */ |
||
last= |
last= z /* " last " " */ |
||
_=length(!.z) |
_= length(!.z) /*the length (# chars) of the digit key*/ |
||
if _>longest then long= |
if _>longest then long= z /*is this the longest textonym ? */ |
||
longest=max(_, longest) |
longest= max(_, longest) /*now, use this length as a target/goal*/ |
||
end /* [↑] discretionary (extra credit). */ |
end /* [↑] discretionary (extra credit). */ |
||
if @.z==1 then digKey=digKey + 1 |
if @.z==1 then digKey= digKey + 1 /*bump the count of digit key words. */ |
||
end /*while*/ |
end /*while*/ |
||
@dict= 'in the dictionary file' /*literal used for some displayed text.*/ |
|||
L= length(commas(max(#word,ills,dups,digKey,#))) /*find length of max # being displayed.*/ |
|||
@Ta = 'There are ' |
|||
say 'The dictionary file being used is: ' |
say 'The dictionary file being used is: ' iFID |
||
call tell #word, "words in the file which can be represented by digit key mapping" |
|||
if ills |
if ills>0 then call tell ills, 'word's(ills) "that contain illegal characters" @dict |
||
if dups |
if dups>0 then call tell dups, 'duplicate word's(dups) "detected" @dict |
||
call tell digKey, 'combination's(digKey) "required to represent them" |
|||
call tell #, 'digit combination's(#) "that can represent Textonyms" |
|||
say; if first\==. then say ' first digit key=' !.first |
|||
say |
|||
if |
if last\==. then say ' last digit key=' !.last |
||
if |
if long\==0 then say ' longest digit key=' !.long |
||
if |
if most\==0 then say ' numerous digit key=' !.mostus " ("most 'words)' |
||
⚫ | |||
if most\==0 then say ' numerous digit key=' !.mostus ' ('most "words)" |
|||
⚫ | |||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _ |
|||
⚫ | |||
tell: arg ##; say 'There are ' right(commas(##), L)' ' arg(2).; return /*commatize #*/ |
|||
⚫ | |||
{{out|output|text= when using the default input file:}} |
{{out|output|text= when using the default input file:}} |
||
<pre> |
<pre> |
||
The dictionary file being used is: UNIXDICT.TXT |
The dictionary file being used is: UNIXDICT.TXT |
||
There are |
There are 24,978 words in the file which can be represented by digit key mapping. |
||
There are 126 words |
There are 126 words that contain illegal characters in the dictionary file. |
||
There are 22,903 combinations required to represent them. |
|||
There are |
There are 1,473 digit combinations that can represent Textonyms. |
||
first digit key= aaa aba abc cab |
first digit key= aaa aba abc cab |
||
Line 2,093: | Line 2,095: | ||
numerous digit key= amy any bmw bow box boy cow cox coy (9 words) |
numerous digit key= amy any bmw bow box boy cow cox coy (9 words) |
||
</pre> |
</pre> |
||
{{out|output|text= when using the input file: <tt> textonyms.txt </tt>}} |
{{out|output|text= when using the input file: <tt> textonyms.txt </tt>}} |
||
<pre> |
<pre> |
||
The dictionary file being used is: |
The dictionary file being used is: TEXTONYMS.TXT |
||
There are |
There are 12,990 words in the file which can be represented by digit key mapping. |
||
There are 95 duplicate words in the dictionary |
There are 95 duplicate words detected in the dictionary file. |
||
There are 11,932 combinations required to represent them. |
|||
There are 650 digit combinations |
There are 650 digit combinations that can represent Textonyms. |
||
first digit key= AA AB AC BA BB BC CA CB |
first digit key= AA AB AC BA BB BC CA CB |