use of com.inova8.intelligentgraph.path.StatementBinding in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PredicateElement method pathPredicatePatternTupleExpr.
/**
* Path predicate pattern tuple expr.
*
* @param predicatePattern the predicate pattern
* @param intermediateSourceVariable the intermediate source variable
* @param intermediatePredicateVariable the intermediate predicate variable
* @param intermediateTargetVariable the intermediate target variable
* @param customQueryOptions the custom query options
* @return the path tuple expr
*/
private PathTupleExpr pathPredicatePatternTupleExpr(PathTupleExpr predicatePattern, Variable intermediateSourceVariable, Variable intermediatePredicateVariable, Variable intermediateTargetVariable, CustomQueryOptions customQueryOptions) {
TupleExpr intermediatePredicatePattern;
Variable predicateVariable;
if (isNegated) {
predicateVariable = new Variable(getPredicateSPARQLVariable());
// TODO
Variable variable = new Variable("p2", predicate);
if (isInverseOf) {
StatementPattern inverseOfPattern = new StatementPattern(intermediateTargetVariable, predicateVariable, intermediateSourceVariable);
Compare filterExpression = new Compare(predicateVariable, variable, CompareOp.NE);
intermediatePredicatePattern = new Filter(inverseOfPattern, filterExpression);
} else {
intermediatePredicatePattern = new StatementPattern(intermediateSourceVariable, predicateVariable, intermediateTargetVariable);
}
} else {
intermediatePredicateVariable.setValue(predicate);
// Variable(getPredicateSPARQLVariable(), predicate);
predicateVariable = intermediatePredicateVariable;
if (isInverseOf) {
intermediatePredicatePattern = new StatementPattern(intermediateTargetVariable, predicateVariable, intermediateSourceVariable);
} else {
intermediatePredicatePattern = new StatementPattern(intermediateSourceVariable, predicateVariable, intermediateTargetVariable);
}
}
if (objectFilterElement != null) {
intermediatePredicatePattern = (TupleExpr) objectFilterElement.filterExpression(intermediateTargetVariable, intermediatePredicateVariable, null, intermediatePredicatePattern, customQueryOptions).getTupleExpr();
}
// EdgeBinding
statementBinding = new StatementBinding(intermediateSourceVariable, predicateVariable, intermediateTargetVariable, getIsInverseOf());
if (predicatePattern == null) {
predicatePattern = new PathTupleExpr(intermediatePredicatePattern);
// predicatePattern.setStatementBinding(statementBinding);
} else {
predicatePattern.setTupleExpr(new Join(predicatePattern.getTupleExpr(), intermediatePredicatePattern));
}
predicatePattern.setStatementBinding(statementBinding);
predicatePattern.setBoundVariable(predicatePattern.getStatementBinding().getSourceVariable());
predicatePattern.getPath().add(statementBinding);
return predicatePattern;
}
use of com.inova8.intelligentgraph.path.StatementBinding 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.path.StatementBinding in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PredicateElement method visitReifiedPredicatePathBinding.
/**
* Visit reified predicate path binding.
*
* @param pathBinding the path binding
* @param pathIteration the path iteration
* @return the path binding
*/
private PathBinding visitReifiedPredicatePathBinding(PathBinding pathBinding, Integer pathIteration) {
StatementBinding predicateEdge;
Variable sourceVariable = this.getSourceVariable();
Variable targetVariable = this.getTargetVariable();
Variable reificationVariable = this.getReifiedVariable();
Variable intermediateSourceVariable = null;
Variable intermediateTargetVariable = null;
Variable priorIntermediateTargetVariable = null;
Variable intermediateReificationVariable = 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;
intermediateReificationVariable = reificationVariable;
} else {
intermediateReificationVariable = new Variable(reificationVariable.getName() + "_i" + iteration);
}
predicateEdge = new StatementBinding(intermediateSourceVariable, this.reification, intermediateReificationVariable, getPredicateVariable(), getIsDereified() ? this.getReifiedVariable() : intermediateTargetVariable, getIsInverseOf(), getIsDereified());
pathBinding.add(predicateEdge);
}
return pathBinding;
}
use of com.inova8.intelligentgraph.path.StatementBinding in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PredicateElement method pathReifiedPredicatePatternTupleExpr.
/**
* Path reified predicate pattern tuple expr.
*
* @param predicatePattern the predicate pattern
* @param sourceVariable the source variable
* @param intermediatePredicateVariable the intermediate predicate variable
* @param targetVariable the target variable
* @param reificationVariable the reification variable
* @param customQueryOptions the custom query options
* @return the path tuple expr
*/
private PathTupleExpr pathReifiedPredicatePatternTupleExpr(PathTupleExpr predicatePattern, Variable sourceVariable, Variable intermediatePredicateVariable, Variable targetVariable, Variable reificationVariable, CustomQueryOptions customQueryOptions) {
ArrayList<Variable> targetVariables = new ArrayList<Variable>();
if (objectFilterElement != null)
targetVariables = objectFilterElement.bindTargetVariable(targetVariable, customQueryOptions);
if (targetVariables.size() == 0)
targetVariables.add(targetVariable);
TupleExpr reifiedPredicatePattern = null;
intermediatePredicateVariable.setValue(getPredicate());
// getPredicateVariable();
Variable predicateVariable = intermediatePredicateVariable;
IRI subject = getReifications().getReificationSubject(reification);
IRI isSubjectOf = getReifications().getReificationIsSubjectOf(reification);
if (subject == null && isSubjectOf == null)
throw new QueryException("Undefined Reification", "No subject/isSubjectOf for reification " + reification.stringValue());
IRI property = getReifications().getReificationPredicate(reification);
IRI isPropertyOf = getReifications().getReificationIsPredicateOf(reification);
if (property == null && isPropertyOf == null)
throw new QueryException("Undefined Reification", "No property/isPropertyOf for reification " + reification.stringValue());
IRI object = getReifications().getReificationObject(reification);
IRI isObjectOf = getReifications().getReificationIsObjectOf(reification);
if (object == null && isObjectOf == null)
throw new QueryException("Undefined Reification", "No object/isObjectOf for reification " + reification.stringValue());
Variable subjectVariable = new Variable("subject" + getExitIndex(), subject);
Variable isSubjectOfVariable = new Variable("isSubjectOf" + getExitIndex(), isSubjectOf);
Variable propertyVariable = new Variable("property" + getExitIndex(), property);
Variable isPropertyOfVariable = new Variable("isPropertyOf" + getExitIndex(), isPropertyOf);
Variable objectVariable = new Variable("object" + getExitIndex(), object);
Variable isObjectOfVariable = new Variable("isObjectOf" + getExitIndex(), isObjectOf);
// Part1
TupleExpr part1Pattern = null;
if (isInverseOf) {
if (object != null && isObjectOf != null) {
StatementPattern objectPattern = new StatementPattern(reificationVariable, objectVariable, sourceVariable);
StatementPattern isObjectOfPattern = new StatementPattern(sourceVariable, isObjectOfVariable, reificationVariable);
part1Pattern = new Union(objectPattern, isObjectOfPattern);
} else if (object != null) {
StatementPattern objectPattern = new StatementPattern(reificationVariable, objectVariable, sourceVariable);
part1Pattern = objectPattern;
} else if (isObjectOf != null) {
StatementPattern isObjectOfPattern = new StatementPattern(targetVariable, isObjectOfVariable, sourceVariable);
part1Pattern = isObjectOfPattern;
} else {
}
} else {
if (subject != null && isSubjectOf != null) {
StatementPattern subjectPattern = new StatementPattern(reificationVariable, subjectVariable, sourceVariable);
StatementPattern isSubjectOfPattern = new StatementPattern(sourceVariable, isSubjectOfVariable, reificationVariable);
part1Pattern = new Union(subjectPattern, isSubjectOfPattern);
} else if (subject != null) {
StatementPattern subjectPattern = new StatementPattern(reificationVariable, subjectVariable, sourceVariable);
part1Pattern = subjectPattern;
} else if (isSubjectOf != null) {
StatementPattern isSubjectOfPattern = new StatementPattern(sourceVariable, isSubjectOfVariable, reificationVariable);
part1Pattern = isSubjectOfPattern;
} else {
}
}
// Part2
TupleExpr part2Pattern = null;
if (property != null && isPropertyOf != null) {
StatementPattern propertyPattern = new StatementPattern(reificationVariable, propertyVariable, predicateVariable);
StatementPattern isPropertyOfPattern = new StatementPattern(predicateVariable, isPropertyOfVariable, reificationVariable);
part2Pattern = new Union(propertyPattern, isPropertyOfPattern);
} else if (property != null) {
StatementPattern propertyPattern = new StatementPattern(reificationVariable, propertyVariable, predicateVariable);
part2Pattern = propertyPattern;
} else if (isPropertyOf != null) {
StatementPattern isPropertyOfPattern = new StatementPattern(predicateVariable, isPropertyOfVariable, reificationVariable);
part2Pattern = isPropertyOfPattern;
} else {
}
TupleExpr part12Pattern = null;
if (part1Pattern != null && part2Pattern != null)
part12Pattern = new Join(part1Pattern, part2Pattern);
else if (part1Pattern != null)
part12Pattern = part1Pattern;
else if (part2Pattern != null)
part12Pattern = part2Pattern;
// Part3
TupleExpr part3Pattern = null;
for (Variable theTargetVariable : targetVariables) {
Variable aTargetVariable = new Variable(theTargetVariable.getName(), theTargetVariable.getValue());
TupleExpr aTargetPattern = null;
if (isInverseOf) {
if (subject != null && isSubjectOf != null) {
StatementPattern subjectPattern = new StatementPattern(reificationVariable, subjectVariable, aTargetVariable);
StatementPattern isSubjectOfPattern = new StatementPattern(aTargetVariable, isSubjectOfVariable, reificationVariable);
aTargetPattern = new Union(subjectPattern, isSubjectOfPattern);
} else if (subject != null) {
StatementPattern subjectPattern = new StatementPattern(reificationVariable, subjectVariable, aTargetVariable);
aTargetPattern = subjectPattern;
} else if (isSubjectOf != null) {
StatementPattern isSubjectOfPattern = new StatementPattern(aTargetVariable, isSubjectOfVariable, reificationVariable);
aTargetPattern = isSubjectOfPattern;
} else {
}
} else {
if (object != null && isObjectOf != null) {
StatementPattern objectPattern = new StatementPattern(reificationVariable, objectVariable, aTargetVariable);
StatementPattern isObjectOfPattern = new StatementPattern(aTargetVariable, isObjectOfVariable, reificationVariable);
aTargetPattern = new Union(objectPattern, isObjectOfPattern);
} else if (object != null) {
StatementPattern objectPattern = new StatementPattern(reificationVariable, objectVariable, aTargetVariable);
aTargetPattern = objectPattern;
} else if (isObjectOf != null) {
StatementPattern isObjectOfPattern = new StatementPattern(aTargetVariable, isObjectOfVariable, reificationVariable);
aTargetPattern = isObjectOfPattern;
} else {
}
}
if (part3Pattern != null) {
Join newPart3Pattern = new Join(part3Pattern, aTargetPattern);
part3Pattern = newPart3Pattern;
} else {
part3Pattern = aTargetPattern;
}
}
if (part12Pattern != null && part3Pattern != null)
reifiedPredicatePattern = new Join(part12Pattern, part3Pattern);
else if (part12Pattern != null)
reifiedPredicatePattern = part12Pattern;
else if (part3Pattern != null)
reifiedPredicatePattern = part3Pattern;
Variable objectFilterTargetVariable;
if (objectFilterElement != null) {
objectFilterTargetVariable = new Variable(targetVariable.getName(), targetVariable.getValue());
reifiedPredicatePattern = objectFilterElement.filterExpression(objectFilterTargetVariable, intermediatePredicateVariable, null, reifiedPredicatePattern, customQueryOptions).getTupleExpr();
}
if (statementFilterElement != null) {
reifiedPredicatePattern = statementFilterElement.filterExpression(reificationVariable, intermediatePredicateVariable, null, reifiedPredicatePattern, customQueryOptions).getTupleExpr();
}
StatementBinding statementBinding = new StatementBinding(sourceVariable, getReification(), reificationVariable, predicateVariable, getIsDereified() ? reificationVariable : targetVariable, getIsInverseOf(), getIsDereified());
if (predicatePattern == null) {
predicatePattern = new PathTupleExpr(reifiedPredicatePattern);
} else {
predicatePattern.setTupleExpr(new Join(predicatePattern.getTupleExpr(), reifiedPredicatePattern));
}
predicatePattern.setStatementBinding(statementBinding);
predicatePattern.setBoundVariable(predicatePattern.getStatementBinding().getSourceVariable());
predicatePattern.getPath().add(statementBinding);
return predicatePattern;
}
Aggregations