Word frequency: Difference between revisions
m
→{{header|Wren}}: Minor tidy and rerun
m (→{{header|Wren}}: Minor tidy and rerun) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 2,813:
=={{header|Java}}==
This is relatively simple in Java.<br />
I used a ''URL'' class to download
<syntaxhighlight lang="java">
import java.io.BufferedReader;
Line 2,832:
<syntaxhighlight lang="java">
void printWordFrequency() throws URISyntaxException, IOException {
Map<String, Integer> map = new HashMap<>();▼
URL url = new URI("https://www.gutenberg.org/files/135/135-0.txt").toURL();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
Line 2,839 ⟶ 2,838:
String line;
String word;
▲ Map<String, Integer> map = new HashMap<>();
while ((line = reader.readLine()) != null) {
matcher = pattern.matcher(line);
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 5,421 ⟶ 5,437:
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
If the Go example is re-run today (
<syntaxhighlight lang="
import "./str" for Str
import "./sort" for Sort
import "./fmt" for Fmt
import "./pattern" for Pattern
var fileName = "135-0.txt"
|