3

I am currently searching in Wikidata with the following query:

https://www.wikidata.org/w/api.php?action=wbsearchentities&language=da&limit=20&format=json&search=jordb%C3%A6r&uselang=da

I need to find different ingredients and food stuff.

So the query is searching for strawberries in Danish. My problem is that I get results like paintings and persons. Is there anyway to search in specific categories like food? or somehow limit the "noise" of "false" hits?

I tried to look at Wikidata and search on Google but its not clear to me what options I have.

Termininja
  • 6,620
  • 12
  • 48
  • 49
Ronnie Jespersen
  • 950
  • 2
  • 9
  • 22
  • You could check the `instance of` property (`P31`) of the results, to see if they belong to the same category – leo May 23 '16 at 18:22
  • Hi @leo sorry for the late response. The content does not match `P31`, nor does it seem they all have the `instance of` either. I have come to the conclusion that it is simply not possible with food/ingredients sadly. – Ronnie Jespersen May 31 '16 at 14:49

2 Answers2

1

You can use the Wikidata Query Service to do this.

To find all the food in Danish, you could use a query like this:

SELECT DISTINCT ?food ?label WHERE {
   ?food (wdt:P31?/wdt:P279*) wd:Q2095.
   ?food rdfs:label ?label.
   SERVICE wikibase:label { bd:serviceParam wikibase:language "da". }
   FILTER((LANG(?label)) = "da")
} ORDER BY ?label

query link

Or, to get all the food items labeled 'Jordbær' in Danish, you could do something like this:

SELECT DISTINCT ?food ?foodLabel WHERE {
  ?food (wdt:P31?/wdt:P279*) wd:Q2095 ;
        rdfs:label "Jordbær"@da;
  SERVICE wikibase:label { bd:serviceParam wikibase:language "da". }
}

query link

Jan Drewniak
  • 1,316
  • 15
  • 18
1

I'm afraid there is, at the moment, no easy way to get this kind of tailored search result, but having this same need (for books in our case), we ended up with 2 work-arounds:

1 - search and filter

2 - filter and search

  • make the SPARQL request that get's all the valid results (see query.wikidata.org documentation), once for all (but needs to be updated periodically)
  • put all those results in your own search engine. See our Wikidata Subset Search Engine project
  • then, when needed, make your request to that search engine instead
maxlath
  • 1,804
  • 15
  • 24