The construct query is supposed to reveal a specific hierarchy. Starting from my leaf object a component of a machine (going upwards) until my root object (company). BUT, what it does is, if I start at a leaf node, iterate to next, then all patterns "?prev skos:broader ?next" are allowed. Which means I have a leaf, go up one level (machine) and next to my start leaf, I see multiple other leafs (other machine components) which are valid but not wanted.
construct {
?start a :Start . #start node
?prev # declare the previous variable
skos:broader ?next ; # hierarchy iteration
a ?prevType ; # return type
rdfs:label ?prevName ; #label of the asserted node
.
?next
a ?nextType ;
rdfs:label ?nextName ;
.
}
WHERE
{
GRAPH (named graph)
{
values ?start { <IRI> } #leaf node
?start skos:broader+ ?next .
?prev
skos:broader ?next ;
a ?prevType ;
rdfs:label ?prevName ;
.
?next
a ?nextType ;
rdfs:label ?nextName ;
bind(localname(?prevType) as ?prevTypeName)
bind(localname(?nextType) as ?nextTypeName)
}
Pic1: Problem of tripples at the same level
So, at the end of my WHERE, I tried to add an EXIST filter. The purpose is to only filter for patterns that start at my start node and disregard all others aside from that direct path. This query shows what I want BUT skips the first skos:borader relation. So I have my leave node (component) (rdf:type Start) but then there is a missing "skos:borader" to my next node in the hierarchy (machine). But from there all other hierarchies (up to company) are returned correctly. It's just that first hop
Big question, how do I declare my start right, so the first skos:borader to my L2 node is correctly asserted?
WHERE
{
GRAPH (named graph)
{
values ?start { <IRI> } #leaf node
?start skos:broader+ ?next .
?prev
skos:broader ?next ;
a ?prevType ;
rdfs:label ?prevName ;
.
?next
a ?nextType ;
rdfs:label ?nextName ;
bind(localname(?prevType) as ?prevTypeName)
bind(localname(?nextType) as ?nextTypeName)
}
#PRUPOSE: from all valid skos:borader defined in the construct part abouve -> filter out only the direct paths at each level which derive from ?start directly
Filter EXISTS {
?start skos:broader+ ?prev .
?prev skos:broader ?next }
}
I'm not exactly sure if I understand your problem correctly. But it seems to me that if you want to go 'up' and 'down', from your starting point, the problem might be caused by the
Maybe if you try something like
you will not get the undesired results?
Hope I'm not pointing you in the wrong direction.