query-20b7e0be73a5af21e214c79256c4ee4b
REGEX usage example:
buildings in Manhattan that have "Drive", "Avenue" or "Street" in their label
SELECT DISTINCT ?object ?objectLabel ?voieLabel ?streetNumber WHERE { ?object wdt:P131 wd:Q11299 ; rdfs:label ?label . ?object p:P669 ?voie. OPTIONAL { ?voie pq:P670 ?streetNumber. } SERVICE wikibase:label { bd:serviceParam wikibase:language "en,fr". } FILTER REGEX(STR(?label), "Drive|Avenue|Street") FILTER(!BOUND(?streetNumber)) }
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# REGEX usage example:
# buildings in Manhattan that have "Drive", "Avenue" or "Street" in their label
SELECT DISTINCT ?object ?objectLabel ?voieLabel ?streetNumber
WHERE {
?object wdt:P131 wd:Q11299 ; rdfs:label ?label .
?object p:P669 ?voie.
OPTIONAL { ?voie pq:P670 ?streetNumber. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,fr". }
FILTER REGEX(STR(?label), "Drive|Avenue|Street")
FILTER(!BOUND(?streetNumber))
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v2("?label")
v3("?object"):::projected
v1("?streetNumber"):::projected
v4("?voie")
c3(["wd:Q11299"]):::iri
c8(["bd:serviceParam"]):::iri
c10(["en,fr"]):::literal
f0[["not bound(?streetNumber)"]]
f0 --> v1
f1[["regex(str(?label),'Drive|Avenue|Street')"]]
f1 --> v2
v3 --"p:direct/P131"--> c3
v3 --"rdfs:label"--> v2
v3 --"p:P669"--> v4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:qualifier/P670".-> v1
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c8 --"wikibase:language"--> c10
end