SPARQL Tips: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 12: | Line 12: | ||
} | } | ||
</sparql> | </sparql> | ||
== All persons with all properties == | |||
<sparql tryit="1"> | |||
PREFIX rlwd: <https://riga-literata.wikibase.cloud/entity/> | |||
PREFIX rlwdt: <https://riga-literata.wikibase.cloud/prop/direct/> | |||
SELECT ?person ?personLabel ?genderLabel ?birthdate ?birthplaceLabel ?deathdate ?deathplaceLabel ?qid ?viaf ?lnc10 | |||
WHERE | |||
{ | |||
?person rlwdt:P1 rlwd:Q6. | |||
OPTIONAL { ?person rlwdt:P15 ?gender.} | |||
OPTIONAL { ?person rlwdt:P18 ?birthdate.} | |||
OPTIONAL { ?person rlwdt:P20 ?birthplace.} | |||
OPTIONAL { ?person rlwdt:P19 ?deathdate.} | |||
OPTIONAL { ?person rlwdt:P21 ?deathplace.} | |||
OPTIONAL { ?person rlwdt:P6 ?qid.} | |||
OPTIONAL { ?person rlwdt:P30 ?viaf.} | |||
OPTIONAL { ?person rlwdt:P4 ?lnc10.} | |||
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]". } | |||
} | |||
</sparql> | |||
== Highlighting and color-coding SPARQL query == | == Highlighting and color-coding SPARQL query == | ||
ISSUE: ''the Wikidata [https://www.wikidata.org/wiki/Template:SPARQL SPARQL template] for query syntax highlighting is not implemented in this Wikibase''. | ISSUE: ''the Wikidata [https://www.wikidata.org/wiki/Template:SPARQL SPARQL template] for query syntax highlighting is not implemented in this Wikibase''. |
Revision as of 14:36, 17 January 2023
Prefixes
in Wikidata prefixes don't need to be specified explicitly in SPARQL queries. However, in our Wikibase.cloud instance, prefixes must be explicitly stated, as this example shows. Please note and mind the distinction between PREFIX kbwdt, kbwd, wdt and wd.
The following query uses these:
PREFIX rlwd: <https://riga-literata.wikibase.cloud/entity/>
PREFIX rlwdt: <https://riga-literata.wikibase.cloud/prop/direct/>
SELECT ?item ?itemLabel
WHERE
{
?item rlwdt:P1 rlwd:Q6.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]". }
}
All persons with all properties
PREFIX rlwd: <https://riga-literata.wikibase.cloud/entity/>
PREFIX rlwdt: <https://riga-literata.wikibase.cloud/prop/direct/>
SELECT ?person ?personLabel ?genderLabel ?birthdate ?birthplaceLabel ?deathdate ?deathplaceLabel ?qid ?viaf ?lnc10
WHERE
{
?person rlwdt:P1 rlwd:Q6.
OPTIONAL { ?person rlwdt:P15 ?gender.}
OPTIONAL { ?person rlwdt:P18 ?birthdate.}
OPTIONAL { ?person rlwdt:P20 ?birthplace.}
OPTIONAL { ?person rlwdt:P19 ?deathdate.}
OPTIONAL { ?person rlwdt:P21 ?deathplace.}
OPTIONAL { ?person rlwdt:P6 ?qid.}
OPTIONAL { ?person rlwdt:P30 ?viaf.}
OPTIONAL { ?person rlwdt:P4 ?lnc10.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]". }
}
Highlighting and color-coding SPARQL query
ISSUE: the Wikidata SPARQL template for query syntax highlighting is not implemented in this Wikibase.
- SOLUTION: Instead one must use a <sparql tryit="1">...</sparql> wrapper, as demonstrated in this example.
Look example above
Exact URL
The exact URL https://kbtestwikibase.wikibase.cloud/wiki/Project:SPARQL/examples, as well as the correct formatting of this page, are important to correctly display these query examples in the query services interface