Text completion: Difference between revisions

m
→‎{{header|Phix}}: flexible args
m (→‎{{header|Phix}}: "not" collection!)
m (→‎{{header|Phix}}: flexible args)
Line 143:
<lang Phix>string word = "complition"
sequence words = get_text(join_path({"demo","unixdict.txt"}),GT_LF_STRIPPED)
function lt(string w, integer n) return levenshtein(w,word)=n end function
--function lt(string w, sequence nw) -- alt...
-- {integer n, string word} = nw -- ...""
return levenshtein(w,word)=n
end function
for n=1 to 4 do
printf(1,"Words at Levenshtein distance of %d (%g%% similarity) from \"%s\": \n%s\n",
{n,100-round(100*n/length(word)),word,join_by(filter(words,lt,n),1,6)})
-- ..."" {n,100-round(100*n/length(word)),word,join_by(filter(words,lt,{n,word}),1,6)})
end for</lang>
Note the parameters of the filter routine lt() can be quite flexible, for instance you could instead do this (and get the same results)
--<lang Phix>function lt(string w, sequence nw) -- alt...
-- {integer n, string word} = nw -- ...""
...
-- ..."" {n,100-round(100*n/length(word)),word,join_by(filter(words,lt,{n,word}),1,6)})</lang>
{{out}}
<pre>
7,796

edits