34 lines
1 KiB
Text
34 lines
1 KiB
Text
main (args):+
|
|
wm =: count words "../les_mis_135-0.txt"
|
|
wr =: map wm as row descending value key pairs
|
|
?# i =: from 1 upto max
|
|
print format '%6d; %s;' wr[i] \ wr[i] is a pair
|
|
|
|
\ read the file and provide a map with all words and their count
|
|
count words (fn):
|
|
wl =: new map
|
|
?# line =: file fn give lines
|
|
?# word =: string line give words of #ASCIIletters
|
|
word =: string word case to lower
|
|
wl{word} =+ 1 \ count for word; void is zero for addition
|
|
wl.words =+ 1 \ count number of words
|
|
:> wl
|
|
|
|
\ create a sorted row of pairs (count, word)
|
|
map (@) as row descending value key pairs:
|
|
rvk =: new row size @.Count
|
|
?# k =: map @ give keys
|
|
rvk[] =: @{k}, k
|
|
row rvk sort fast descending
|
|
:> rvk
|
|
|
|
\ not (yet) in library
|
|
string (@) give words of (chars):
|
|
$ =~ 1 \ start point
|
|
?* $ <= @.Count
|
|
word =: string @ from $ many of chars
|
|
$ =+ word.Count + 1 \ skip following character
|
|
? word ~= ''
|
|
:> word
|
|
$ =: ()
|
|
:> ()
|