From 75ac48742bdf2826a135375fe1acf5f399bbbaf3 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Wed, 2 Dec 2015 16:52:58 +0100 Subject: Create word array and test it --- Aufgabe5/searchengine.pm | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'Aufgabe5/searchengine.pm') diff --git a/Aufgabe5/searchengine.pm b/Aufgabe5/searchengine.pm index 9a1690b..9a70367 100644 --- a/Aufgabe5/searchengine.pm +++ b/Aufgabe5/searchengine.pm @@ -33,10 +33,10 @@ use open ":encoding(UTF-8)"; our @ISA= qw( Exporter ); # these CAN be exported. -our @EXPORT_OK = qw( buildStoplist ); +our @EXPORT_OK = qw( buildStoplist getWords ); # these are exported by default. -our @EXPORT = qw( buildStoplist ); +our @EXPORT = qw( buildStoplist getWords ); sub buildStoplist { my ( $stoplistFileName, $stoplist ) = @_; @@ -57,3 +57,25 @@ sub buildStoplist { or warn "$0 : failed to close input file '$stoplistFileName' : $!\n"; } ## --- end sub buildStoplist + + +sub getWords { + my ( $text, $stoplist ) = @_; + + defined $text or die "Text must be supplied"; + defined $stoplist or die "Stoplist hash must be supplied"; + + # Split at whitespaces + my @words = split /[[:space:]]+/, $text; + + # Apply regex + @words = map /([[:lower:]]{3,})/i , @words; + + # Convert to lower case + @words = map {lc $_} @words; + + # Remove all words that are in the stoplist + @words = map {!exists $stoplist->{$_} ? ($_) : ()} @words; + + return @words; +} ## --- end sub getWords -- cgit v1.2.3-70-g09d2