SPARQL Query to create a merged graph from different graphs based on property value comparisons

Viewed 198

I have three graph data models with nodes representing the same physical entity in different ways in the three graphs.

Graph G1 where Pump P1 is of type CentrifugalPumpType Graph G1

Graph G2 where Pump P2 is of type PADIMType Graph G2

Graph G3 where Pump P3 is of type PumpType Graph G3

As you can see in the above three graphs the same Pump is being modelled in different ways. However there is a way to find out if they are indeed the same pump. Between the first graph (G1) and the second graph (G2) the comparison can be done based on the values of the TagNameAssignmentClass property (from the G1 graph) with that of SignalTag property (from the G2 graph), in this example they both have the value "P1612-A". Similary between G2 and the third Graph (G3) the comparison can be done between the Manufacturer properties from G2 and G3 (in the example they have the same value "XYZ") and the respective SerialNumber properties from G2 and G3 ((in the example they have the same value "1234"). All of these properties are direct or indirect properties of the node representing the same pump (P1, P2 and P3) in all three models. The aim of the merge would be to actually merge the node representing the pump in the three models. The merged Graph would then look something like this: Merged Graph

I am a complete newbie to this new way of thinking, I went through all the basic SPARQL tutorials that are out there, however this query that I am trying to write is too complex for my current level of understanding of SPARQL. It would be great if someone out there could help! The string literals are just to explain what I mean, I do not mean to mention the string literals in my query, rather I would just want to directly compare the properties that I mentioned without mentioning what literal value that is.

Edit 1: I was asked to create a minimal reproducible example, so here is a try after removing unnecessary properties and simplifying the aim further:

So the Graph G1 dataset is as follows:

@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> . 
@prefix eg1:    <http://www.myexample1.com> . 

eg1:PumpP1
    rdf:type eg1:CentrifugalPumpType ;
    has_property  eg1:DifferentialPressure ;
    has_property  eg1:TagNameAssignmentClass .

eg1:TagNameAssignmentClass
    rdf:value "P1612-A" . 

Graph G2 Dataset is as follows:

@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> . 
@prefix eg2:    <http://www.myexample2.com> . 
    
eg2:PumpP2
    rdf:type   eg2:PADIMType ;
    has_property  eg2:SignalSet ;
    has_property  eg2:Manufacturer ;
    has_property  eg2:SerialNumber .

eg2:Manufacturer
    rdf:value "XYZ" .

eg2:SerialNumber
    rdf:value "1234" .

eg2:SignalSet
    has_property eg2:SignalS1 .

eg2:SignalS1
    has_property eg2:SignalTag .

eg2:SignalTag
    rdf:value "P1612-A" .

Graph G3 Dataset may look like:

@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> . 
@prefix eg3:    <http://www.myexample3.com> . 
    
eg3:PumpP3
    rdf:type   eg3:PumpType ;
    has_property  eg3:Identification ;
    has_property  eg3:Ports .

eg3:Identification
    has_property  eg3:Manufacturer ;
    has_property  eg3:SerialNumber .

eg3:Manufacturer
    rdf:value "XYZ" .

eg3:SerialNumber
    rdf:value "1234" .

Expected Graph after the merge could look like this:

@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> . 
@prefix eg1:   <http://www.myexample1.com> .
@prefix eg2:   <http://www.myexample2.com> .
@prefix eg3:   <http://www.myexample3.com> . 
@prefix mg:    <http://www.mymergeexample.com> .
    
mg:PumpP
    rdf:type   eg1:CentrifugalPumpType ;
    rdf:type   eg2:PADIMType ;
    rdf:type   eg3:PumpType ;
    has_property  eg1:DifferentialPressure ;
    has_property  eg1:TagNameAssignmentClass ;
    has_property  eg2:Manufacturer ;
    has_property  eg2:SerialNumber ;
    has_property  eg2:SignalSet ;
    has_property  eg3:Identification ;
    has_property  eg3:Ports .

eg1:TagNameAssignmentClass
    rdf:value "P1612-A" .

eg2:Manufacturer
    rdf:value "XYZ" .

eg2:SerialNumber
    rdf:value "1234" .

eg2:SignalSet
    has_property eg2:SignalS1 .

eg2:SignalS1
    has_property eg2:SignalTag .

eg2:SignalTag
    rdf:value "P1612-A" .

eg3:Identification
    has_property  eg3:Manufacturer ;
    has_property  eg3:SerialNumber .

eg3:Manufacturer
    rdf:value "XYZ" .

eg3:SerialNumber
    rdf:value "1234" .

Please forgive syntax errors incase I might have made any.

0 Answers
Related