0

I have a graph of RDF data, that is the result of a SPARQL query in rdflib, but this question is valid just on any endpoint too. The graph looks like the picture below.

I want to find a way to query the nodes that are shared between two clusters. Those are basically the nodes that are:

  • Subject to two objects
  • Object to two subjects
  • Object to a subject, and, then subject to another object

I tried with Graph.subjects() and Graph.objects() on rdflib it seems to me that they are only iterable and I have to iterate the whole graph three times, for each of the above scenarios, and it would result in a lot of double counting.

I was wondering if anyone has an idea on how to do this in a better way, perhaps within SPARQL to begin with.

visualization

TallTed
  • 9,069
  • 2
  • 22
  • 37
  • you know, it's always better too provide a sample of the RDF data (**not** in RDF/XML syntax please) + the expected result as RDF data when you're asking for SPARQL queries. – UninformedUser Dec 20 '18 at 08:39
  • Subject to two objects: `?s ?p1 ?o1. ?s ?p2 ?o2 . filter(?o1 != ?o2)` - something like that? The other cases are analogous, just write the triple patterns, it's mostly trivial as long as you don't have further restrictions we don't know yet – UninformedUser Dec 20 '18 at 08:41

0 Answers0