-1

In the examples of the SPARQL of Wikidata, we have this one:

    SELECT ?h ?date 
WHERE 
{
    ?h wdt:P31 wd:Q5 .
    ?h wdt:P569 ?date .
    OPTIONAL {?h wdt:P570 ?d } 
    FILTER (?date > "1880-01-01T00:00:00Z"^^xsd:dateTime)
    FILTER (!bound(?d))
}
LIMIT 1000

I understand that if you put Label after the name of a variable it shows the label. So, I don't understand why this shows no output:

    SELECT ?h ?hLabel ?date ...

Thank you in advance!

Jack Green
  • 141
  • 2
  • 12
  • This feature is provided by Wikidata-specific [service](https://m.mediawiki.org/wiki/Wikidata_query_service/User_Manual#Label_service). – Stanislav Kralin Jun 13 '17 at 10:31

1 Answers1

3

I am not aware of that specific feature for Label after the variable name.

However, for rdfs:label, you can to inculde the rdfs:label in your query. Add the following line: ?h rdfs:label ?hLabel.:

SELECT ?h ?hLabel ?date WHERE 
{
    ?h wdt:P31 wd:Q5 .
    ?h wdt:P569 ?date .      
    ?h rdfs:label ?hLabel. 
    OPTIONAL {?h wdt:P570 ?d } 
    FILTER (?date > "1880-01-01T00:00:00Z"^^xsd:dateTime)
    FILTER (!bound(?d))
}
LIMIT 1000

If you want labels in a specific language, e.g. for English add FILTER (langMatches( lang(?hLabel), "EN" ) )

Here is a stackoverflow intersting answer about labels.

Median Hilal
  • 1,483
  • 9
  • 17
  • It solved that issue, but now there is añother one. This is my new query: ` SELECT ?h ?hLabel ?date WHERE { ?h wdt:P31 wd:Q5 . ?h wdt:P569 ?date . ?h rdfs:label ?hLabel. OPTIONAL {?h wdt:P570 ?d } FILTER (?date > "1880-01-01T00:00:00Z"^^xsd:dateTime) FILTER (!bound(?d)) } LIMIT 1000 ` Now in the answer I have some elements more than once. I tried `DISTINCT` and ` SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }`. But neither is working. Thanks – Jack Green Jun 13 '17 at 18:19
  • I think it is because the language. Just add the language filter I mentioned in the answer to include only English results. Or add ?lang to the select, and then add BIND ( lang(?hLabel) as ?lang) in the where clause. – Median Hilal Jun 13 '17 at 18:59
  • @JackGreen if you use the Wikidata label service, then you don't need to use the `rdfs:label` triple pattern. – UninformedUser Jun 13 '17 at 19:49
  • 1
    Thank you. I discovered that you mean this: `SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }.` – Jack Green Jun 13 '17 at 20:29