Word frequency: Difference between revisions

PascalABC.NET
(PascalABC.NET)
 
(2 intermediate revisions by 2 users not shown)
Line 2,993:
"he" │ 6816
"had" │ 6140</pre>
 
=={{header|K}}==
{{works with|ngn/k}}<syntaxhighlight lang=K>common:{+((!d)o)!n@o:x#>n:#'.d:=("&"\`c$"&"|_,/0:y)^,""}
{(,'!x),'.x}common[10;"135-0.txt"]
(("the";41019)
("of";19898)
("and";14658)
(,"a";14517)
("to";13695)
("in";11134)
("he";9405)
("was";8361)
("that";7592)
("his";6446))</syntaxhighlight>
 
(The relatively easy to read output format here is arguably less useful than the table produced by <code>common</code> but it would have been more concise to have <code>common</code> generate it directly.)
 
=={{header|KAP}}==
Line 3,385 ⟶ 3,401:
7924 that
6661 it
</pre>
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
##
ReadAllText('135-0.txt').ToLower.MatchValues('\w+').EachCount
.OrderByDescending(w -> w.Value).Take(10).PrintLines
</syntaxhighlight>
{{out}}
<pre>
(the,41042)
(of,19952)
(and,14938)
(a,14527)
(to,13942)
(in,11208)
(he,9646)
(was,8620)
(that,7922)
(it,6659)
</pre>
 
Line 5,421 ⟶ 5,457:
I've taken the view that 'letter' means either a letter or digit for Unicode codepoints up to 255. I haven't included underscore, hyphen nor apostrophe as these usually separate compound words.
 
Not very quick (runs in about 4715 seconds on my system) though this is partially due to Wren not having regular expressions and the string pattern matching module being written in Wren itself rather than C.
 
If the Go example is re-run today (2117 OctoberFebruary 20202024), then the output matches this Wren example precisely though it appears that the text file has changed since the former was written more than 25 years ago.
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "./str" for Str
import "./sort" for Sort
import "./fmt" for Fmt
import "./pattern" for Pattern
 
var fileName = "135-0.txt"
230

edits