0

I want to a query to load a resource and automatically load all resources connected by a 'DependencyProperty'.

The query below does what I want up to 3 levels deep. I'm wondering if it can be altered - potentially with property paths? - in such a way that there is no limit to how deep it goes.

SELECT * WHERE { 
    :resourceToLoad ?p ?o.
    OPTIONAL { 
        ?p rdf:type :DependencyProperty.
        ?o ?p2 ?o2.
        OPTIONAL { 
            ?p2 rdf:type :DependencyProperty.
            ?o2 ?p3 ?o3.
            OPTIONAL { 
                ?p3 rdf:type :DependencyProperty.
                ?o3 ?p4 ?o4.
            }
        }
    }
}
Flion
  • 10,468
  • 13
  • 48
  • 68

1 Answers1

2

So I found a solution myself for now. I added

:DependencyProperty rdfs:subClassOf [
    a owl:Restriction;
    owl:onProperty rdfs:subPropertyOf;
    owl:hasValue :dependency;
]

now every property that is a :DependencyProperty is a subPropertyOf :dependency, so every time a dependency property appears as predicate in a triple, another triple is created with :dependency as predicate.

So now I can query like this:

SELECT * WHERE { {
    ?s?p ?o
    FILTER(?s= :resourceToLoad)
} UNION {
    :resourceToLoad :dependency+ ?s.
    ?s?p ?o.
}}
Flion
  • 10,468
  • 13
  • 48
  • 68
  • 1
    this works only for triples with the predicate being `:DependencyProperty` itself, but not for properties of type `:DependencyProperty` as you've asked for in your question - or am I wrong? – UninformedUser Aug 09 '18 at 08:59
  • `:a :DependencyProperty :b . -> :b rdfs:subPropertyOf :dependency . ` - that follows from the range axiom. – UninformedUser Aug 09 '18 at 09:02
  • Ah you're right, typo.. it should be rdfs:subClassOf instead of rdfs:range. That's way it works (and is how its working for me). `:a :p :b` & `:p rdf:type :DependencyProperty` => `:a :dependency :b`. – Flion Aug 09 '18 at 20:01