• From JoyceUlysses.txt -- words occurring exactly once

    From HenHanna@HenHanna@devnull.tb to comp.lang.lisp,comp.lang.scheme on Thu May 30 13:09:39 2024
    From Newsgroup: comp.lang.scheme


    i'd not use Gauche for this, but maybe someone can change my mind.


    _______________________
    From JoyceUlysses.txt -- words occurring exactly once


    Given a text file of a novel (JoyceUlysses.txt) ...

    could someone give me a pretty fast (and simple) program that'd give me
    a list of all words occurring exactly once?

    -- Also, a list of words occurring once, twice or 3 times



    re: hyphenated words (you can treat it anyway you like)

    ideally, i'd treat [editor-in-chief]
    [go-ahead] [pen-knife]
    [know-how] [far-fetched] ...
    as one unit.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Jeff Barnett@jbb@notatt.com to comp.lang.lisp,comp.lang.scheme on Thu May 30 16:33:30 2024
    From Newsgroup: comp.lang.scheme

    On 5/30/2024 2:09 PM, HenHanna wrote:

    i'd not use Gauche for this, but maybe someone can change my mind.


    _______________________
    From JoyceUlysses.txt -- words occurring exactly once


    Given a text file of a novel (JoyceUlysses.txt) ...

    could someone give me a pretty fast (and simple) program that'd give me
    a list of all words occurring exactly once?

    -a-a-a-a-a-a-a-a-a-a-a-a-a -- Also, a list of words occurring once, twice or 3 times



    re: hyphenated words-a-a-a-a-a-a-a (you can treat it anyway you like)

    -a-a-a-a-a-a ideally, i'd treat-a [editor-in-chief]
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a [go-ahead]-a [pen-knife]
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a [know-how]-a [far-fetched] ...
    -a-a-a-a-a-a as one unit.

    Make a list (or array) of the individual words (as strings or symbols in
    a special package) of the original document then sort the list using the Lisp-supplied sort function. You than write a loop using your favorite
    tools and look for interior sequences of the required length. This gives
    you a program that is asymptotically efficient as the theoretical
    run-time will look something like (* c N (log N)), where N is the length
    of the list produced by the first step and c is some constant.

    Note, any solution resembling this one is not really what you want. For example it would think "Snark" and "Snarks" are different words. Some differences such as capitalization can be suppressed by choosing a sort predicate that is case insensitive. You can, of course, write your own
    sort predicate. The thing to note is that the predicate (the <= operator
    used by sort) will not access the words or maintain state between
    invocations; otherwise, the complexity can become arbitrarily large.
    --
    Jeff Barnett

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Stefan Monnier@monnier@iro.umontreal.ca to comp.lang.lisp,comp.lang.scheme on Thu May 30 18:45:00 2024
    From Newsgroup: comp.lang.scheme

    Given a text file of a novel (JoyceUlysses.txt) ...
    could someone give me a pretty fast (and simple) program that'd give me
    a list of all words occurring exactly once?

    tr ' .;:,?!' '\n' | sort | uniq -u

    ?


    - Stefan
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Kaz Kylheku@643-408-1753@kylheku.com to comp.lang.lisp,comp.lang.scheme on Thu May 30 23:20:08 2024
    From Newsgroup: comp.lang.scheme

    On 2024-05-30, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
    Given a text file of a novel (JoyceUlysses.txt) ...
    could someone give me a pretty fast (and simple) program that'd give me
    a list of all words occurring exactly once?

    tr ' .;:,?!' '\n' | sort | uniq -u

    Yep, that's pretty much how Doug McIlroy famously shut down Knuth.
    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Paul Rubin@no.email@nospam.invalid to comp.lang.lisp,comp.lang.scheme on Fri May 31 00:40:59 2024
    From Newsgroup: comp.lang.scheme

    could someone give me a pretty fast (and simple) program that'd give
    me a list of all words occurring exactly once?

    To first approximation, this works for me (bash command):

    tr -c "[a-zA-Z-]" "\n" < ulysses.txt |sort|uniq -c|sort -n
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From B. Pym@No_spamming@noWhere_7073.org to comp.lang.lisp,comp.lang.scheme on Fri May 31 10:13:50 2024
    From Newsgroup: comp.lang.scheme

    On 5/30/2024, HenHanna wrote:


    i'd not use Gauche for this, but maybe someone can change my mind.


    _______________________
    From JoyceUlysses.txt -- words occurring exactly once


    Given a text file of a novel (JoyceUlysses.txt) ...

    could someone give me a pretty fast (and simple) program that'd give me a list of all words occurring exactly once?

    -- Also, a list of words occurring once, twice or 3 times



    re: hyphenated words (you can treat it anyway you like)

    ideally, i'd treat [editor-in-chief]
    [go-ahead] [pen-knife]
    [know-how] [far-fetched] ...
    as one unit.

    Gauche Scheme

    (use file.util) ;; file->string
    (use srfi-13) ;; character sets
    (use srfi-14) ;; string-tokenize

    (define h (make-hash-table 'string=?))

    (dolist
    (s
    (string-tokenize (file->string "Alice.txt")
    (char-set-adjoin char-set:letter #\-)))
    (hash-table-update! h
    (regexp-replace* (string-upcase s) #/^-+/ "" #/-+$/ "")
    (pa$ + 1) 0))

    (filter (lambda(kv) (< (cdr kv) 3))
    (hash-table->alist h))

    ===>

    (("LASTED" . 2) ("WAY--NEVER" . 1) ("VISIT" . 1) ("CHANCED" . 1)
    ("WILDLY" . 2) ("BEHEAD" . 1) ("PROMISE" . 1) ("MEANWHILE" . 1)
    ("ENGAGED" . 1) ("KNIFE" . 2) ("ROARED" . 1) ("RETIRE" . 1)
    ("BLACKING" . 1) ("HATED" . 1) ("BRIGHT-EYED" . 1)
    ("SHEEP-BELLS" . 1) ("PROTECTION" . 1) ("CRIES" . 1) ("ADA" . 1)
    ("ENJOY" . 1) ("WRITHING" . 1) ("RAW" . 1) ("APPEALED" . 1)
    ("RELIEVED" . 1) ("CHILDHOOD" . 1) ("WEPT" . 1) ("RACE-COURSE" . 1)
    ("THEIRS" . 1) ("MAD--AT" . 1) ("SPOKEN" . 1) ("PENCILS" . 1)
    ("CLEAR" . 2) ("TREADING" . 2) ("RETURNED" . 2) ("CHERRY-TART" . 1)
    ("UNEASY" . 1) ("LOW-SPIRITED" . 1) ("BONE" . 1) ("PROMISED" . 1)
    ("HAPPENING" . 1) ("OYSTER" . 1) ("PATIENTLY" . 2) ("NEEDS" . 1)
    ("LESSON-BOOK" . 1) ("PITIED" . 1) ("UNCOMFORTABLY" . 1)
    ("ANTIPATHIES" . 1) ("PICTURED" . 1) ("DESPERATE" . 1)
    ("ENGRAVED" . 1)
    ...
    )
    --- Synchronet 3.22a-Linux NewsLink 1.2