Skip to content

Commit

Permalink
Merge pull request apache#716 from afs/shacl-misc
Browse files Browse the repository at this point in the history
cleanup: jena-shacl
  • Loading branch information
afs authored Mar 26, 2020
2 parents 81a777a + 663f334 commit 40c6000
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion jena-cmds/src/main/java/shacl/shacl.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void main(String...args) {
case "val": case "validate": case "v":
cmdExec = "validate";
break;
case "parse": case "p":
case "parse": case "p": case "print":
cmdExec = "parse";
break;

Expand Down
10 changes: 9 additions & 1 deletion jena-cmds/src/main/java/shacl/shacl_validate.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ protected void processModulesAndArgs() {
datafile = super.getValue(argData);
shapesfile = super.getValue(argShapes);

// No -- arguments, use act on single file of shapes and data.
if ( datafile == null && shapesfile == null ) {
if ( positionals.size() == 1 ) {
datafile = positionals.get(0);
shapesfile = positionals.get(0);
}
}

if ( datafile == null )
throw new CmdException("Usage: "+getSummary());
if ( shapesfile == null )
shapesfile = datafile;

textOutput = super.hasArg(argOutputText);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ private static Path path(Graph graph, Node node) {
return path;
}
}

//RDFDataMgr.write(System.out, graph, Lang.TTL);

// List<Node> x = G.find(graph, node, null, null).mapWith(Triple::getPredicate).toList();
// throw new ShaclParseException("Bad list: "+ShLib.displayStr(node)+" : "+x);
throw new ShaclParseException("Bad list: "+ShLib.displayStr(node));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class ValidationContext {
public ValidationContext(ValidationContext vCxt) {
this.shapes = vCxt.shapes;
this.dataGraph = vCxt.dataGraph;
this.verbose = vCxt.verbose;
this.strict = vCxt.strict;
}

public ValidationContext(Shapes shapes, Graph data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@
import java.util.Objects;
import java.util.Set;

import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.shacl.engine.ValidationContext;
import org.apache.jena.shacl.parser.ShaclParseException;
import org.apache.jena.shacl.parser.Shape;
import org.apache.jena.shacl.validation.ReportItem;

public abstract class CardinalityConstraint extends ConstraintEntity {

protected final int minCount;
protected final int maxCount;

@Override
public void validateNodeShape(ValidationContext vCxt, Graph data, Shape shape, Node focusNode) {
// Node shape with cardinality. Can this usefully be checked for in the parser?
throw new ShaclParseException("Cardinality constraint on a node shape");
}

// -1 => no test
protected CardinalityConstraint(int minCardinality, int maxCardinality) {
this.minCount = minCardinality;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.shacl.ShaclException;
import org.apache.jena.shacl.engine.ValidationContext;
import org.apache.jena.shacl.parser.Constraint;
import org.apache.jena.shacl.parser.Shape;
Expand All @@ -33,9 +32,7 @@
public abstract class ConstraintEntity implements Constraint {

@Override
public void validateNodeShape(ValidationContext vCxt, Graph data, Shape shape, Node focusNode) {
throw new ShaclException("Unexpected call (no path, no path nodes)");
}
public abstract void validateNodeShape(ValidationContext vCxt, Graph data, Shape shape, Node focusNode);

@Override
final
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public QualifiedValueShape(Shape sub, int qMin, int qMax, boolean qDisjoint) {
this.qMin = qMin;
this.qMax = qMax;
this.qDisjoint = qDisjoint;
// throw new NotImplemented(QualifiedValueShape.class.getSimpleName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ public ReportItem validate(ValidationContext vCxt, Graph data, Node node) {
boolean innerConforms = vCxt2.generateReport().conforms();
if ( innerConforms ) {
c++;
if ( c > 1 )
break;
// Choice: count all vs break as soon as error deteched
// if ( c > 1 )
// break;
}
}
if ( c == 1 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public static ConstraintComponents parseSparqlConstraintComponents(Graph shapesG
G.listAllNodesOfType(shapesGraph, SHACL.ConstraintComponent).forEach(sccNode->{
SparqlComponent c = sparqlConstraintComponent(shapesGraph, sccNode);
if ( c != null ) {
// System.out.print(c);
// System.out.println(c.getSparqlString());
for ( Parameter p : c.getParams() ) {
x.paramPathToComponents.put(p.getParameterPath(), c);
x.parameters.add(p);
Expand All @@ -100,7 +98,6 @@ public static List<Constraint> processShape(Graph shapesGraph, ConstraintCompone
continue;
// The parameter's property node
Node paramPath = param.getParameterPath();
//System.out.printf("Param: ?%s %s\n", param.getSparqlName(), param.getParameterPath());

// Does the shape use the parameter?
boolean b = G.contains(shapesGraph, shape.getShapeNode(), paramPath, null);
Expand All @@ -111,7 +108,6 @@ public static List<Constraint> processShape(Graph shapesGraph, ConstraintCompone
// // Find all shapes uses the parameter.
// List<Node> shapes = G.find(shapesGraph, null, paramPath, null).mapWith(Triple::getSubject).toList();
Node shNode = shape.getShapeNode();
//System.out.println("Shapes with param: "+shapes);

// All components with this parameter.
Collection<SparqlComponent> sccs = components.paramPathToComponents.get(paramPath);
Expand All @@ -123,7 +119,6 @@ public static List<Constraint> processShape(Graph shapesGraph, ConstraintCompone
// Check not seen.
Set<Node> x = new HashSet<>(required);
if ( seen.contains(x) ) {
//System.out.println("++++ Skip: "+scc);
return;
}
seen.add(x);
Expand Down Expand Up @@ -161,7 +156,6 @@ private static Multimap<Parameter, Node> constraintParameterValues(Graph shapesG
Node validatorNode = G.getZeroOrOneSP(shapesGraph, shNode, SHACL.validator);
Node vNode = firstNonNull(nodeValidatorNode, propertyValidatorNode, validatorNode);
Multimap<Parameter, Node> parameterValues = Parameters.parameterValues(shapesGraph, shNode, scc);
//parameterValues.forEach((p,v)->System.out.printf(" ?%s -- %s\n", p.getSparqlName(), v));
return parameterValues;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private static Constraint parseQualifiedValueShape(Graph g, Node s, Node p, Node
int vMax = intValue(qMax, -1);
Node qDisjoint = G.getZeroOrOneSP(g, s, SHACL.qualifiedValueShapesDisjoint);
if ( vMin < 0 && vMax < 0 )
throw new ShaclParseException("At least on of sh:qualifiedMinCount and sh:qualifiedMaxCount required");
throw new ShaclParseException("At least one of sh:qualifiedMinCount and sh:qualifiedMaxCount required");
return new QualifiedValueShape(sub, intValue(qMin, -1), intValue(qMax, -1), booleanValueStrict(qDisjoint)) ;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ static class ParserState {
public static Collection<Shape> parseShapes(Graph shapesGraph, Targets targets, Map<Node, Shape> shapesMap) {
Targets rootShapes = targets;

// Fast "nothing check"-> null.
if ( DEBUG )
OUT.println("SparqlConstraintComponents");
ConstraintComponents sparqlConstraintComponents = ConstraintComponents.parseSparqlConstraintComponents(shapesGraph);
Expand Down Expand Up @@ -107,15 +106,17 @@ public static Collection<Shape> parseShapes(Graph shapesGraph, Targets targets,
if ( sparqlConstraintComponents != null && ! sparqlConstraintComponents.isEmpty() ) {
// Deep for all shapes.
shapesMap.values().forEach(shape->{
//System.out.println(shape);
List<Constraint> x = ConstraintComponents.processShape(shapesGraph, sparqlConstraintComponents, shape);
if ( x != null && !x.isEmpty() ) {
// System.out.println("-- "+shape);
// System.out.println(">> "+x);
shape.getConstraints().addAll(x);
}
});
}

// Syntax rules for well-formed shapes.
//https://www.w3.org/TR/shacl/#syntax-rules
// Note - we only have the reachable shapes in "shapesMap".

return acc ;
}

Expand Down

0 comments on commit 40c6000

Please sign in to comment.