Inverted index: Difference between revisions
Content added Content deleted
(Added Wren) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 11: | Line 11: | ||
The search index can be in memory. |
The search index can be in memory. |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|D}} |
|||
<lang 11l>DefaultDict[String, Set[String]] index |
|||
F parse_file(fname, fcontents) |
|||
L(word) fcontents.split(re:‘\W’) |
|||
:index[word.lowercase()].add(fname) |
|||
L(fname, fcontents) [(‘inv1.txt’, ‘It is what it is.’), |
|||
(‘inv2.txt’, ‘What is it?’), |
|||
(‘inv3.txt’, ‘It is a banana!’)] |
|||
parse_file(fname, fcontents) |
|||
L(w) [‘cat’, ‘is’, ‘banana’, ‘it’, ‘what’] |
|||
print("\nEnter a word to search for: (q to quit): "w) |
|||
I w C index |
|||
print(‘'#.' found in #..’.format(w, sorted(Array(index[w])))) |
|||
E |
|||
print(‘'#.' not found.’.format(w))</lang> |
|||
{{out}} |
|||
<pre> |
|||
Enter a word to search for: (q to quit): cat |
|||
'cat' not found. |
|||
Enter a word to search for: (q to quit): is |
|||
'is' found in [inv1.txt, inv2.txt, inv3.txt]. |
|||
Enter a word to search for: (q to quit): banana |
|||
'banana' found in [inv3.txt]. |
|||
Enter a word to search for: (q to quit): it |
|||
'it' found in [inv1.txt, inv2.txt, inv3.txt]. |
|||
Enter a word to search for: (q to quit): what |
|||
'what' found in [inv1.txt, inv2.txt]. |
|||
</pre> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |