Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Inverted-index/D/inverted-index.d
Normal file
33
Task/Inverted-index/D/inverted-index.d
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import std.stdio, std.algorithm, std.string, std.file, std.regex;
|
||||
|
||||
void main() {
|
||||
string[][string] index;
|
||||
|
||||
void parseFile(in string fn) {
|
||||
if (!exists(fn) || !isFile(fn))
|
||||
throw new Exception("File not found");
|
||||
|
||||
foreach (word; readText(fn).splitter(regex(r"\W"))) {
|
||||
word = word.toLower();
|
||||
if (!index.get(word, null).canFind(fn))
|
||||
index[word] ~= fn;
|
||||
}
|
||||
}
|
||||
|
||||
immutable fileNames = ["inv1.txt", "inv2.txt", "inv3.txt"];
|
||||
foreach (fName; fileNames)
|
||||
parseFile(fName);
|
||||
|
||||
while (true) {
|
||||
writef("\nEnter a word to search for: (q to quit): ");
|
||||
immutable w = readln().strip().toLower();
|
||||
if (w == "q") {
|
||||
writeln("quitting.");
|
||||
break;
|
||||
}
|
||||
if (w in index)
|
||||
writefln("'%s' found in%( %).", w, index[w]);
|
||||
else
|
||||
writefln("'%s' not found.", w);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue