use of com.inova8.intelligentgraph.context.CustomQueryOptions 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.context.CustomQueryOptions 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;
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions 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);
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class CustomQueryOption method getCustomQueryOptions.
/**
* Gets the custom query options.
*
* @param contexts the contexts
* @param prefixes the prefixes
* @return the custom query options
*/
public static CustomQueryOptions getCustomQueryOptions(org.eclipse.rdf4j.model.Resource[] contexts, Prefixes prefixes) {
CustomQueryOptions customQueryOptions = new CustomQueryOptions();
if (contexts != null) {
for (org.eclipse.rdf4j.model.Resource context : contexts) {
if (context.stringValue().startsWith(IntelligentGraphConstants.URN_CUSTOM_QUERY_OPTIONS)) {
String queryString = null;
try {
queryString = URLDecoder.decode(context.stringValue(), StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
customQueryOptions = CustomQueryOption.splitQuery(queryString, prefixes);
return customQueryOptions;
}
}
return customQueryOptions;
} else
return null;
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method prepareDataset.
/**
* Prepare dataset.
*
* @param pathElement the path element
* @param source the source
* @param contexts the contexts
* @return the simple dataset
* @throws IllegalArgumentException the illegal argument exception
*/
private SimpleDataset prepareDataset(PathElement pathElement, IntelligentGraphRepository source, Resource... contexts) throws IllegalArgumentException {
CustomQueryOptions customQueryOptions = prepareCustomQueryOptions(pathElement, source, contexts);
SimpleDataset dataset = getDataset(contexts);
if (customQueryOptions != null && !customQueryOptions.isEmpty()) {
if (dataset == null)
dataset = new SimpleDataset();
dataset.addDefaultGraph(iri(IntelligentGraphConstants.URN_CUSTOM_QUERY_OPTIONS + "?" + customQueryOptions.toURIEncodedString()));
}
return dataset;
}
Aggregations