use of com.inova8.pathql.element.VerbObjectList in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitPropertyListNotEmpty.
/**
* Visit property list not empty.
*
* @param ctx the ctx
* @return the fact filter element
*/
@Override
public FactFilterElement visitPropertyListNotEmpty(PropertyListNotEmptyContext ctx) {
// propertyListNotEmpty : verbObjectList ( ';' ( verbObjectList )? )* ;
FactFilterElement propertyListNotEmptyElement = new FactFilterElement(this.repositoryContext);
ArrayList<VerbObjectList> propertyListNotEmpty = new ArrayList<VerbObjectList>();
for (VerbObjectListContext verbObjectListContext : ctx.verbObjectList()) {
PathElement verb = visit(verbObjectListContext.verb());
ObjectListValueElement objectList = (ObjectListValueElement) visit(verbObjectListContext.objectList());
VerbObjectList verbObjectList = new VerbObjectList(this.repositoryContext);
if (verb instanceof ValueElement) {
verbObjectList.setFilterOperator(((FilterOperatorValueElement) verb).getFilterOperator());
} else if (verb instanceof PredicateElement) {
verbObjectList.setPredicate(((PredicateElement) verb));
}
verbObjectList.setObjectList(objectList.getObjectList());
propertyListNotEmpty.add(verbObjectList);
}
propertyListNotEmptyElement.setPropertyListNotEmpty(propertyListNotEmpty);
return propertyListNotEmptyElement;
}
use of com.inova8.pathql.element.VerbObjectList 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);
}
Aggregations