Search in sources :

Example 1 with FactFilterElement

use of com.inova8.pathql.element.FactFilterElement 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;
}
Also used : PredicateElement(com.inova8.pathql.element.PredicateElement)

Example 2 with FactFilterElement

use of com.inova8.pathql.element.FactFilterElement 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;
}
Also used : PredicateElement(com.inova8.pathql.element.PredicateElement) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement)

Example 3 with FactFilterElement

use of com.inova8.pathql.element.FactFilterElement 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 4 with FactFilterElement

use of com.inova8.pathql.element.FactFilterElement in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternVisitor method visitBoundPattern.

/**
 * Visit bound pattern.
 *
 * @param ctx the ctx
 * @return the path element
 */
@Override
public PathElement visitBoundPattern(PathPatternParser.BoundPatternContext ctx) {
    // boundPattern :  binding ('/'|'>') pathPatterns EOF
    PathElement pathElement = new BoundPathElement(this.repositoryContext);
    pathElement.setLeftPathElement((FactFilterElement) visit(ctx.binding()));
    if (ctx.pathPatterns() != null)
        pathElement.setRightPathElement(visit(ctx.pathPatterns()));
    else
        throw new ScriptFailedException(String.format("Bolund pattern %s must be followed by pathPatterns", ctx.getText()));
    return pathElement;
}
Also used : 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) ScriptFailedException(com.inova8.intelligentgraph.exceptions.ScriptFailedException) BoundPathElement(com.inova8.pathql.element.BoundPathElement)

Example 5 with FactFilterElement

use of com.inova8.pathql.element.FactFilterElement 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;
    }
}
Also used : Extension(org.eclipse.rdf4j.query.algebra.Extension) PathTupleExpr(com.inova8.intelligentgraph.path.PathTupleExpr) ExtensionElem(org.eclipse.rdf4j.query.algebra.ExtensionElem) Join(org.eclipse.rdf4j.query.algebra.Join)

Aggregations

PredicateElement (com.inova8.pathql.element.PredicateElement)3 AlternativePathElement (com.inova8.pathql.element.AlternativePathElement)2 BoundPathElement (com.inova8.pathql.element.BoundPathElement)2 IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)2 PathElement (com.inova8.pathql.element.PathElement)2 QueryOptionsPathElement (com.inova8.pathql.element.QueryOptionsPathElement)2 SequencePathElement (com.inova8.pathql.element.SequencePathElement)2 ScriptFailedException (com.inova8.intelligentgraph.exceptions.ScriptFailedException)1 PathTupleExpr (com.inova8.intelligentgraph.path.PathTupleExpr)1 FactFilterElement (com.inova8.pathql.element.FactFilterElement)1 FilterOperatorValueElement (com.inova8.pathql.element.FilterOperatorValueElement)1 LiteralValueElement (com.inova8.pathql.element.LiteralValueElement)1 ObjectListValueElement (com.inova8.pathql.element.ObjectListValueElement)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 Extension (org.eclipse.rdf4j.query.algebra.Extension)1 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)1 Join (org.eclipse.rdf4j.query.algebra.Join)1