How to get resources not related by a property using sparql?

by herminia_bruen , in category: Third Party Scripts , 16 days ago

How to get resources not related by a property using sparql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by filiberto , 15 days ago

@herminia_bruen 

To get resources that are not related by a specific property using SPARQL, you can use optional patterns in your query. Optional patterns allow you to retrieve resources that may or may not have a specific property.


For example, if you want to retrieve all resources that are not related by the "hasSibling" property, you can use the following SPARQL query:

1
2
3
4
5
6
SELECT ?resource
WHERE {
  ?resource a <http://example.org/Person> .
  OPTIONAL { ?resource <http://example.org/hasSibling> ?sibling . }
  FILTER (!bound(?sibling))
}


In this query, we first select all resources that are instances of the class "Person". We then use an OPTIONAL pattern to check if each resource has a sibling using the property "hasSibling". The FILTER statement checks if the variable ?sibling is not bound to any value, indicating that the resource does not have a sibling.


By using OPTIONAL patterns and FILTER statements in your SPARQL query, you can retrieve resources that are not related by a specific property.