This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 946
Reborn IA: Drinks #2191
Merged
Merged
Reborn IA: Drinks #2191
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c129140
added drinks spice, fixes #2184
013be2f
Drinks: Check the empty ingredients
ca302ac
Drinks: change the triggers, add the word list
1d39422
Drinks: updated drinks text file
7f01a73
Drinks: update drinks.txt file lines to lc alphanumeric and space only
76a580e
Drinks: Update drink list and triggers
0653be9
Drinks: configure triggers
ce340d2
Drinks: configure tests
40f16fe
Drinks: Check the response whether null or empty
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package DDG::Spice::Drinks; | ||
# ABSTRACT: Drink mixing instructions | ||
|
||
use strict; | ||
use DDG::Spice; | ||
use Text::Trim; | ||
|
||
spice is_cached => 1; | ||
|
||
name "Drinks"; | ||
description "Bartending info"; | ||
primary_example_queries "how to make a mojito"; | ||
secondary_example_queries "what ingredients are being used within gin fizz", "long island cocktail"; | ||
|
||
code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Drinks.pm"; | ||
attribution github => ["https://github.com/mutilator", "mutilator"], | ||
github => ["https://github.com/ozdemirburak", "Burak Özdemir"], | ||
twitter => ["https://twitter.com/ozdemirbur", "Burak Özdemir"], | ||
web => ["http://burakozdemir.co.uk", "Burak Özdemir"]; | ||
|
||
spice to => 'http://www.thecocktaildb.com/api/json/v1/1/search.php?s=$1'; | ||
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 ($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 ""; | ||
} | ||
return; | ||
}; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(function (env) { | ||
"use strict"; | ||
|
||
function getInfoBoxData(item) { | ||
var infoboxData = [{ | ||
heading: 'Ingredients:' | ||
}]; | ||
for (var i = 1; i <= 15; i++) { | ||
if(item["strIngredient" + i] !== "") { | ||
infoboxData.push({ | ||
label: item["strMeasure" + i] + "" + item["strIngredient" + i] | ||
}); | ||
} | ||
} | ||
return infoboxData; | ||
} | ||
|
||
env.ddg_spice_drinks = function(api_result){ | ||
|
||
if (!api_result || api_result.error || !api_result.drinks || api_result.drinks.length === 0) { | ||
return Spice.failed('drinks'); | ||
} | ||
|
||
var drink = api_result.drinks[0]; | ||
|
||
Spice.add({ | ||
id: 'drinks', | ||
data: drink, | ||
name: "Drinks", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please change this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've fixed this 👍 |
||
meta: { | ||
sourceUrl: "http://www.thecocktaildb.com/drink.php?c=" + drink.idDrink, | ||
sourceName: 'TheCocktailDB' | ||
}, | ||
normalize: function(item) { | ||
return { | ||
description: item.strInstructions, | ||
title: item.strDrink, | ||
infoboxData: getInfoBoxData(item) | ||
}; | ||
}, | ||
templates: { | ||
group: 'info' | ||
} | ||
}); | ||
}; | ||
}(this)); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if
drinks
has any elements: