Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Inverted-index/Jq/inverted-index-1.jq
Normal file
18
Task/Inverted-index/Jq/inverted-index-1.jq
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Given an array of [ doc, array_of_distinct_words ]
|
||||
# construct a lookup table: { word: array_of_docs }
|
||||
def inverted_index:
|
||||
reduce .[] as $pair
|
||||
({};
|
||||
$pair[0] as $doc
|
||||
| reduce $pair[1][] as $word
|
||||
(.; .[$word] += [$doc]));
|
||||
|
||||
def search(words):
|
||||
def overlap(that): . as $this
|
||||
| reduce that[] as $item ([]; if $this|index($item) then . + [$item] else . end);
|
||||
|
||||
. as $dict
|
||||
| if (words|length) == 0 then []
|
||||
else reduce words[1:][] as $word
|
||||
( $dict[words[0]]; overlap( $dict[$word] ) )
|
||||
end ;
|
||||
8
Task/Inverted-index/Jq/inverted-index-2.jq
Normal file
8
Task/Inverted-index/Jq/inverted-index-2.jq
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
def prompt_search:
|
||||
"Enter a string or an array of strings to search for, quoting each string, or 0 to exit:",
|
||||
( (input | if type == "array" then . elif type == "string" then [.]
|
||||
else empty
|
||||
end) as $in
|
||||
| search($in), prompt_search ) ;
|
||||
|
||||
$in | inverted_index | prompt_search
|
||||
10
Task/Inverted-index/Jq/inverted-index-3.jq
Normal file
10
Task/Inverted-index/Jq/inverted-index-3.jq
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
$ jq -r -c -n --argfile in <(jq -R 'split(" ") | select(length>0) | [input_filename, unique]' T?.txt) -f Inverted_index.jq
|
||||
Enter a string or an array of strings to search for, quoting each string, or 0 to exit:
|
||||
"is"
|
||||
["T0.txt","T1.txt","T2.txt"]
|
||||
Enter a string or an array of strings to search for, quoting each string, or 0 to exit:
|
||||
["is", "banana"]
|
||||
["T2.txt"]
|
||||
Enter a string or an array of strings to search for, quoting each string, or 0 to exit:
|
||||
0
|
||||
$
|
||||
Loading…
Add table
Add a link
Reference in a new issue