Search in sources :

Example 1 with VerbObjectList

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;
}
Also used : ObjectListValueElement(com.inova8.pathql.element.ObjectListValueElement) ValueElement(com.inova8.pathql.element.ValueElement) ObjectListValueElement(com.inova8.pathql.element.ObjectListValueElement) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement) FilterOperatorValueElement(com.inova8.pathql.element.FilterOperatorValueElement) LiteralValueElement(com.inova8.pathql.element.LiteralValueElement) SequencePathElement(com.inova8.pathql.element.SequencePathElement) BoundPathElement(com.inova8.pathql.element.BoundPathElement) PathElement(com.inova8.pathql.element.PathElement) AlternativePathElement(com.inova8.pathql.element.AlternativePathElement) QueryOptionsPathElement(com.inova8.pathql.element.QueryOptionsPathElement) VerbObjectListContext(com.inova8.pathql.pathPattern.PathPatternParser.VerbObjectListContext) PredicateElement(com.inova8.pathql.element.PredicateElement) ArrayList(java.util.ArrayList) VerbObjectList(com.inova8.pathql.element.VerbObjectList) FactFilterElement(com.inova8.pathql.element.FactFilterElement)

Example 2 with VerbObjectList

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);
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) PathTupleExpr(com.inova8.intelligentgraph.path.PathTupleExpr) Filter(org.eclipse.rdf4j.query.algebra.Filter) And(org.eclipse.rdf4j.query.algebra.And) QueryModelNode(org.eclipse.rdf4j.query.algebra.QueryModelNode) Join(org.eclipse.rdf4j.query.algebra.Join) PathTupleExpr(com.inova8.intelligentgraph.path.PathTupleExpr) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Aggregations

PathTupleExpr (com.inova8.intelligentgraph.path.PathTupleExpr)1 AlternativePathElement (com.inova8.pathql.element.AlternativePathElement)1 BoundPathElement (com.inova8.pathql.element.BoundPathElement)1 FactFilterElement (com.inova8.pathql.element.FactFilterElement)1 FilterOperatorValueElement (com.inova8.pathql.element.FilterOperatorValueElement)1 IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)1 LiteralValueElement (com.inova8.pathql.element.LiteralValueElement)1 ObjectListValueElement (com.inova8.pathql.element.ObjectListValueElement)1 PathElement (com.inova8.pathql.element.PathElement)1 PredicateElement (com.inova8.pathql.element.PredicateElement)1 QueryOptionsPathElement (com.inova8.pathql.element.QueryOptionsPathElement)1 SequencePathElement (com.inova8.pathql.element.SequencePathElement)1 ValueElement (com.inova8.pathql.element.ValueElement)1 VerbObjectList (com.inova8.pathql.element.VerbObjectList)1 VerbObjectListContext (com.inova8.pathql.pathPattern.PathPatternParser.VerbObjectListContext)1 ArrayList (java.util.ArrayList)1 And (org.eclipse.rdf4j.query.algebra.And)1 Filter (org.eclipse.rdf4j.query.algebra.Filter)1 Join (org.eclipse.rdf4j.query.algebra.Join)1 QueryModelNode (org.eclipse.rdf4j.query.algebra.QueryModelNode)1