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;
}
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);
}
Aggregations