Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Inverted-index/Factor/inverted-index-1.factor
Normal file
16
Task/Inverted-index/Factor/inverted-index-1.factor
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
USING: assocs fry io.encodings.utf8 io.files kernel sequences
|
||||
sets splitting vectors ;
|
||||
IN: rosettacode.inverted-index
|
||||
|
||||
: file-words ( file -- assoc )
|
||||
utf8 file-contents " ,;:!?.()[]{}\n\r" split harvest ;
|
||||
: add-to-file-list ( files file -- files )
|
||||
over [ swap [ adjoin ] keep ] [ nip 1vector ] if ;
|
||||
: add-to-index ( words index file -- )
|
||||
'[ _ [ _ add-to-file-list ] change-at ] each ;
|
||||
: (index-files) ( files index -- )
|
||||
[ [ [ file-words ] keep ] dip swap add-to-index ] curry each ;
|
||||
: index-files ( files -- index )
|
||||
H{ } clone [ (index-files) ] keep ;
|
||||
: query ( terms index -- files )
|
||||
[ at ] curry map [ ] [ intersect ] map-reduce ;
|
||||
6
Task/Inverted-index/Factor/inverted-index-2.factor
Normal file
6
Task/Inverted-index/Factor/inverted-index-2.factor
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
( scratchpad ) { "f1" "f2" "f3" } index-files
|
||||
|
||||
--- Data stack:
|
||||
H{ { "a" ~vector~ } { "is" ~vector~ } { "what" ~vector~ } { ...
|
||||
( scratchpad ) { "what" "is" "it" } swap query .
|
||||
V{ "f1" "f2" }
|
||||
Loading…
Add table
Add a link
Reference in a new issue