blob: d05d458b5209d2debc53d7eac11aa5ac1a3db160 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#!/usr/bin/env perl
#===============================================================================
#
# FILE: skript3.pl
#
# USAGE: ./skript3.pl
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Stefan Suhren (su), suhren.stefan@fh-swf.de
# ORGANIZATION: FH Südwestfalen, Iserlohn
# VERSION: 1.0
# CREATED: 02.12.2015 14:14:02
# REVISION: ---
#===============================================================================
use strict;
use warnings;
use utf8;
# Add own module
use searchengine;
# For dumping data
use Data::Dumper;
# enforce utf-8 mode
binmode (STDIN, ":encoding(UTF-8)");
binmode (STDOUT, ":encoding(UTF-8)");
binmode (STDERR, ":encoding(UTF-8)");
use open ":encoding(UTF-8)";
my $stoplistFile = "stoplist.txt";
my %stoplist;
buildStoplist($stoplistFile, \%stoplist);
my %documentName;
for (my $i = 1; $i <= 4; $i++)
{
$documentName{$i} = 'doc.einfach/doc'.$i.'.txt';
}
my %reverseIndex;
foreach my $key (keys %documentName)
{
my $wordFileName = $documentName{$key};
open my $wordFile, '<', $wordFileName
or die "$0 : failed to open input file '$wordFileName' : $!\n";
# Read in slurp mode
my $fileContent = do{
local $/ = undef;
<$wordFile>;
};
close $wordFile
or warn "$0 : failed to close input file '$wordFileName' : $!\n";
foreach my $word (getWords($fileContent, \%stoplist))
{
${$reverseIndex{$word}}->{$key} = '';
}
}
print Dumper(%reverseIndex);
print "Suchwort: ";
my $eingabe = <>;
chomp $eingabe;
$eingabe = lc $eingabe;
if(exists $reverseIndex{$eingabe})
{
print "Suchwort '" . $eingabe . "' --- gefundene Dokumente: \n";
foreach my $fileId (sort keys ${$reverseIndex{$eingabe}})
{
printf "\t%d : %s\n", $fileId, $documentName{$fileId};
}
}
else
{
print "Suchwort '" . $eingabe . "' nicht gefunden\n";
}
|