use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PredicateElement method visitPredicatePathBinding.
/**
* Visit predicate path binding.
*
* @param pathBinding the path binding
* @param pathIteration the path iteration
* @return the path binding
*/
private PathBinding visitPredicatePathBinding(PathBinding pathBinding, Integer pathIteration) {
StatementBinding predicateEdge;
Variable sourceVariable = this.getSourceVariable();
Variable targetVariable = this.getTargetVariable();
Variable intermediateSourceVariable = null;
Variable intermediateTargetVariable = null;
Variable priorIntermediateTargetVariable = null;
for (int iteration = 1; iteration <= getCardinality(pathIteration); iteration++) {
if (iteration == 1) {
intermediateSourceVariable = sourceVariable;
}
if (iteration < getCardinality(pathIteration)) {
if (iteration > 1)
intermediateSourceVariable = priorIntermediateTargetVariable;
intermediateTargetVariable = new Variable(targetVariable.getName() + "_i" + iteration);
priorIntermediateTargetVariable = intermediateTargetVariable;
}
if (iteration == getCardinality(pathIteration)) {
if (iteration > 1)
intermediateSourceVariable = priorIntermediateTargetVariable;
intermediateTargetVariable = targetVariable;
}
predicateEdge = new StatementBinding(intermediateSourceVariable, getPredicateVariable(), intermediateTargetVariable, getIsInverseOf());
pathBinding.add(predicateEdge);
}
return pathBinding;
}
use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class SequencePathElement method pathPatternQuery.
/**
* Path pattern query.
*
* @param sourceVariable the source variable
* @param predicateVariable the predicate variable
* @param targetVariable the target variable
* @param pathIteration the path iteration
* @param customQueryOptions the custom query options
* @return the path tuple expr
*/
@Override
public PathTupleExpr pathPatternQuery(Variable sourceVariable, Variable predicateVariable, Variable targetVariable, Integer pathIteration, CustomQueryOptions customQueryOptions) {
if (sourceVariable == null)
sourceVariable = this.getSourceVariable();
if (targetVariable == null)
targetVariable = this.getTargetVariable();
TupleExpr intermediateJoinPattern = null;
PathTupleExpr joinPattern = null;
if (getCardinality(pathIteration) > 0) {
Variable intermediateSourceVariable = null;
Variable intermediateVariable = null;
Variable intermediateTargetVariable = null;
Variable priorIntermediateTargetVariable = null;
for (int iteration = 1; iteration <= getCardinality(pathIteration); iteration++) {
if (iteration == 1) {
intermediateSourceVariable = sourceVariable;
// getLeftPathElement().getTargetVariable();
intermediateVariable = new Variable(getLeftPathElement().getTargetVariable().getName(), getLeftPathElement().getTargetVariable().getValue());
intermediateTargetVariable = targetVariable;
}
if (iteration < getCardinality(pathIteration)) {
if (iteration > 1)
intermediateSourceVariable = priorIntermediateTargetVariable;
intermediateTargetVariable = new Variable(sourceVariable.getName() + "_i" + iteration);
intermediateVariable = new Variable(sourceVariable.getName() + "_in" + iteration);
priorIntermediateTargetVariable = intermediateTargetVariable;
}
if (iteration == getCardinality(pathIteration)) {
if (iteration > 1) {
intermediateSourceVariable = priorIntermediateTargetVariable;
intermediateVariable = new Variable(sourceVariable.getName() + "_in" + iteration);
intermediateTargetVariable = targetVariable;
}
}
PathTupleExpr leftPattern = getLeftPathElement().pathPatternQuery(intermediateSourceVariable, predicateVariable, intermediateVariable, pathIteration, customQueryOptions);
PathTupleExpr rightPattern;
if (leftPattern == null) {
intermediateVariable.setValue(intermediateSourceVariable.getValue());
// intermediateVariable.setName(intermediateSourceVariable.getName());
rightPattern = getRightPathElement().pathPatternQuery(intermediateVariable, predicateVariable, intermediateTargetVariable, pathIteration, customQueryOptions);
} else {
rightPattern = getRightPathElement().pathPatternQuery(leftPattern.getStatementBinding().getTargetVariable(), predicateVariable, intermediateTargetVariable, pathIteration, customQueryOptions);
}
if (leftPattern != null)
if (rightPattern != null)
intermediateJoinPattern = new Join(leftPattern.getTupleExpr(), rightPattern.getTupleExpr());
else {
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
intermediateVariable.setName(intermediateTargetVariable.getName());
// Projection bindRight = new Projection((TupleExpr) intermediateVariable);
intermediateJoinPattern = leftPattern.getTupleExpr();
}
else {
if (rightPattern != null)
intermediateJoinPattern = rightPattern.getTupleExpr();
else
intermediateJoinPattern = null;
}
if (joinPattern == null) {
joinPattern = new PathTupleExpr((TupleExpr) intermediateJoinPattern);
if (leftPattern != null) {
joinPattern.getPath().addAll(leftPattern.getPath());
joinPattern.setStatementBinding(leftPattern.getStatementBinding());
}
if (rightPattern != null) {
joinPattern.getPath().addAll(rightPattern.getPath());
joinPattern.setStatementBinding(rightPattern.getStatementBinding());
}
} else {
joinPattern.setTupleExpr(new Join(joinPattern.getTupleExpr(), intermediateJoinPattern));
if (leftPattern != null) {
joinPattern.getPath().addAll(leftPattern.getPath());
joinPattern.setStatementBinding(leftPattern.getStatementBinding());
}
if (rightPattern != null) {
joinPattern.getPath().addAll(rightPattern.getPath());
joinPattern.setStatementBinding(rightPattern.getStatementBinding());
}
}
}
joinPattern.setBoundVariable(joinPattern.getStatementBinding().getSourceVariable());
return joinPattern;
} else {
return null;
}
}
use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitReifiedPredicate.
/**
* Visit reified predicate.
*
* @param ctx the ctx
* @return the predicate element
*/
@Override
public PredicateElement visitReifiedPredicate(ReifiedPredicateContext ctx) {
// reifiedPredicate : iriRef? REIFIER predicateRef factFilterPattern? dereifier? ; #statementFilterPattern
PredicateElement reifiedPredicateElement = new PredicateElement(this.repositoryContext);
reifiedPredicateElement.setIsReified(true);
if (ctx.iriRef() != null) {
reifiedPredicateElement.setReification(((IriRefValueElement) visit(ctx.iriRef())).getIri());
}
if (ctx.predicateRef() != null) {
reifiedPredicateElement.setPredicate(((IriRefValueElement) visit(ctx.predicateRef())).getIri());
}
if (ctx.factFilterPattern() != null) {
reifiedPredicateElement.setObjectFilterElement((FactFilterElement) visit(ctx.factFilterPattern()));
}
if (ctx.dereifier() != null) {
reifiedPredicateElement.setIsDereified(true);
}
return reifiedPredicateElement;
}
use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitPredicate.
/**
* Visit predicate.
*
* @param ctx the ctx
* @return the predicate element
*/
@Override
public PredicateElement visitPredicate(PredicateContext ctx) {
// predicate : ( reifiedPredicate | predicateRef | rdfType | '*' ) factFilterPattern? #objectFilterPattern
PredicateElement predicateElement = null;
if (ctx.reifiedPredicate() != null) {
predicateElement = (PredicateElement) visit(ctx.reifiedPredicate());
predicateElement.setOperator(PathConstants.Operator.PREDICATE);
} else if (ctx.predicateRef() != null) {
predicateElement = new PredicateElement(this.repositoryContext);
predicateElement.setOperator(PathConstants.Operator.PREDICATE);
IriRefValueElement predicateRef = ((IriRefValueElement) visit(ctx.predicateRef()));
predicateElement.setPredicate(predicateRef.getIri());
} else if (ctx.rdfType() != null) {
predicateElement = new PredicateElement(this.repositoryContext);
predicateElement.setOperator(PathConstants.Operator.PREDICATE);
predicateElement.setPredicate((iri("http://rdftype")));
} else if (ctx.anyPredicate() != null) {
predicateElement = new PredicateElement(this.repositoryContext);
predicateElement.setOperator(PathConstants.Operator.PREDICATE);
predicateElement.setAnyPredicate(true);
}
if (ctx.factFilterPattern() != null) {
if (ctx.reifiedPredicate() != null) {
predicateElement.setStatementFilterElement((FactFilterElement) visit(ctx.factFilterPattern()));
} else {
predicateElement.setObjectFilterElement((FactFilterElement) visit(ctx.factFilterPattern()));
}
}
return predicateElement;
}
use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternQueryExpressionTests method test_1.
/**
* Test 1.
*/
@Test
@Order(1)
void test_1() {
CharStream input = CharStreams.fromString("^:Attribute@:volumeFlow");
PathElement element = prepareElement(input);
// Query.assertEqualsWOSpaces
assertEquals("Join\r\n" + " Join\r\n" + " Union\r\n" + " StatementPattern\r\n" + " Variable (name=r1)\r\n" + " Variable (name=object1, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#object)\r\n" + " Variable (name=n0)\r\n" + " StatementPattern\r\n" + " Variable (name=n0)\r\n" + " Variable (name=isObjectOf1, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#object)\r\n" + " Variable (name=r1)\r\n" + " Union\r\n" + " StatementPattern\r\n" + " Variable (name=r1)\r\n" + " Variable (name=property1, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate)\r\n" + " Variable (name=p_n0_n1, value=http://default/volumeFlow)\r\n" + " StatementPattern\r\n" + " Variable (name=p_n0_n1, value=http://default/volumeFlow)\r\n" + " Variable (name=isPropertyOf1, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate)\r\n" + " Variable (name=r1)\r\n" + " Union\r\n" + " StatementPattern\r\n" + " Variable (name=r1)\r\n" + " Variable (name=subject1, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#subject)\r\n" + " Variable (name=n1)\r\n" + " StatementPattern\r\n" + " Variable (name=n1)\r\n" + " Variable (name=isSubjectOf1, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#subject)\r\n" + " Variable (name=r1)\r\n" + "", element.pathPatternQuery().toString());
}
Aggregations