Wikimedia Belgium
bewikimedia
https://be.wikimedia.org/wiki/Wikimedia_Belgium
MediaWiki 1.47.0-wmf.16
first-letter
Media
Special
Talk
User
User talk
Wikimedia
Wikimedia talk
File
File talk
MediaWiki
MediaWiki talk
Template
Template talk
Help
Help talk
Category
Category talk
TimedText
TimedText talk
Module
Module talk
Translations
Translations talk
Wikidata Query logic
0
12561
38625
38624
2026-08-19T22:55:51Z
Geertivp
171
filter on qualifiers
38625
wikitext
text/x-wiki
[[File:Rdf mapping-vector.svg|thumb|600x600px|Wikidata Query logic schema]]
The '''Wikidata Query logic''' is based on the ''RDF Dump Format''/''LoD specifications''.
It describes the logic of [[SPARQL]] queries, that are built and executed via the [[Wikidata Query]] or related tools.
The model describes how the data is structured, and how queries can be constructed.
== Query logic choices ==
=== Object versus subject based ===
You can basically choose between two types of queries, depending on the item values you base your query on:
* ''object based queries'' (default), that search subjects having certain statements (this is the Wikidata standard query)
* and ''subject based queries'', to search related objects based on a subject item.
=== With or without qualifiers ===
You can query with and without qualifiers:
* When you want to execute ''straight queries'', without qualifiers, you can use the simple (straight) WDT property type filter. This is the Wikidata standard query. You can find this filter to the left of the schema.
* When you want to ''query with qualifiers'', you need to use the P, PS, and PQ property type filters. You can split WDT type filters into a combination of P and PS type queries. Then you go through intermediate WDS statements. Please look at the center of the schema. You can apply PQ qualifiers to get more information, or to add addional filters. Here you have the additional possibility to query for reference and value nodes.
== Example queries ==
=== Straight queries without qualifiers ===
==== Straight object based query ====
An object based query is searching for all subjects that have a link with the object. It only uses WDT property type filters. This is the standard Wiki Data query type, as automatically built when you start to filter for an item number.
List all persons where Guido Gezelle is relevant to them, and have an nlwiki page.<syntaxhighlight lang="sparql">
SELECT ?item ?itemLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
?item wdt:P3342 wd:Q336977.
{
?articleplus schema:about ?item;
schema:isPartOf <https://nl.wikipedia.org/>.
}
}
</syntaxhighlight>[https://w.wiki/TbVM Try!]
==== Straight subject based query ====
A subject based query starts from the subject, and ''cascades'' through its data connections. Basically it is the above query where the WDT statement is reversed.
List all relevant persons of Guido Gezelle, having an nlwiki page.<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
wd:Q336977 wdt:P3342 ?item
{
?articleplus schema:about ?item;
schema:isPartOf <https://nl.wikipedia.org/>.
}
}</syntaxhighlight>[https://w.wiki/TbVP Try!]
=== Queries with qualifiers ===
==== Object based query with qualifiers ====
An object based query is searching for all subject that have a link with the object.
List all persons where Guido Gezelle is relevant to them, and have an nlwiki page, with an indication of their role.<syntaxhighlight lang="sparql">
SELECT ?item ?itemLabel ?roleLabel ?startdt ?enddt WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
?item p:P3342 ?s.
?s ps:P3342 wd:Q336977.
OPTIONAL { ?s pq:P3831 ?role. }
OPTIONAL { ?s pq:P580 ?startdt. }
OPTIONAL { ?s pq:P582 ?enddt. }
{
?articleplus schema:about ?item;
schema:isPartOf <https://nl.wikipedia.org/>.
}
}
</syntaxhighlight>[https://w.wiki/TdL7 Run!]
==== Subject based query with qualifiers ====
A subject based query starts from the subject, and ''cascades'' through its data connections.
List all relevant persons of Guido Gezelle, having an nlwiki page, with an indication of their role.<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel ?roleLabel ?startdt ?enddt WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
wd:Q336977 p:P3342 ?s.
?s ps:P3342 ?item.
OPTIONAL { ?s pq:P3831 ?role. }
OPTIONAL { ?s pq:P580 ?startdt. }
OPTIONAL { ?s pq:P582 ?enddt. }
{
?articleplus schema:about ?item;
schema:isPartOf <https://nl.wikipedia.org/>.
}
}</syntaxhighlight>[https://w.wiki/TdLC Run!]
==== Subject based query with filter on qualifiers ====
List all persons that have started writing to Guido Gezelle in the 5 last years of his life, and have an nlwiki page.<syntaxhighlight lang="sparql">
SELECT ?item ?itemLabel ?roleLabel ?startdt ?enddt WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
wd:Q336977 p:P3342 ?s.
?s ps:P3342 ?item;
pq:P3831 wd:Q3589290, ?role;
pq:P580 ?startdt.
FILTER(?startdt >= "1894-01-01T00:00:00Z"^^xsd:dateTime)
OPTIONAL { ?s pq:P582 ?enddt. }
{
?articleplus schema:about ?item;
schema:isPartOf <https://nl.wikipedia.org/>.
}
}
ORDER BY (?startdt)
</syntaxhighlight>[https://w.wiki/TdM4 Run!]
== Other query tools ==
* [[Pywikibot SPARQL queries]]
== See also ==
* [[mw:Wikibase/Indexing/RDF_Dump_Format|RDF Dump Format]] (RDF/LoD specifications)
* [[Wikimedia Commons Wikibase queries]]
* [[SPARQL LoD queries]] (distributed queries)
[[Category:Wikidata Query]]
7cch9zcwl6b9cc2ex8wuj5y3ce3od9y