colour palette search

64 views
Skip to first unread message

Nicole Coates

unread,
Jan 31, 2021, 8:36:35 AM1/31/21
to Europeana API forum

Hello,

I'm trying to write a little personal project that will a) establish a random 5-colour palette, b) query Europeana for paintings with that palette, c) have Europeana return one at random.

What seems to be happening is that the colour palette criteria is being ignored when results are returned.

I am really very new to all of this and one of my reasons for doing this is to learn how to deal with APIs, so it is very likely that I have done something stupid. I am sorry for bothering you if that is the case - I did try to work this out by reading the documentation several times and trying to read the source code of the Europeana Colour Explorer. Here is my python function to build the API call:

def get_art():
    api_key = 'XXXXXXXX'
    art_api = 'https://api.europeana.eu/record/v2/search.json?wskey='+ api_key
    query = {"query" : "painting",
             "theme" : "art",
             "colourpalette" : [colour0, colour1, colour2, colour3, colour4],
             "media" : "true",
             "sort"  : ("random", "desc"),
             "rows" : "1"
             }
    response = requests.post(art_api, json = query)
  
    return response

(I know this api key handling is not ideal but it is the only way i could get it to work!)

The colour variables are defined above this snippet, taken randomly from a list of the CSS hex colours and then returned as hex values.

This query returns 239,552 results. Commenting out 'theme' returns 264,554 results, which suggests that the original query is 'painting' AND 'theme:art'. Likewise, commenting out 'media' gives a higher number of returns: 245,498. But commenting out 'colourpalette' also returns 239,552 results. So i think my query as stands returns 'painting' AND 'theme:art' AND 'media:true' but ignores the colourpalette parameters?

Please do you have any tips for fixing this?

many thanks in advance,

Nikki


James Morley

unread,
Jan 31, 2021, 2:05:51 PM1/31/21
to europe...@googlegroups.com
Hi Nikki

You might want to take a look at https://culturepics.org/colour/ which is all client-side javascript so relatively easy to unpick.  

But as a starter, if you take a palette combination like 


it is based on the API call 


On the assumption that you are also wanting to do an AND query then the first thing I'd suggest trying is putting all values through separately (you can add as many &colourpalette= attributes as you like). There may of course be a neater way of doing it, but that seems to work for me!  I don't believe that the order they are queried has any effect but again might be worth testing. Note also that rather confusingly the IMAGE_SIZE parameters are doing the exact opposite here - in their case you add each size you want returned so they are in effect an OR query!

Just be warned that the palette is very unevenly spread amongst the Europeana corpus and you are likely to find a LOT of combinations of five colours that will have no results, so you'll probably want to put a loop around your palette generation, test for results, and only continue once you've found a suitable image!

Best, James

---
James Morley


On Sun, 31 Jan 2021 at 13:36, Nicole Coates <nikki....@gmail.com> wrote:

Hello,

I'm trying to write a little personal project that will a) establish a random 5-colour palette, b) query Europeana for paintings with that palette, c) have Europeana return one at random.

What seems to be happening is that the colour palette criteria is being ignored when results are returned..

I am really very new to all of this and one of my reasons for doing this is to learn how to deal with APIs, so it is very likely that I have done something stupid. I am sorry for bothering you if that is the case - I did try to work this out by reading the documentation several times and trying to read the source code of the Europeana Colour Explorer. Here is my python function to build the API call:

def get_art():
    api_key = 'XXXXXXXX'

    query = {"query" : "painting",
             "theme" : "art",
             "colourpalette" : [colour0, colour1, colour2, colour3, colour4],
             "media" : "true",
             "sort"  : ("random", "desc"),
             "rows" : "1"
             }
    response = requests.post(art_api, json = query)
  
    return response

(I know this api key handling is not ideal but it is the only way i could get it to work!)

The colour variables are defined above this snippet, taken randomly from a list of the CSS hex colours and then returned as hex values.

This query returns 239,552 results. Commenting out 'theme' returns 264,554 results, which suggests that the original query is 'painting' AND 'theme:art'. Likewise, commenting out 'media' gives a higher number of returns: 245,498. But commenting out 'colourpalette' also returns 239,552 results. So i think my query as stands returns 'painting' AND 'theme:art' AND 'media:true' but ignores the colourpalette parameters?

Please do you have any tips for fixing this?

many thanks in advance,

Nikki


--
Visit Europeana Labs for API Documentation, Open Datasets, and our Apps Showcase - http://labs.europeana.eu
---
You received this message because you are subscribed to the Google Groups "Europeana API forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to europeanaAPI...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/europeanaAPI/f3224856-92d8-421a-8940-fc8a2ed3a4ean%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages