Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
55
Task/Inverted-index/Icon/inverted-index-1.icon
Normal file
55
Task/Inverted-index/Icon/inverted-index-1.icon
Normal 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
|
||||
19
Task/Inverted-index/Icon/inverted-index-2.icon
Normal file
19
Task/Inverted-index/Icon/inverted-index-2.icon
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue