Skip to content

Commit

Permalink
Merge pull request duckduckgo#2244 from ozdemirburak/master
Browse files Browse the repository at this point in the history
Drinks: Improve the Drink Name Filter
  • Loading branch information
moollaza committed Oct 28, 2015
2 parents 2511317 + 4bfc50f commit 6f8011b
Show file tree
Hide file tree
Showing 3 changed files with 417 additions and 404 deletions.
9 changes: 5 additions & 4 deletions lib/DDG/Spice/Drinks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ spice wrap_jsonp_callback => 1;
triggers any => ('cocktail', 'drink', 'ingredient', 'ingredients', 'make', 'making', 'mix', 'mixing', 'recipe');

my %drinks = map { trim($_) => 0 } share('drinks.txt')->slurp;
my @stop_words = ("a", "an", "are", "being", "for", "how", "in", "is", "needed", "of", "that", "to", "used", "what", "within");
my @stop_words = ("are", "being", "for", "how", "is", "needed", "that", "to", "used", "what", "within");
my ($rx) = map qr/(?:$_)/, join "|", map qr/\b\Q$_\E\b/, @stop_words;

# Handle statement
handle remainder_lc => sub {
$_ =~ s/$rx//g;
my $drink = trim($_);
if (exists($drinks{$drink})) {
return $drink if $drink ne "";
$_ =~ s/\b(a|an|in|of)\b//;
trim $_;
if (exists ($drinks{$_})) {
return $_;
}
return;
};
Expand Down
Loading

0 comments on commit 6f8011b

Please sign in to comment.