duckduckgo / zeroclickinfo-spice

DuckDuckGo Instant Answers based on JavaScript (JSON) APIs
https://duckduckhack.com/
Other
548 stars 942 forks source link

Color Picker: Triggers on any query starting with "Colour Picker" #2838

Closed moollaza closed 7 years ago

moollaza commented 8 years ago

E.g. https://duckduckgo.com/?q=color+picker+download

We should verify any remainders match the name of a color, or the pattern of a color (e.g. #e0e0e0)

If the remainder is a colour, then we should definitely set the color picker to that colour. Right now we pick a random colour so you get funny results like this:

color_picker_blue_at_duckduckgo


IA Page: http://duck.co/ia/view/color_picker Maintainer: @chrisharrill

moollaza commented 8 years ago

@ManrajGrover were you still interested in working on this?

If not, would any of our awesome @duckduckgo/duckduckhack-contributors be interested?

This will require some Perl work to verify the query is valid for this Instant Answer

manrajgrover commented 8 years ago

@moollaza I'll take this one up. Would love some pointers and links to similar Spice to this. :smile:

moollaza commented 8 years ago

@ManrajGrover the Color Codes IA is somewhat similar, but it uses a regular expression trigger.

Currently this IA is doing no relevancy checking against the query so I think we should start simple.

Most IA's do some form of relevancy checking like this so there should be plenty of examples in the repo.

For the HTML colour names, we can use a list like this: http://www.w3schools.com/colors/colors_names.asp -- I would put them into a YAML file and load it into a hash, then check if the remainder exists in that hash. We may need to normalize the remainder a bit. If we handle remainder_lc => then eerything will be forced to lowercase which makes it a little easier.

Example of loading a YAML file can be seen in several IAs as well: https://github.com/duckduckgo/zeroclickinfo-spice/search?utf8=%E2%9C%93&q=LoadFile

Feel free to break this up into a few consecutive PR's if you'd like 👍

GuiltyDolphin commented 8 years ago

@moollaza @ManrajGrover It's probably worth checking out Color::Library (Perl package) for checking names and getting Hex values.

use Color::Library;

my @colors = Color::Library->HTML->names;

...
handle remainder_lc => sub {
    my $remainder = shift;
    return unless any { $_ eq $remainder } @colors; # You'd want other checks for Hex
    my $color = Color::Library->HTML->color($remainder);
    my $hex = $color->hex();
    ...
}
manrajgrover commented 8 years ago

@GuiltyDolphin I just checked and found that Color::Library doesn't have many color names as link shared by @moollaza has. I feel we should go with that link.

GuiltyDolphin commented 8 years ago

@ManrajGrover Color::Library has over 10,000 (named) colors - pretty comprehensive :wink:

Even Color::Library::WWW alone has 148 - more than the 140 on that site.

manrajgrover commented 8 years ago

@GuiltyDolphin I had tried your code. I guess HTML has doesn't have that many. :worried: Should I revert the colors.yml and add check for colors mentioned in Color::Library including sub-modules?

GuiltyDolphin commented 8 years ago

@ManrajGrover Oh, sorry, my bad - that was just an example of how you might use it.

You'll probably want to use Color::Library::SVG for starters (same as Color::Library::WWW) which has 148 colors; it combines some of the common sets w/ some extra.

If there's some positive response for duckduckgo/zeroclickinfo-goodies#3371 then I'll put some work into a Role for various color-related functionality that is shared across color Goodies (including retrieving all colors). So we could perhaps expand the supported colors then?

manrajgrover commented 8 years ago

@GuiltyDolphin Sounds like a plan! (Counter Strike reference, sorry :wink: ) I'll delete the YML file and add Color::Library::SVG support for now. :smile: Also, if you could share some pointers on writing test files, that will help a lot! :smile:

GuiltyDolphin commented 8 years ago

@ManrajGrover Check out perldoc Test::Tutorial for a basic overview of testing in Perl; then we use Test::Deep for more advanced testing of structures. We have a few conventions and utility routines for writing ZCI tests - (using a build_test routine, the test_zci routine etc.) which should be present in a fair amount of existing test files.

manrajgrover commented 8 years ago

@GuiltyDolphin Thank you once again! :smile: I'll check them out.

moollaza commented 8 years ago

@ManrajGrover thanks a lot for converting this to a Goodie!

Now that it has been converted, we still need to fix the triggering, are you still interested in doing that part?

manrajgrover commented 8 years ago

@moollaza I guess previous PR also fixed the triggering, if triggering means extracting remainder color from query and matching it with ones in Color::Library. Please confirm. :smile:

tagawa commented 7 years ago

This still seems to be an issue, e.g. https://duckduckgo.com/?q=colour+picker+tutorials shouldn't show the colour picker.

mintsoft commented 7 years ago

@tagawa @moollaza The metadata for this IA is wrong; I don't think chrisharrill is the maintainer (IIRC he's not committed into this at all) and the backend files are NoteFrequency?

mintsoft commented 7 years ago

Also it's now moved to goodies: https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/ColorPicker.pm

mintsoft commented 7 years ago

@tagawa I'll fix this; it's really quick to knock out

mintsoft commented 7 years ago

Moved to: https://github.com/duckduckgo/zeroclickinfo-goodies/issues/3788

tagawa commented 7 years ago

Thank you for the PR and move to Goodies @mintsoft. Chrisharrill is the maintainer because he created the original version, but we could change that if somebody else wants to take over.

@MariagraziaAlastra Would you be able to remove the two NoteFrequency files from the backend metadata please? https://duck.co/ia/view/color_picker

manrajgrover commented 7 years ago

@tagawa I can take up the maintaining work.

tagawa commented 7 years ago

That's very kind @ManrajGrover - thank you. I've made you the maintainer.