0

I have an oxigraph store that contains all of my information. At different points in time I construct various subgraphs from that store with the same columns ?s ?p and ?o.

At some point I want to combine any two of these subgraphs. Constructing a new subgraph with them is trivial, but how can I check for missing predicates that are in the main graph?

For example the first subgraph could include a relationship between a mother and daughter in a family. The second subgraph could have a father and son of that same family. These relationships are in the main graph since these are subgraphs, but the main graph could have relationships like the mother and father being spouses or the two children being siblings that I would want to include. Is there a way to go about this in a performant way?

Technical details: I technically create separate stores for each subgraph, but these stores can easily be dumped and loaded into the main store as different graphs, or just be kept in the same store from the beginning.

I've created a simple query like this:

CONSTRUCT {
  ?s ?p ?o .
} WHERE {
  {
    GRAPH <subgraph1IRI> {
      ?s ?p ?o .
    }
  }
  UNION
  {
    GRAPH <subgraph2IRI> {
      ?s ?p ?o .
    }
  }
}

But that's just merging. I've looked into FILTER, but what exactly the query is doing quickly gets confusing with my inexperience, especially wrapping my head around reversing every check to account for flipped subjects and objects.

  • I don't get it, what is wrong with your query? It returns all triples of two named graphs - if both graphs contain different triples about the same entities, then the returned graph contains all those triples about the entities. What else is missing? – UninformedUser Mar 18 '23 at 12:09
  • if relationships aka triples are neither in graph 1 or graph 2, then you need a) either some reasoning techniques based on your manually create domain rules to generate implicit triples or b) apply some machine learning technique, i.e. link prediction. – UninformedUser Mar 18 '23 at 12:10
  • The original query is only merging the 2 subgraphs without looking into the main graph for missing connections. I need something like "for any iri that's an s or o in subgraph1, find if there's triples in the main graph that match with any s's or o's in subgraph 2." and vice versa to get every combination of triple ordering. Plus there's the whole literals can't be subjects thing that may or may not be a factor in construction and performance. – Panda Pancake Mar 20 '23 at 21:05
  • with "main graph" I assume you mean the default graph. The you can simply query that as well in the `WHERE` clause: `... UNION { ?s ?p ?o GRAPH { ?s ?p1 ?o1 . } GRAPH { ?o ?p2 ?o2 . } }` - this example gives you triples from the default graph with subject being a subject in G1 and the object being a subject in G2 - you can simply add more `UNION` blocks for all the other combinations. Indeed, you could try to optimize and get all nodes for a named graph via a subquery and then proceed. – UninformedUser Mar 22 '23 at 06:45

0 Answers0