This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,55 @@
procedure main()
texts := table() # substitute for read and parse files
texts["T0.txt"] := ["it", "is", "what", "it", "is"]
texts["T1.txt"] := ["what", "is", "it"]
texts["T2.txt"] := ["it", "is", "a", "banana"]
every textname := key(texts) do # build index for each 'text'
SII := InvertedIndex(SII,textname,texts[textname])
TermSearchUI(SII) # search UI
end
procedure InvertedIndex(ii,k,words) #: accumulate a simple inverted index
/ii := table(set()) # create lookup table and null set
every w := !words do {
if *ii[w] = 0 then ii[w] := set() # new word, new set
insert(ii[w],k)
}
return ii
end
procedure TermSearchUI(ii) #: search UI, all words must match
repeat {
writes("Enter search terms (^z to quit) : ")
terms := map(trim(read() | break))
x := []
terms ? while not pos(0) do {
tab(many(' \t'))
put(x,tab(upto('\ \t')|0))
}
show("Searching for : ",x)
show("Found in : ",s := TermSearch(ii,x)) | show("Not found : ",x)
}
write("End of search")
return
end
procedure TermSearch(ii,x) #: return set of matches or fail
every s := !x do
( /u := ii[s] ) | (u **:= ii[s])
if *u > 0 then return u
end
procedure show(s,x) # display helper
every writes(s|!x) do writes(" ")
write()
return
end

View file

@ -0,0 +1,19 @@
record InvertedIndexRec(simple,full)
procedure FullInvertedIndex(ii,k,words) #: accumulate a full inverted index
/ii := InvertedIndexRec( table(set()), table() ) # create lookup table and null set
wc := 0
every (w := !words, wc +:= 1) do {
if *ii.simple[w] = 0 then {
ii.simple[w] := set() # new word, new set
ii.full[w] := table() # also new table
}
insert(ii.simple[w],k)
/ii.full[w,k] := set()
insert(ii.full[w,k],wc)
}
return ii
end