PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/Thesaurus.pm

https://github.com/robertbrook/zeroclickinfo-spice
Perl | 44 lines | 32 code | 11 blank | 1 comment | 4 complexity | 40d3a9933e948890d3015f08d4f8b43b MD5 | raw file
  1. package DDG::Spice::Thesaurus;
  2. # ABSTRACT: Give the synonym, antonym, similar and related words of the query.
  3. use DDG::Spice;
  4. primary_example_queries "synonyms for person", "thesaurus awesome";
  5. secondary_example_queries "similar words to miniature";
  6. description 'Related words';
  7. name "BigHuge Thesaurus";
  8. source "Big Huge Labs";
  9. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Thesaurus.pm";
  10. topics "music", "words_and_games";
  11. category "language";
  12. attribution github => ['https://github.com/lactose','lactose'],
  13. twitter => ['http://twitter.com/hackariah','zachariah'];
  14. spice from => '([^/]+)/([^/]+)';
  15. spice to => 'http://words.bighugelabs.com/api/2/{{ENV{DDG_SPICE_BIGHUGE_APIKEY}}}/$1/json?callback={{callback}}';
  16. triggers startend => "synonyms", "synonym", "antonyms", "antonym", "related", "similar", "thesaurus";
  17. handle query_lc => sub {
  18. /^
  19. (?:(synonym|antonym|related|similar|thesaurus)s?) \s+
  20. (?:(?:terms?|words?)\s+)? (?:(?:of|to|for)\s+)?
  21. (\w+) \s*
  22. |
  23. (\w+) \s+
  24. ((synonym|antonym|thesaurus)s?)? \s*
  25. $/x;
  26. my $type = $1 || $4;
  27. my $word = $2 || $3;
  28. return unless $word and $type;
  29. $type = 'synonym' if $type eq 'thesaurus';
  30. return $word, $type;
  31. return;
  32. };
  33. 1;