title: SPARQL Query to create a merged graph from different graphs based on property value comparisons
body: <p>I have three graph data models with nodes representing the same physical entity in different ways in the three graphs.</p>
  <p>Graph G1 where <em>Pump P1</em> is of type <em>CentrifugalPumpType</em>
  <a href="https://i.stack.imgur.com/qndWW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qndWW.png" alt="Graph G1" /></a></p>
  <p>Graph G2 where <em>Pump P2</em> is of type <em>PADIMType</em>
  <a href="https://i.stack.imgur.com/hIC96.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hIC96.png" alt="Graph G2" /></a></p>
  <p>Graph G3 where <em>Pump P3</em> is of type <em>PumpType</em>
  <a href="https://i.stack.imgur.com/tZfWX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tZfWX.png" alt="Graph G3" /></a></p>
  <p>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 <em>TagNameAssignmentClass</em> property (from the G1 graph) with that of <em>SignalTag</em> property (from the G2 graph), in this example they both have the value &quot;P1612-A&quot;. Similary between G2 and the third Graph (G3) the comparison can be done between the <em>Manufacturer</em> properties from G2 and G3 (in the example they have the same value &quot;XYZ&quot;) and the respective <em>SerialNumber</em> properties from G2 and G3 ((in the example they have the same value &quot;1234&quot;). 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:
  <a href="https://i.stack.imgur.com/wQ1iE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wQ1iE.png" alt="Merged Graph" /></a></p>
  <p>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.</p>
  <p>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:</p>
  <p>So the Graph G1 dataset is as follows:</p>
  <pre><code>@prefix rdf:    &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns&gt; .
  @prefix rdfs:   &lt;http://www.w3.org/2000/01/rdf-schema#&gt; . 
  @prefix eg1:    &lt;http://www.myexample1.com&gt; . 
  
  eg1:PumpP1
      rdf:type eg1:CentrifugalPumpType ;
      has_property  eg1:DifferentialPressure ;
      has_property  eg1:TagNameAssignmentClass .
  
  eg1:TagNameAssignmentClass
      rdf:value &quot;P1612-A&quot; . 
  </code></pre>
  <p>Graph G2 Dataset is as follows:</p>
  <pre><code>@prefix rdf:    &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns&gt; .
  @prefix rdfs:   &lt;http://www.w3.org/2000/01/rdf-schema#&gt; . 
  @prefix eg2:    &lt;http://www.myexample2.com&gt; . 
      
  eg2:PumpP2
      rdf:type   eg2:PADIMType ;
      has_property  eg2:SignalSet ;
      has_property  eg2:Manufacturer ;
      has_property  eg2:SerialNumber .
  
  eg2:Manufacturer
      rdf:value &quot;XYZ&quot; .
  
  eg2:SerialNumber
      rdf:value &quot;1234&quot; .
  
  eg2:SignalSet
      has_property eg2:SignalS1 .
  
  eg2:SignalS1
      has_property eg2:SignalTag .
  
  eg2:SignalTag
      rdf:value &quot;P1612-A&quot; .
  </code></pre>
  <p>Graph G3 Dataset may look like:</p>
  <pre><code>@prefix rdf:    &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns&gt; .
  @prefix rdfs:   &lt;http://www.w3.org/2000/01/rdf-schema#&gt; . 
  @prefix eg3:    &lt;http://www.myexample3.com&gt; . 
      
  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 &quot;XYZ&quot; .
  
  eg3:SerialNumber
      rdf:value &quot;1234&quot; .
  </code></pre>
  <p>Expected Graph after the merge could look like this:</p>
  <pre><code>@prefix rdf:   &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns&gt; .
  @prefix rdfs:  &lt;http://www.w3.org/2000/01/rdf-schema#&gt; . 
  @prefix eg1:   &lt;http://www.myexample1.com&gt; .
  @prefix eg2:   &lt;http://www.myexample2.com&gt; .
  @prefix eg3:   &lt;http://www.myexample3.com&gt; . 
  @prefix mg:    &lt;http://www.mymergeexample.com&gt; .
      
  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 &quot;P1612-A&quot; .
  
  eg2:Manufacturer
      rdf:value &quot;XYZ&quot; .
  
  eg2:SerialNumber
      rdf:value &quot;1234&quot; .
  
  eg2:SignalSet
      has_property eg2:SignalS1 .
  
  eg2:SignalS1
      has_property eg2:SignalTag .
  
  eg2:SignalTag
      rdf:value &quot;P1612-A&quot; .
  
  eg3:Identification
      has_property  eg3:Manufacturer ;
      has_property  eg3:SerialNumber .
  
  eg3:Manufacturer
      rdf:value &quot;XYZ&quot; .
  
  eg3:SerialNumber
      rdf:value &quot;1234&quot; .
  </code></pre>
  <p>Please forgive syntax errors incase I might have made any.</p>