Paste: factor-finder (2)
Author: | randy7 |
Mode: | factor |
Date: | Sun, 18 Jan 2009 00:30:38 |
Plain Text |
IN: factor-finder
USING: ui.tools.search io.encodings.utf8 regexp splitting grouping
fry sets ;
: count-seq ( seq -- seq' ) dup '[ _ swap '[ _ = ] count ] map ;
: count-dups ( seq -- seq ) dup count-seq zip prune >array ;
: just-2+ ( seq -- seq ) [ dup second 2 < [ drop f ] when ] map harvest ;
: sort-by-count ( seq -- seq ) [ [ second ] bi@ <=> ] sort reverse ;
: read-as-one-string ( seq -- str ) [ utf8 file-contents ] map " " join ;
: consistent-space ( str -- str ) "[\n|\r|\t|\s\s]" <regexp> " " re-replace ;
: split-to-words ( str -- seq ) " " split harvest ;
: (prepare-clumps) ( n -- seq ) [ length >array ] dip short head [ 1+ ] map ;
: make-words-groups ( count-array words -- groups ) [ swap clump ] curry map ;
: words-to-phrases ( seq -- seq ) [ [ " " join ] map ] map ;
: run-factor-finder ( -- )
all-source-files 30 short head
read-as-one-string
consistent-space split-to-words
[ 10 (prepare-clumps) ] keep
make-words-groups
words-to-phrases
[ count-dups ] map
[ just-2+ ] map
sort-by-count ;
Author: | randy7 |
Mode: | factor |
Date: | Sun, 18 Jan 2009 00:38:57 |
Plain Text |
concat sort-by-count
Author: | randy7 |
Mode: | factor |
Date: | Sun, 18 Jan 2009 00:52:35 |
Plain Text |
all-source-files [ "-docs" swap subseq? not ] filter
New Annotation