1

I use GraphDB to store different production steps. The productionsteps are typified by their steps such as A,B,C,D. Process steps that belong together are connected by the object property ":hasUpstreamProduktionsnummer".

The data contains many different workflows. Where also a few production steps are missing. So, a Workflow can end with an instance of class B or start with an instance of Class C.

To visualize the workflow, I need to create a table that contains all production steps in one row and keeping a free space for the missing. For example:

A1  B1  C1
    B2  C2
A3  B3  
A4      
        C4

My approach was :hasUpstreamProduktionsnummer as transtiv and the following:

    select distinct ?A ?B ?C where {
    
    {   ?A a :A.
    ?A :hasUpstreamProduktionsnummer ?AUP.}
Optional
    { ?B owl:sameAs ?AUP.
    ?B a :B.}
Optional
    { ?C owl:sameAs ?AUP.
    ?C a :C. }
}
  

The query will result the following for Workflow 1:

    A1      C1
    A1  B1  
    A1  

Is there any option to query them in one row?

Is there any write the query more efficient? In my case I would need to write the same down for B and C as a starting point.

Data:

@base <http://BLB.de/Daten/Produktionsdaten/>
@prefix : <http://BLB.de/Daten/Produktionsdaten/> .
<A1> a :A;
:hasUpstreamProduktionsnummer <B1>.
<B1> a :B;
:hasUpstreamProduktionsnummer <C1>.
<C1> a :C.
<B2> a :B;
:hasUpstreamProduktionsnummer <C2>.
<C2> a :C.
<A3> a :A;
:hasUpstreamProduktionsnummer <B3>.
<B3> a :B.
<A4> a :A.
<C4> a :C

Thank you for helping in advance!

PhilippGr
  • 76
  • 6
  • what is the purpose of the `owl:sameAs` triple patterns? Also, i minimal proper sample of the RDF data is necessary. I'm too lazy to create data based on some vague description – UninformedUser Feb 10 '21 at 15:48
  • 1
    I want to reuse the variable ?AUP for the other patterns. Spezifing directly" ?AUP a :B" would prevent me using it for Processstep C. Using owl:sameAs was the most hands on way to do so. Let me know what kind of desciption helps to understand better. – PhilippGr Feb 10 '21 at 16:19
  • 1
    no need for transitivity and `owl:sameAs` reasoning enabled, here we go: `prefix : select distinct ?A ?B ?C where { { ?A a :A. OPTIONAL {?A :hasUpstreamProduktionsnummer ?B . ?B a :B Optional{?B :hasUpstreamProduktionsnummer ?C . ?C a :C. }} } UNION { ?B a :B Optional{?B :hasUpstreamProduktionsnummer ?C . ?C a :C. } filter not exists {?A :hasUpstreamProduktionsnummer ?B} } UNION { ?C a :C. filter not exists {?B :hasUpstreamProduktionsnummer ?C} } } ` – UninformedUser Feb 12 '21 at 10:53
  • Thanks a lot. This works out good for my project. Imagen there is not only 3 Classes A-C but a lot Classes, where I only need to select a 3 Classes. a :A; :hasUpstreamProduktionsnummer . a :AB; :hasUpstreamProduktionsnummer . a :B. :hasUpstreamProduktionsnummer a :BA; :hasUpstreamProduktionsnummer a :C; Would you use the same Query and transitivity for the to select the instances of Class A, B and C? – PhilippGr Feb 16 '21 at 14:59

1 Answers1

0

Problem solved by UninformedUser with SPARQL Elements Optional, Union and filter not exists in the following Query:

prefix : <http://BLB.de/Daten/Produktionsdaten/>  
select distinct ?A ?B ?C where {  
{ ?A a :A. 
OPTIONAL {?A :hasUpstreamProduktionsnummer ?B . 
?B a :B 
Optional{?B :hasUpstreamProduktionsnummer ?C . 
?C a :C. }} }
UNION { ?B a :B 
Optional{?B :hasUpstreamProduktionsnummer ?C . ?C a :C. } 
filter not exists {?A :hasUpstreamProduktionsnummer ?B} } 
UNION { ?C a :C.  filter not exists {?B :hasUpstreamProduktionsnummer ?C} } }
PhilippGr
  • 76
  • 6