PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/Drinks.pm

http://github.com/duckduckgo/zeroclickinfo-spice
Perl | 30 lines | 21 code | 7 blank | 2 comment | 1 complexity | 463aad66b1c6ad3c32d956104375764a MD5 | raw file
Possible License(s): Apache-2.0
  1. package DDG::Spice::Drinks;
  2. # ABSTRACT: Drink mixing instructions
  3. use strict;
  4. use DDG::Spice;
  5. use Text::Trim;
  6. spice is_cached => 1;
  7. spice to => 'http://www.thecocktaildb.com/api/json/v1/{{ENV{DDG_SPICE_COCKTAILDB_APIKEY}}}/search.php?s=$1';
  8. spice wrap_jsonp_callback => 1;
  9. triggers any => ('cocktail', 'drink', 'ingredient', 'ingredients', 'make', 'making', 'mix', 'mixing', 'recipe');
  10. my %drinks = map { trim($_) => 0 } share('drinks.txt')->slurp;
  11. my @stop_words = ("are", "being", "for", "how", "is", "needed", "that", "to", "used", "what", "within");
  12. my ($rx) = map qr/(?:$_)/, join "|", map qr/\b\Q$_\E\b/, @stop_words;
  13. # Handle statement
  14. handle remainder_lc => sub {
  15. $_ =~ s/$rx//g;
  16. $_ =~ s/\b(a|an|in|of)\b//;
  17. trim $_;
  18. if (exists ($drinks{$_})) {
  19. return $_;
  20. }
  21. return;
  22. };
  23. 1;