-
Notifications
You must be signed in to change notification settings - Fork 946
Reborn IA: Drinks #2191
Reborn IA: Drinks #2191
Changes from 5 commits
c129140
013be2f
ca302ac
1d39422
7f01a73
76a580e
0653be9
ce340d2
40f16fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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; | ||
|
||
my %drinks = map { trim($_) => 0 } share('drinks.txt')->slurp; | ||
triggers any => ('cocktail', 'drink', keys(%drinks)); | ||
|
||
# Handle statement | ||
handle query_lc => sub { | ||
my $query = $_; | ||
my @stop_words = ("a", "an", "are", "being", "cocktail", "drink", "for", "how", "in", "ingredient", "ingredients", "is", "make", "making", "mix", "mixing", "needed", "of", "that", "to", "used", "what", "within"); | ||
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. Let's define this array outside the |
||
my ($rx) = map qr/(?:$_)/, join "|", map qr/\b\Q$_\E\b/, @stop_words; | ||
$query =~ s/$rx//g; | ||
my $drink = trim($query); | ||
return $drink if $drink ne ""; | ||
return; | ||
}; | ||
|
||
1; |
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) { | ||
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. |
||
return Spice.failed('drinks'); | ||
} | ||
|
||
var drink = api_result.drinks[0]; | ||
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. |
||
|
||
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)); |
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.
This is in theory a great idea, but in practice it will result in a lot of over-triggering for dictionary words/phrases that exist in the drinks.txt file. E.G. "abc", "adam", "acid", etc. If the query is just "adam" it's pretty unlikely that they're looking for a drink recipe.
For now, let's stick with the triggers that are more suggestive of the user's intention, like "how to mix", "how to make", "drink", "cocktail", "recipe"