How to check a sub-property at all levels, extended from the SPARQL * template?

In Wikidata I want to find the country of the goods. Either directly, if the goods have a country directly, or by going up to P131 (located in the administrative territorial unit) until I find the country. Here is the request:

?item wdt:P131*/wdt:P17 ?country.

The above query works fine ... unless the unit belonged to another country, for example Q25270 (Pristina). In this case, the result may be anachronistic. This is what I want to fix.

Great news: in such cases, we should consider only the unique P131 (located in the administrative-territorial unit), which does not have the sub-property P582 attached to it (end of time), and the problem is solved!

My question is : how to modify my request above to achieve this?

Example : let’s say that MyItem is in MyStreet, in MyTown is MyRegion in MyCountry, I have to make sure that MyStreet, MyTown and MyRegion do not have P582 (end time).

enter image description here

(If the "sub-property" is not the correct term, tell me the correct term and I will fix the question, thanks!)

Attempt

The query below works in most cases , but, unfortunately, it has an error: it finds the wrong country in cases where the current country is also a country in the past (for example, Alsace belonged to France until 1871, then to Germany and now during France again).

SELECT DISTINCT ?country WHERE {
  wd:Q6556803 wdt:P131* ?area .
  ?area wdt:P17 ?country .
  OPTIONAL {
    wd:Q6556803 wdt:P131*/p:P131 [
      pq:P582 ?endTime; ps:P131/wdt:P131* ?area
    ] .
  } .
  FILTER( !BOUND( ?endTime ) ) .
}
+3
source share
1 answer

Wikidata . , " - ", :

wd:Q25270 wdt:P131 wd:Q646035

( ):

wd:Q25270 p:P131 wds:Q25270-7df79cec-4938-8b6d-4e11-4dde6f72d73b .

wds:Q25270-7df79cec-4938-8b6d-4e11-4dde6f72d73b ps:P131 wd:Q646035 ;
    pq:P582 "1990-01-01T00:00:00Z"

, (pq:582):

SELECT DISTINCT ?s ?sLabel ?country ?countryLabel {
  VALUES ?s {
    wd:Q25270 
  }
  ?s wdt:P131* ?area .
  ?area wdt:P17 ?country .
  FILTER NOT EXISTS {
    ?s p:P131/(ps:P131/p:P131)* ?statement .
    ?statement ps:P131 ?area .
    ?s p:P131/(ps:P131/p:P131)* ?intermediateStatement .
    ?intermediateStatement (ps:P131/p:P131)* ?statement .
    ?intermediateStatement pq:P582 ?endTime .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
limit 50

?intermediateStatement - ?s .

-, ?s . , , , , - ( ).

+2

Source: https://habr.com/ru/post/1694936/


All Articles