On 9/08/2016 9:31, Jack Hodges wrote:
I have looked at and run the ValidationExample from the github archive
and have looked carefully at the SHACL archive
ModelConstraintValidator. These are very helpful and I encourage
anyone playing with SHACL to look at them. This said, I have run into
a bit of a problem trying to extend the example. Here is a code
fragment from a modified version of the Validation Example in the
archive:
// Load the main data model
Model dataModel = JenaUtil.createMemoryModel();
dataModel.read(EDDLValidation.class.getResourceAsStream("/sh/project/vocab/Data.ttl"),
"urn:dummy", FileUtils.langTurtle);
Model schemaModel = JenaUtil.createMemoryModel();
schemaModel.read(ValidationExample.class.getResourceAsStream("/sh/project/schema/Schema.ttl"),
"urn:dummy", FileUtils.langTurtle);
// Load the shapes Model (here, includes the dataModel because that
has shape definitions too)
Model shaclModel = SHACLSystemModel.getSHACLModel();
MultiUnion unionGraph = new MultiUnion(new Graph[] {
shaclModel.getGraph(),
schemaModel.getGraph()
});
Model shapesModel = ModelFactory.createModelForGraph(unionGraph);
// Make sure all sh:Functions are registered
SHACLFunctions.registerFunctions(shapesModel);
// Create Dataset that contains both the main query model and the
shapes model
// (here, using a temporary URI for the shapes graph)
URI shapesGraphURI = URI.create("uri_path_to_schema_graph");
Dataset dataset = ARQFactory.get().getDataset(dataModel);
dataset.addNamedModel(shapesGraphURI.toString(), shapesModel);
So the questions here are as follows:
(1) does the schemaModel graph need to be a combined graph that
includes any imports (such as separate SPIN graphs) within it or is it
ok to be just the graph that has SHACL validation functions defined
within it? I suspect that it must include the SPIN graph, and would
that be done with a jena export from TBC of the related graphs?
To get this out of the way, the *shapes* graph needs to include at least:
- the W3C SHACL graph itself
- the DASH namespace
The latter includes the SPARQL queries and other info needed at runtime,
while the former should be there anyway, to get the class hierarchy
correct at runtime. I would assume the RDF systems graph should be
included, too. All this is handled by SHACLSystemModel.getSHACLModel as
a convenience. In addition to these, you certainly want to add your own
shapes to that graph, i.e. the schema model.
I see no relation to SPIN here - so any SPIN imports should be optional
when running SHACL. But yes, the simplest thing to do would be to
"flatten" all graphs imported by TBC e.g. using the Export/Merge wizard.
(2) in the ValidationExample a MultiUnion graph was used because there
were some SHACL definitions in the dataset. This would generally not
be the case so this extra layer wouldn't be necessary, right?
The union graph is the combination of the general SHACL system graphs
plus your actual data. The whole separation between the two graphs is
only needed if you have your shapes (i.e. classes or schema) separated
from instance data. By keeping them separate, the theory is that engines
need to do less work because they don't really need the specific
instances to figure out which shape declarations exist. If you are just
playing with SHACL in a normal set up, I don't think this performance
difference would be significant. So you can basically treat shapesModel
= dataModel.
(3) In my current case I am getting a result: @base
<http://example.org/random> .
Is this the kind of result to expect if there are no constraint
violations or have I done something wrong in the code fragment?
An empty results graph would mean no violations were found. It's hard to
guess whether this is correct without seeing the actual data and shapes.
HTH
Holger
--
You received this message because you are subscribed to the Google Group "TopBraid
Suite Users", the topics of which include the TopBraid Suite family of products and
its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to [email protected]
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.