0

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

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?

1
  • 1
    your current query will miss all ?object. bindings where it is a literal as those can't be subjects of an RDF triple, thus, it would make the join with the second triple pattern being empty Commented Jan 11, 2023 at 16:53

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.