Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Counting words

21 views
Skip to first unread message

WJ

unread,
Jul 22, 2016, 10:24:43 AM7/22/16
to
Count occurrences of words in "Alice's Adventures in Wonderland":

R:

filename = "Alice.txt"
rx = "[^a-zA-Z]+"

sub( paste0("^",rx), "", readChar(filename, 999000)) -> text.of.file

words <- (strsplit(text.of.file, rx))[[1]]

stats = summary( factor(words), maxsum = 99000)

> stats[1:8]
a A abide able about About above absence
672 18 2 1 101 1 3 1

> tail(stats,8)
YOUR yours YOURS yourself youth Zealand zigzag zip
7 2 1 10 6 1 1 1

Show the most common words of sizes 10 through 16:

for (i in 10:16)
{ word = sort(stats[nchar(names(stats)) == i], decreasing=TRUE)[1]
cat("size:", i, " word:", names(word), "\n")
}

size: 10 word: electronic
size: 11 word: Caterpillar
size: 12 word: conversation
size: 13 word: uncomfortable
size: 14 word: contemptuously
size: 15 word: MERCHANTIBILITY
size: 16 word: unenforceability

Can it be more concise and readable in Forth?

--
3/28/14 - Silas Nelson, 1, was beaten to death in Olyphant, PA. His mother's
black boyfriend was charged.
10/12/14 - Li'Asia Moorer, 2, was tortured and beaten to death in Cleveland,
OH. The victim's mother's black boyfriend has been charged.
http://conservative-headlines.com/2015/01/55690/
0 new messages