Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Wikidata SPARL query by generic property return object instead of statement

I want to disseminate the query by spreading the nodes like in the below query.

SELECT ?item ?itemLabel  ?prop ?object ?objectLabel ?prop2 ?object2
WHERE 
{
  VALUES (?item) { (wd:Q12418)}
  ?item ?prop ?object.
   ?object ?prop2 ?object2
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
}

Here I start with wd:Q12418(Mona Lisa) and I retrieve all properties of it – than for each object I want to retrieve all properties of it as well.

The problem is that ?item ?prop ?object line returns statement for object rather than the object itself. So it’s pointing to Mona Lisa’s statement like this: https://www.wikidata.org/wiki/Q12418#Q12418$9c08a93a-4591-561d-36a9-78083ae0a3fa

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In this case second part (?object ?prop2 ?object2) works on this statement so it returns something if only that statement has subproperties. What I’d like to get is the object(e.g. painter Leonardo Da Vinci) rather than the statement so that I can iterate through object’s properties.

How can I achieve that?

>Solution :

You want ?prop to start with the wdt: prefix, then you can add this filter function:

filter(strstarts(str(?prop), str(wdt:)))

and, if you need, an analogous one for ?prop2.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading