In this project I want to collect useful SPARQL queries for the WikiData endpoint for use with the InfoRapid KnowledgeBase Builder. Please participate and publish your own favorite SPARQL queries.
i_ : item
ic_ : item category, the column values are ignored, only the column header is relevant
in_ or i_XXXLabel or ic_XXXLabel: item name
id_ or i_XXXDescription or ic_XXXDescription: item description
iu_ : item url
ii_ : item image
idi_ : item description image
rn_ : relation name
rn_t_ : relation name for a table relation
rc_ : relation category
The columns in the SELECT statement must have the following order (the values in round brackets are optional)
?i_item1 (?ic_item1) (?in_item1) (?id_item1) (?iu_item1) (?ii_item1) (?rn_relation1) (?rc_relation1) ?i_item2 (?ic_item2) ... (?rn_relation2) (?i_item3) ...
This SELECT statement connects item1 through relation1 with item2 and through relation 2 with item3
One result row can connect item1 with any number of other items
A line starting with the comment #query can be used to separte many queries
BIND (CONCAT (STR (?url), "§if") AS ?iu_url).
OPTIONAL { ?i_place p:P625 ?statement.
?statement psv:P625 ?coordinate_node.
?coordinate_node wikibase:geoLatitude ?lat.
?coordinate_node wikibase:geoLongitude ?long.
BIND (CONCAT ("http://www.google.com/maps/place/", STR(?lat), ",", STR(?long), "§if") AS ?iu_url).
}
OPTIONAL { ?iu_wikipedia_url schema:about ?i_item; schema:isPartOf <https://en.wikipedia.org/> }
?centerPlace wdt:P625 ?centerLoc.
SERVICE wikibase:around {
?i_place wdt:P625 ?location. # the first statement must include the place and the location
bd:serviceParam wikibase:center ?centerLoc.
bd:serviceParam wikibase:radius "10". # maximum distance in kilometers
bd:serviceParam wikibase:distance ?dist. # current distance in kilometers
}
BIND (geof:distance (?location1, ?location2) AS ?dist).
BIND (CONCAT (xsd:string (xsd:integer (CEIL (100 * ?dist) * 10)), " m") AS ?rounded_dist_in_m).
?item1 ?property ?item2.
OPTIONAL { ?propertyName wikibase:directClaim ?property. }
OPTIONAL { ?i_item wdt:P18 ?ii_itemImage. }
OPTIONAL { ?i_person wdt:P569 ?ic_DateOfBirth. }
OPTIONAL { ?rn_t_DateOfBirth wikibase:directClaim wdt:P569. }
OPTIONAL { ?i_person wdt:P570 ?ic_DateOfDeath. }
OPTIONAL { ?rn_t_DateOfDeath wikibase:directClaim wdt:P570. }
OPTIONAL { ?i_person wdt:P19 ?ic_PlaceOfBirth. }
OPTIONAL { ?rn_t_PlaceOfBirth wikibase:directClaim wdt:P19. }
OPTIONAL { ?i_person wdt:P20 ?ic_PlaceOfDeath. }
OPTIONAL { ?rn_t_PlaceOfDeath wikibase:directClaim wdt:P20. }
VALUES (?item) {(wd:Q138809)}