use of com.inova8.intelligentgraph.path.PathTupleExpr in project com.inova8.intelligentgraph by peterjohnlawrence.
the class MultiPathPatternQueryExpressionTests method test_3.
/**
* Test 3.
*/
@Test
@Order(3)
void test_3() {
try {
PathElement element = PathParser.parsePathPattern(repositoryContext, ":Attribute@:density{1, 42}");
PathTupleExpr pathTupleExpr = element.pathPatternQuery(0, null);
// Query.assertEqualsWOSpaces
assertEquals("Join\r\n" + " Join\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=n0)\r\n" + " StatementPattern\r\n" + " Variable (name=n0)\r\n" + " Variable (name=isSubjectOf1, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#subject)\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/density)\r\n" + " StatementPattern\r\n" + " Variable (name=p_n0_n1, value=http://default/density)\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=object1, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#object)\r\n" + " Variable (name=n1)\r\n" + " StatementPattern\r\n" + " Variable (name=n1)\r\n" + " Variable (name=isObjectOf1, value=http://www.w3.org/1999/02/22-rdf-syntax-ns#object)\r\n" + " Variable (name=r1)\r\n" + "", pathTupleExpr.toString());
assertEquals("[n0,r1:<http://default/Attribute>@http://default/density,n1,DIRECT,false]\r\n" + "", pathTupleExpr.pathToString());
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.path.PathTupleExpr in project com.inova8.intelligentgraph by peterjohnlawrence.
the class MultiPathPatternQueryExpressionTests method test_10.
/**
* Test 10.
*/
@Test
@Order(10)
void test_10() {
try {
PathElement element = PathParser.parsePathPattern(repositoryContext, "(*){1, 2}/:massThroughput");
PathTupleExpr pathTupleExpr = element.pathPatternQuery(1, null);
// Query.assertEqualsWOSpaces
assertEquals("Join\r\n" + " Join\r\n" + " StatementPattern\r\n" + " Variable (name=n0)\r\n" + " Variable (name=p_n0_n1)\r\n" + " Variable (name=n1_i1)\r\n" + " StatementPattern\r\n" + " Variable (name=n1_i1)\r\n" + " Variable (name=p_n0_n1)\r\n" + " Variable (name=n1)\r\n" + " StatementPattern\r\n" + " Variable (name=n1)\r\n" + " Variable (name=p_n1_n2, value=http://default/massThroughput)\r\n" + " Variable (name=n2)\r\n" + "", pathTupleExpr.toString());
assertEquals("[n0,p_n0_n1,n1_i1,DIRECT]\r\n" + "[n1_i1,p_n0_n1,n1,DIRECT]\r\n" + "[n1,http://default/massThroughput,n2,DIRECT]\r\n" + "", pathTupleExpr.pathToString());
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.path.PathTupleExpr in project com.inova8.intelligentgraph by peterjohnlawrence.
the class BoundPathElement 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) {
// Extend(rightPatern(?s,?p,?o),
Variable bindSourceVariable = new Variable("bind");
// new Variable("b0_b1");
Variable bindPredicateVariable = null;
Variable bindTargetVariable = new Variable("b");
PathTupleExpr bindPattern = ((FactFilterElement) getLeftPathElement()).filterExpression(bindSourceVariable, bindPredicateVariable, bindTargetVariable, null, customQueryOptions);
// PathTupleExpr bindPattern = getLeftPathElement().pathPatternQuery(bindSourceVariable,bindPredicateVariable,bindTargetVariable,customQueryOptions);
PathTupleExpr rightPattern;
if (bindPattern.getTupleExpr() == null) {
bindSourceVariable.setName("n0");
rightPattern = getRightPathElement().pathPatternQuery(bindSourceVariable, predicateVariable, targetVariable, customQueryOptions);
rightPattern.setBoundVariable(bindSourceVariable);
return rightPattern;
} else {
rightPattern = getRightPathElement().pathPatternQuery(sourceVariable, predicateVariable, targetVariable, customQueryOptions);
Extension leftPattern = new Extension(bindPattern.getTupleExpr(), new ExtensionElem(bindSourceVariable, "n0"));
Join boundPattern = new Join(leftPattern, rightPattern.getTupleExpr());
PathTupleExpr boundPatternTupleExpr = new PathTupleExpr(boundPattern);
boundPatternTupleExpr.setStatementBinding(rightPattern.getStatementBinding());
boundPatternTupleExpr.setBoundVariable(bindSourceVariable);
return boundPatternTupleExpr;
}
}
use of com.inova8.intelligentgraph.path.PathTupleExpr in project com.inova8.intelligentgraph by peterjohnlawrence.
the class FactFilterElement method filterExpression.
/**
* Filter expression.
*
* @param sourceVariable the source variable
* @param predicateVariable the predicate variable
* @param targetVariable the target variable
* @param filterExpression the filter expression
* @param customQueryOptions the custom query options
* @return the path tuple expr
*/
public PathTupleExpr filterExpression(Variable sourceVariable, Variable predicateVariable, Variable targetVariable, TupleExpr filterExpression, CustomQueryOptions customQueryOptions) {
// QueryModelNode filterExpression = null;
if (propertyListNotEmpty != null) {
int verbObjectListCount = 0;
for (VerbObjectList verbObjectList : propertyListNotEmpty) {
verbObjectListCount++;
Variable verbObjectListTargetVariable = null;
if (targetVariable != null)
verbObjectListTargetVariable = new Variable(targetVariable.getName() + verbObjectListCount);
QueryModelNode verbObjectListExpression = verbObjectList.filterExpression(sourceVariable, predicateVariable, verbObjectListTargetVariable, customQueryOptions);
if (filterExpression == null)
filterExpression = (TupleExpr) verbObjectListExpression;
else if (verbObjectListExpression == null) {
// Ignore it for some unknown reason
} else {
if (filterExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.Compare"))
if (verbObjectListExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.Compare"))
filterExpression = (TupleExpr) new And((ValueExpr) filterExpression, (ValueExpr) verbObjectListExpression);
else
filterExpression = new Filter((TupleExpr) verbObjectListExpression, (ValueExpr) filterExpression);
else if (verbObjectListExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.StatementPattern"))
filterExpression = new Join((TupleExpr) filterExpression, (TupleExpr) verbObjectListExpression);
else if (verbObjectListExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.Join"))
filterExpression = new Join((TupleExpr) filterExpression, (TupleExpr) verbObjectListExpression);
else if (verbObjectListExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.Compare"))
filterExpression = new Filter(filterExpression, (ValueExpr) verbObjectListExpression);
else if (verbObjectListExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.Filter")) {
TupleExpr arg = ((Filter) verbObjectListExpression).getArg();
filterExpression = new Filter(new Join(filterExpression, arg), ((Filter) verbObjectListExpression).getCondition());
} else
filterExpression = new Filter((TupleExpr) filterExpression, (ValueExpr) verbObjectListExpression);
}
}
}
return new PathTupleExpr(filterExpression);
}
use of com.inova8.intelligentgraph.path.PathTupleExpr in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentStatementResults method hasNext.
/**
* Checks for next.
*
* @return true, if successful
* @throws QueryEvaluationException the query evaluation exception
*/
@Override
public boolean hasNext() throws QueryEvaluationException {
if (resultsIterator != null && resultsIterator.hasNext()) {
return true;
} else {
while (pathIteration < this.sortedIterations.size()) {
// source.getIntelligentGraphConnection().getPrefixes());
CustomQueryOptions customQueryOptions = CustomQueryOption.getCustomQueryOptions(contexts, source.getRepositoryContext().getPrefixes());
pathTupleExpr = pathElement.pathPatternQuery(pathIteration, customQueryOptions);
if (this.thing == null && pathTupleExpr.getBoundVariable() == null) {
throw new QueryEvaluationException("Facts query unbound");
} else {
this.boundVariableName = pathTupleExpr.getBoundVariable().getName();
}
pathIteration++;
this.resultsIterator = intelligentGraphConnection.getResultsIterator(source, thing, pathElement, pathTupleExpr, contexts);
boolean hasNext = resultsIterator.hasNext();
if (hasNext) {
predicateVariable = pathTupleExpr.getStatementBinding().getPredicateVariable();
subj = pathTupleExpr.getStatementBinding().getSourceVariable().getName();
pathTupleExpr.getStatementBinding().getPredicateVariable().getName();
obj = pathTupleExpr.getStatementBinding().getTargetVariable().getName();
return true;
}
}
return false;
}
}
Aggregations