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_r306677124
########## File path: jena-shacl/src/main/java/org/apache/jena/shacl/lib/Transitive.java ########## @@ -0,0 +1,67 @@ +/* + * 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.lib; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.jena.atlas.iterator.Iter; +import org.apache.jena.graph.Graph; +import org.apache.jena.graph.Node; +import org.apache.jena.graph.Triple; + +public class Transitive { + + // ---- Transitive properties. + public static void transitive(Graph graph, boolean forward, Node node, Node predicate, Collection<Node> output) { + recurse(graph, forward, node, predicate, output); + } + + // Extracted and simpified From PathEval/PathEngineSPARQL. + private static void recurse(Graph graph, boolean forward, Node node, Node predicate, Collection<Node> output) { + Set<Node> visited = new HashSet<>(); + recurse_1(graph, forward, 0, -1, node, predicate, visited, output); + } + + private static void recurse_1(Graph graph, boolean forward, int stepCount, int maxStepCount, Node node, Node predicate, Set<Node> visited, Collection<Node> output) { + if ( maxStepCount >= 0 && stepCount > maxStepCount ) + return ; + if ( !visited.add(node) ) + return ; + output.add(node); + Iterator<Node> iter1 = singleStep(graph, forward, node, predicate) ; + // For each step, add to results and recurse. + for (; iter1.hasNext();) { + Node n1 = iter1.next() ; + recurse_1(graph, forward, stepCount + 1, maxStepCount, n1, predicate, visited, output) ; + } + } + + // A single step of a transitive properties. + // Because for SP? or ?PO, no duplicates occur, so works for both strategies. + private static Iterator<Node> singleStep(Graph graph, boolean forward, Node node, Node property) { + Iter<Node> iter2 = null ; Review comment: Not used `iter2` ---------------------------------------------------------------- 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
