Search in sources :

Example 1 with PathVisitorBase

use of org.apache.jena.sparql.path.PathVisitorBase in project webofneeds by researchstudio-sat.

the class MainTypesPostprocessor method pathToTriples.

private static List<Triple> pathToTriples(Path path) {
    List<Triple> triples = new ArrayList<>();
    path.visit(new PathVisitorBase() {

        private Node tip = NodeFactory.createBlankNode("start");

        @Override
        public void visit(P_Link pathNode) {
            Node nextTip = NodeFactory.createBlankNode();
            Triple nextStep = new Triple(tip, pathNode.getNode(), nextTip);
            triples.add(nextStep);
            tip = nextTip;
        }

        public void visit(P_Inverse pathNode) {
            Path uninverted = pathNode.getSubPath();
            if (uninverted instanceof P_Link) {
                Node nextTip = NodeFactory.createBlankNode();
                Triple nextStep = new Triple(nextTip, ((P_Link) uninverted).getNode(), tip);
                triples.add(nextStep);
                tip = nextTip;
            }
        }
    });
    return triples;
}
Also used : PropertyPath(won.shacl2java.annotation.PropertyPath) Path(org.apache.jena.sparql.path.Path) P_Link(org.apache.jena.sparql.path.P_Link) P_Inverse(org.apache.jena.sparql.path.P_Inverse) PathVisitorBase(org.apache.jena.sparql.path.PathVisitorBase)

Example 2 with PathVisitorBase

use of org.apache.jena.sparql.path.PathVisitorBase in project webofneeds by researchstudio-sat.

the class NameUtils method propertyNameForPath.

public static Optional<String> propertyNameForPath(Path path) {
    StringBuilder propertyName = new StringBuilder();
    path.visit(new PathVisitorBase() {

        @Override
        public void visit(P_Link pathNode) {
            propertyName.append(pathNode.getNode().getLocalName());
        }

        public void visit(P_Inverse pathNode) {
            Path uninverted = pathNode.getSubPath();
            if (uninverted instanceof P_Link) {
                visit((P_Link) uninverted);
                propertyName.append("Inv");
            }
        }
    });
    String ret = propertyName.toString();
    if (ret.length() == 0) {
        return Optional.empty();
    }
    return Optional.of(ret);
}
Also used : Path(org.apache.jena.sparql.path.Path) P_Link(org.apache.jena.sparql.path.P_Link) P_Inverse(org.apache.jena.sparql.path.P_Inverse) PathVisitorBase(org.apache.jena.sparql.path.PathVisitorBase)

Aggregations

P_Inverse (org.apache.jena.sparql.path.P_Inverse)2 P_Link (org.apache.jena.sparql.path.P_Link)2 Path (org.apache.jena.sparql.path.Path)2 PathVisitorBase (org.apache.jena.sparql.path.PathVisitorBase)2 PropertyPath (won.shacl2java.annotation.PropertyPath)1