-
Got a SHACL graph where shapes have properties, in short form: ex:Foo a owl:Class,
sh:NodeShape ;
sh:property [ sh:class ex:Bar ;
sh:path ex:somePath ] . When collecting the triples for |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Triples are not "inside" a node (blank or otherwise). The square brackets are just a shortcut to spare you the trouple of "labelling" the blank node, but internally, all blank node get an arbitrary label. So your Turtle is equivalent to: ex:Foo a owl:Class .
ex:Foo a sh:NodeShape .
ex:Foo sh:property _:b .
_:b sh:class ex:Bar .
_:b sh:path ex:somePath . In order to get all the triples from a graph for triple in g.triples_matching([b], Any, Any) {
// do something with the triple
} A more elaborate example would be: let mut graph: LightGraph = turtle::parse_str(your_data).collect_triples()?;
let ex = Namespace::new("http://example.org/")?;
let sh = Namespace::new("http://www.w3.org/ns/shacl#")?;
// retrieve all sh:properties of ex:Foo
for t1 in graph.triples_matching([ex.get("Foo")?], [sh.get("property")?], Any) {
let prop = t1?.p();
// retrieve all the triples describing `prop`
for triple in graph.triples_matching([prop], Any, Any) {
// do something with the triple
}
} |
Beta Was this translation helpful? Give feedback.
Triples are not "inside" a node (blank or otherwise). The square brackets are just a shortcut to spare you the trouple of "labelling" the blank node, but internally, all blank node get an arbitrary label. So your Turtle is equivalent to:
In order to get all the triples from a graph
g
whose subject is a given blank nodebn
that you got, you can useGraph::triples_matching
. For example:A more elaborate example would be: