Merging results of two different qualifier queries in SPARQL

55 Views Asked by At

I can't come up with the right way to describe my problem, so I'll just show it. I want to find towns (aka seats) in two subsidiary regions (subprovinces aka sancaks and districts aka kazas) of each province (aka vilayet) in a wikibase I've made of Ottoman placenames.

I have a query that works for the subprovinces and another that works for the districts, but I can't figure out how to combine them into a single query.

This is what I'm trying (on the query service of my wikibase). Basically it runs the two queries that I know work in parallel, then attempts to bind the ?vilayet and ?seat results from each :

# Map of every sancak and kaza seat within each vilayet, in the year 1900. Labels in Ottoman Turkish. To search a different year, change both dates in lines 50-52.
#defaultView:Map{"layer":"?vilayetLabel","hide":"?coord"}
PREFIX og: <https://ottgaz.org/entity/>
PREFIX ogs: <https://ottgaz.org/entity/statement/>
PREFIX ogv: <https://ottgaz.org/value/>
PREFIX ogt: <https://ottgaz.org/prop/direct/>
PREFIX ogp: <https://ottgaz.org/prop/>
PREFIX ogps: <https://ottgaz.org/prop/statement/>
PREFIX ogpq: <https://ottgaz.org/prop/qualifier/>

SELECT ?vilayetLabel ?seat_ota ?seat ?coord ?seatLabel
WHERE 
{ 
  # sancaks
  ?sancak ogp:P15 ?statement.
  ?statement ogps:P15 og:Q4.
  ?statement ogpq:P7 ?starttime.
  ?statement ogpq:P34 ?vilayet1.
  ?sancak ogt:P14 ?sancakSeat.
  ?sancakSeat ogt:P10 ?coord.
  OPTIONAL{?statement ogpq:P8 ?endtime.}
  OPTIONAL{?statement ogpq:P22 ?endtime.}
  
  # kazas
  ?kaza ogp:P15 ?statement2.
  ?statement2 ogps:P15 og:Q3.
  ?statement2 ogpq:P7 ?starttime2.
  ?statement2 ogpq:P34 ?sancak2.
  ?kaza ogt:P14 ?kazaSeat.
  ?kazaSeat ogt:P10 ?kazaCoord.
  OPTIONAL{?statement2 ogpq:P8 ?endtime2.}
  OPTIONAL{?statement2 ogpq:P22 ?endtime2.}
            
  # find vilayets for kazas
  ?sancak2 ogp:P15 ?statement3.
  ?statement3 ogps:P15 og:Q4.
  ?statement3 ogpq:P7 ?starttime3.
  ?statement3 ogpq:P34 ?vilayet2.
  OPTIONAL{?statement3 ogpq:P8 ?endtime3.}
  OPTIONAL{?statement3 ogpq:P22 ?endtime3.}
  
  # combine vilayets, seats
  BIND ( CONCAT(?vilayet1, ?vilayet2) AS ?vilayet)
  BIND ( CONCAT(?kazaSeat, ?sancakSeat) AS ?seat)
  
  # get ottoman label
  ?seat rdfs:label ?seat_ota filter (lang(?seat_ota) = "ota")
            
  #enter same year twice
  FILTER(YEAR(?starttime) <= 1900 && YEAR(?endtime) > 1900)
  FILTER(YEAR(?starttime2) <= 1900 && YEAR(?endtime2) > 1900)
  FILTER(YEAR(?starttime3) <= 1900 && YEAR(?endtime3) > 1900)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

It returns an "unknown error," and I can't figure out why. The queries are a bit intricate, because they involve qualifiers. Maybe I'm not binding or concatenating correctly?

0

There are 0 best solutions below