5

Know QID I can get items's label:

SELECT DISTINCT * WHERE {
  wd:Q302 rdfs:label ?label . 
  FILTER (langMatches( lang(?label), "EN" ) )
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    
}
LIMIT 1

see this query on Wikidata Query Service.

But how can I get other properties, for example description?

I tried the following:

SELECT DISTINCT * WHERE {
  wd:Q302 rdfs:description ?description . 
  FILTER (langMatches( lang(?label), "EN" ) )
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    
}
LIMIT 1

or this:

SELECT DISTINCT * WHERE {
  wd:Q302 rdfs:label ?label . 
  wd:Q302 rdfs:description ?description .
  FILTER (langMatches( lang(?label), "EN" ) )
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    
}
LIMIT 1

or

SELECT DISTINCT ?label ?description WHERE {
  wd:Q302 rdfs:label ?label .   
  FILTER (langMatches( lang(?label), "EN" ) )
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    
}
LIMIT 1

but got nothing.

Description is only for sample, I need other properties too.

UPDATE: Probably SPARQL isn't best way to do this, I open to other ways.

UPDATE2: What exactly I need: I have Query, where I get info about item searching by it's label:

SELECT distinct ?item ?itemLabel ?itemDescription
(SAMPLE(?DR) as ?DR) (SAMPLE(?article)as ?article)
WHERE {?item wdt:P31 wd:Q5. 
?item ?label "Einstein"@en 
OPTIONAL{?item wdt:P569 ?DR .}
?article schema:about ?item .
?article schema:inLanguage "en" .
?article schema:isPartOf <https://en.wikipedia.org/>.
OPTIONAL{?item wdt:P570 ?RIP .}
OPTIONAL{?item wdt:P18 ?image .}
SERVICE wikibase:label
{ bd:serviceParam wikibase:language "en". }}
GROUP BY ?item ?itemLabel ?itemDescription

I need to get the same info using it's QID, in this case Q937.

2 Answers 2

4

I asked similar question on SO and got 2 answers.

first answer:

Using the URI instead of the variable ?item will get the information based on the entity Albert Einstein:

PREFIX  schema: <http://schema.org/>
PREFIX  bd:   <http://www.bigdata.com/rdf#>
PREFIX  wdt:  <http://www.wikidata.org/prop/direct/>
PREFIX  wikibase: <http://wikiba.se/ontology#>

SELECT DISTINCT  ?item ?itemLabel ?itemDescription (SAMPLE(?DR) AS ?DRSample) (SAMPLE(?article) AS ?articleSample)
WHERE
  { ?article  schema:about       ?item ;
              schema:inLanguage  "en" ;
              schema:isPartOf    <https://en.wikipedia.org/>
    FILTER ( ?item = <http://www.wikidata.org/entity/Q937> )
    OPTIONAL
      { ?item  wdt:P569  ?DR }
    OPTIONAL
      { ?item  wdt:P570  ?RIP }
    OPTIONAL
      { ?item  wdt:P18  ?image }
    SERVICE wikibase:label
      { bd:serviceParam
                  wikibase:language  "en"
      }
  }
GROUP BY ?item ?itemLabel ?itemDescription

second answer:

If you already have the QID of the entity you are looking for and simply look for its properties and labels, you're better off using the Wikidata API wbgetentities module

In A. Einstein (Q937) case, that would give the following API call: https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q937&format=json

I think both answers are valuable to be presented here.

2

Here's a SPARQL query that returns the properties that have a value for Q302 (limit 100 for speed). In your orignal queries, I think filtering on English is one reason there are no results.

prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
SELECT distinct ?prop WHERE {
  ?item ?prop wd:Q302 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }  
}
limit 100

You can then get details about each property

SELECT DISTINCT ?property ?propertyLabel ?propertyDescription ?subpropertyOf ?subpropertyOfLabel  
WHERE
{
    ?property a wikibase:Property .
    OPTIONAL {?property wdt:P1647  ?subpropertyOf .}
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }   
}
1
  • not exactly what I need, I updated my question
    – Alexan
    Dec 30, 2016 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.