0

Hi i'm trying to work with wikidata in order to enrich text data for a classification nlp task, but i have zero knowledge and i'm running out of time.

What I want to query in wikidata:

Let's say I'd like to know that Mercedes-Benz is part of the automotive industry.

I'd like to give as a filtering condition the itemLabel Mercedes-benz:

I've tried Something like:

#All items with a property
# Sample to query all values of a property
# Property talk pages on Wikidata include basic queries adapted to each property
SELECT
  ?item ?itemLabel
  ?value ?valueLabel
# valueLabel is only useful for properties with item-datatype
WHERE 
{
  ?item wdt:P452 ?itemLabel 
  FILTER(CONTAINS(LCASE(?itemLabel), "Mercedes-benz"@en))    
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
# remove or change limit for more results
LIMIT 10

which is returning an empty results. Help?

Thanks

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Marco Fumagalli
  • 2,307
  • 3
  • 23
  • 41
  • because `?itemLabel` is a special variable bound to the result after everything is done by a special SERVICE. This is not SPARQL standard, thus, it does not work – UninformedUser Apr 23 '20 at 09:30
  • the correct way and the SPARQL way is to write `?item rdfs:label "Mercedes-Benz"@en . ` – UninformedUser Apr 23 '20 at 09:31
  • I also don't get why you do `?item wdt:P452 ?itemLabel ` - it binds and industry to the item, but then you won't make use of the label SERVICE. It should be `?item wdt:P452 ?value ` – UninformedUser Apr 23 '20 at 09:33
  • Moreover, in `FILTER(CONTAINS(LCASE(?itemLabel), "Mercedes-benz"@en))` you'd make the first value lower case, but your second value contains upper-case chars. Do you think this makes sense? Here with filters (though poor performance of course): `SELECT ?item ?itemLabel ?value ?valueLabel WHERE { ?item wdt:P452 ?value . ?item rdfs:label ?label FILTER(lang(?label) = 'en' && CONTAINS(LCASE(STR(?label)), LCASE("Mercedes-benz"))) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } LIMIT 10` – UninformedUser Apr 23 '20 at 09:35
  • 1
    here with the more efficient search feature: `SELECT ?item ?itemLabel ?value ?valueLabel WHERE { ?item wdt:P452 ?value . SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } SERVICE wikibase:mwapi { bd:serviceParam wikibase:api "EntitySearch" . bd:serviceParam wikibase:endpoint "www.wikidata.org" . bd:serviceParam mwapi:search "Mercedes-benz" . bd:serviceParam mwapi:language "en" . ?item wikibase:apiOutputItem mwapi:item . ?num wikibase:apiOrdinal true . } } ORDER BY ASC(?num) LIMIT 10` – UninformedUser Apr 23 '20 at 09:43
  • 1
    that's what I was looking for. I'm sorry if my question was kind of a mess. – Marco Fumagalli Apr 23 '20 at 09:47

0 Answers0