kinow commented on a change in pull request #586: JENA-1733: SHACL engine, command line validator and Fuseki service. URL: https://github.com/apache/jena/pull/586#discussion_r306694354
########## File path: jena-shacl/src/main/java/org/apache/jena/shacl/engine/ShaclPaths.java ########## @@ -0,0 +1,419 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jena.shacl.engine; + +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.function.Consumer; + +import org.apache.jena.atlas.iterator.Iter; +import org.apache.jena.atlas.lib.NotImplemented; +import org.apache.jena.graph.Graph; +import org.apache.jena.graph.Node; +import org.apache.jena.graph.NodeFactory; +import org.apache.jena.graph.Triple; +import org.apache.jena.shacl.lib.G; +import org.apache.jena.shacl.lib.ShLib; +import org.apache.jena.shacl.parser.ShaclParseException; +import org.apache.jena.shacl.sys.C; +import org.apache.jena.shacl.vocabulary.SHACL; +import org.apache.jena.sparql.core.Prologue; +import org.apache.jena.sparql.path.*; +import org.apache.jena.sparql.path.eval.PathEval; + +public class ShaclPaths { +// SPARQL Property path: ex:parent +// SHACL Property path: ex:parent +// +// SPARQL Property path: ^ex:parent +// SHACL Property path: [ sh:inversePath ex:parent ] +// +// SPARQL Property path: ex:parent/ex:firstName +// SHACL Property path: ( ex:parent ex:firstName ) +// +// SPARQL Property path: rdf:type/rdfs:subClassOf* +// SHACL Property path: ( rdf:type [ sh:zeroOrMorePath rdfs:subClassOf ] ) +// +// SPARQL Property path: ex:father|ex:mother +// SHACL Property path: [ sh:alternativePath ( ex:father ex:mother ) ] + +// 2.3.1 SHACL Property Paths +// 2.3.1.1 Predicate Paths +// 2.3.1.2 Sequence Paths +// 2.3.1.3 Alternative Paths +// 2.3.1.4 Inverse Paths +// 2.3.1.5 Zero-Or-More Paths +// 2.3.1.6 One-Or-More Paths +// 2.3.1.7 Zero-Or-One Paths + + public static Set<Node> valueNodes(Graph graph, Node node, Path path) { + if ( path instanceof P_Link ) { + // Fast path common case. + Node p = ((P_Link)path).getNode(); + return G.setSP(graph, node, p); + } + // Value nodes are a set. + return Iter.toSet(pathReachIter(graph, node, path)); + } + + private static Iterator<Node> pathReachIter(Graph graph, Node node, Path path) { + if ( path instanceof P_Link ) { + // Fast path common case. + Node p = ((P_Link)path).getNode(); + // Not an extended iterator. + return G.iterSP(graph, node, p); + } + return PathEval.eval(graph, node, path, null); + } + + private static void toRDF(Graph graph, Node node, Path path) { + throw new NotImplemented(); + } + + // XXX Dev + public static Path parsePath(Graph graph, Node node) { + return path(graph, node); + } + + // XXX Better error checking. + private static Path path(Graph graph, Node node) { + if ( node.isURI() && ! C.NIL.equals(node) ) + return PathFactory.pathLink(node); + + if ( isList(graph, node) ) { + List<Node> nodes = G.rdfList(graph, node); + if ( nodes.isEmpty() ) + throw new ShaclParseException("Empty list for path sequnce"); Review comment: s/sequnce/sequence ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
