use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PredicateElement method pathPredicatePatternQuery.
/**
* Path predicate 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
*/
private PathTupleExpr pathPredicatePatternQuery(Variable sourceVariable, Variable predicateVariable, Variable targetVariable, Integer pathIteration, CustomQueryOptions customQueryOptions) {
PathTupleExpr predicatePattern = null;
if (getCardinality(pathIteration) > 0) {
Variable intermediateSourceVariable = null;
Variable intermediatePredicateVariable = null;
Variable intermediateTargetVariable = null;
Variable priorIntermediateTargetVariable = null;
for (int iteration = 1; iteration <= getCardinality(pathIteration); iteration++) {
if (iteration == 1) {
intermediateSourceVariable = sourceVariable;
}
if (iteration < getCardinality(pathIteration)) {
if (iteration > 1)
intermediateSourceVariable = priorIntermediateTargetVariable;
intermediateTargetVariable = new Variable(targetVariable.getName() + "_i" + iteration);
priorIntermediateTargetVariable = intermediateTargetVariable;
}
if (iteration == getCardinality(pathIteration)) {
if (iteration > 1)
intermediateSourceVariable = priorIntermediateTargetVariable;
intermediateTargetVariable = targetVariable;
}
intermediatePredicateVariable = deducePredicateVariable(sourceVariable, predicateVariable, targetVariable);
predicatePattern = pathPredicatePatternTupleExpr(predicatePattern, intermediateSourceVariable, intermediatePredicateVariable, intermediateTargetVariable, customQueryOptions);
}
return predicatePattern;
} else {
return null;
}
}
use of com.inova8.intelligentgraph.model.Predicate 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.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternQueryExpressionTests method test_13.
/**
* Test 13.
*/
// }
@Test
@Order(13)
void test_13() {
try {
PathElement element = PathParser.parsePathPattern(repositoryContext, ":Location@:appearsOn[eq id:Calc2Graph1, id:Calc2Graph2]#");
// Query.assertEqualsWOSpaces
assertEquals("Join\r\n" + " Join\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=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/appearsOn)\r\n" + " Join\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, value=http://id/Calc2Graph1)\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, value=http://id/Calc2Graph2)\r\n" + "", element.pathPatternQuery().toString());
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitPredicateRef.
/**
* Visit predicate ref.
*
* @param ctx the ctx
* @return the iri ref value element
*/
@Override
public IriRefValueElement visitPredicateRef(PredicateRefContext ctx) {
// predicateRef : IRI_REF | rdfType | qname | pname_ns ;
IriRefValueElement predicateRefElement;
if (ctx.qname() != null) {
predicateRefElement = (IriRefValueElement) visit(ctx.qname());
} else if (ctx.pname_ns() != null) {
predicateRefElement = (IriRefValueElement) visit(ctx.pname_ns());
} else if (ctx.rdfType() != null) {
predicateRefElement = new IriRefValueElement(this.repositoryContext);
predicateRefElement.setIri(iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
} else {
predicateRefElement = new IriRefValueElement(this.repositoryContext);
String iri = ctx.IRI_REF().getText();
iri = iri.substring(1, iri.length() - 1);
predicateRefElement.setIri(iri(iri));
}
return predicateRefElement;
}
use of com.inova8.intelligentgraph.model.Predicate 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