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;
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations