Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #49326

Counting words

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Counting words
Date 2016-07-22 14:24 +0000
Organization A noiseless patient Spider
Message-ID <nmtab9$v38$1@dont-email.me> (permalink)

Show all headers | View raw


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/

Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread


Thread

Counting words "WJ" <w_a_x_man@yahoo.com> - 2016-07-22 14:24 +0000

csiph-web