::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:
method LOAD.DICTIONARY: Read and map dictionary file of words.
exit Map..Heap..string :Dictionary map from number -> {code, ...}
entry Path string :Dictionary file path
local Line word, &Current line in the dictionary file
Digit string, &Numeric code word representation
*Key Key..Heap..string, &Current number entry in the mapping
Code.Max |= 50, &Maximum code word width
Line.Max |= 75_000, &Maximum number of code words
Map |= "57630499617851881234762239" :Map letters to digits
alter Phonecode/Short :On exit, the shortest word size
:
:...............................................................................
DO Code from Read.Text( Path ): DO over the dictionary file,
assert Line < Line.Max &Too many code words in
pass "limit = " ! form( Line ) : the dictionary file.
Line += 1; Current line number
Digit = ""; Begin building encodings.
assert upper( Code, 1 ) = 'A' to 'Z' &A code word does not
pass "line " ! form( Line ) : begin with a letter.
DO C in lower( Code ): DO over code word characters,
IF C ~= '-' | '"': IF not skipping a delimiter,
assert Is.Alpha( C ) &A code word has an
pass "line " ! form( Line ) : invalid character.
Digit != string( Map, C - 'a' + 1 ); Map and build up digits.
- .
PUT.AT $, Digit, @Key; Map a digital code to the word.
PILE Key`Tag, Code; Same digits map to multiple words.
IF Short: IF previously established,
Short = min( Short, length( Digit )); Reset if smaller
ELSE: ELSE first iteration,
Short = length( Digit ); Initial minimum width
- .
return