use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method getResultsIterator.
/**
* Gets the results iterator.
*
* @param source the source
* @param thing the thing
* @param pathElement the path element
* @param pathIteration the path iteration
* @param contexts the contexts
* @return the results iterator
* @throws IllegalArgumentException the illegal argument exception
* @throws QueryEvaluationException the query evaluation exception
*/
CloseableIteration<BindingSet, QueryEvaluationException> getResultsIterator(IntelligentGraphRepository source, Thing thing, PathElement pathElement, Integer pathIteration, Resource... contexts) throws IllegalArgumentException, QueryEvaluationException {
CustomQueryOptions customQueryOptions = CustomQueryOption.getCustomQueryOptions(contexts, source.getRepositoryContext().getPrefixes());
TupleExpr tupleExpr = pathElement.pathPatternQuery(pathIteration, customQueryOptions).getTupleExpr();
SimpleDataset dataset = prepareDataset(pathElement, source, contexts);
BindingSet bindings = new QueryBindingSet();
EvaluationStrategy evaluationStrategy = new StrictEvaluationStrategy(source.getTripleSource(), dataset, null);
CloseableIteration<BindingSet, QueryEvaluationException> resultsIterator = evaluationStrategy.evaluate(tupleExpr, bindings);
return resultsIterator;
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method prepareCustomQueryOptions.
/**
* Prepare custom query options.
*
* @param pathElement the path element
* @param source the source
* @param contexts the contexts
* @return the custom query options
*/
private CustomQueryOptions prepareCustomQueryOptions(PathElement pathElement, IntelligentGraphRepository source, Resource... contexts) {
// TODOgetPrefixes());
CustomQueryOptions customQueryOptions = CustomQueryOption.getCustomQueryOptions(contexts, source.getRepositoryContext().getPrefixes());
CustomQueryOptions pathQLCustomQueryOptions = pathElement.getCustomQueryOptions();
if (pathQLCustomQueryOptions != null) {
pathQLCustomQueryOptions.addInherited(customQueryOptions);
customQueryOptions = pathQLCustomQueryOptions;
}
return customQueryOptions;
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentStatementResults method next.
/**
* Next.
*
* @return the intelligent statement
* @throws QueryEvaluationException the query evaluation exception
*/
@SuppressWarnings("deprecation")
@Override
public IntelligentStatement next() throws QueryEvaluationException {
BindingSet nextBindingset = getResultsIterator().next();
Binding subjBinding = nextBindingset.getBinding(subj);
Binding predBinding = StatementBinding.getAlternatePredicateBinding(nextBindingset, predicateVariable);
Binding objBinding = nextBindingset.getBinding(obj);
if (subjBinding != null && predBinding != null && objBinding != null) {
IRI parameterizedPredicate;
try {
parameterizedPredicate = this.pathElement.getParameterizedPredicate((IRI) predBinding.getValue());
} catch (URISyntaxException e) {
parameterizedPredicate = (IRI) predBinding.getValue();
}
Value subjectValue;
if (subjBinding != null)
subjectValue = subjBinding.getValue();
else
subjectValue = nextBindingset.getBinding(this.boundVariableName).getValue();
if (trace && this.evaluationContext != null) {
thing.getEvaluationContext().getTracer().traceFactReturnValue(thing, predBinding.getValue().stringValue(), objBinding.getValue());
return new IntelligentStatement((ContextStatement) simpleValueFactory.createStatement((Resource) subjectValue, parameterizedPredicate, literal(thing.getEvaluationContext().getTrace()), null), null, this.evaluationContext, customQueryOptions);
} else {
return new IntelligentStatement((ContextStatement) simpleValueFactory.createStatement((Resource) subjectValue, parameterizedPredicate, objBinding.getValue(), null), source, this.evaluationContext, customQueryOptions);
}
} else
return new IntelligentStatement(null, null, null);
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentStatementResults method hasNext.
/**
* Checks for next.
*
* @return true, if successful
* @throws QueryEvaluationException the query evaluation exception
*/
@Override
public boolean hasNext() throws QueryEvaluationException {
if (resultsIterator != null && resultsIterator.hasNext()) {
return true;
} else {
while (pathIteration < this.sortedIterations.size()) {
// source.getIntelligentGraphConnection().getPrefixes());
CustomQueryOptions customQueryOptions = CustomQueryOption.getCustomQueryOptions(contexts, source.getRepositoryContext().getPrefixes());
pathTupleExpr = pathElement.pathPatternQuery(pathIteration, customQueryOptions);
if (this.thing == null && pathTupleExpr.getBoundVariable() == null) {
throw new QueryEvaluationException("Facts query unbound");
} else {
this.boundVariableName = pathTupleExpr.getBoundVariable().getName();
}
pathIteration++;
this.resultsIterator = intelligentGraphConnection.getResultsIterator(source, thing, pathElement, pathTupleExpr, contexts);
boolean hasNext = resultsIterator.hasNext();
if (hasNext) {
predicateVariable = pathTupleExpr.getStatementBinding().getPredicateVariable();
subj = pathTupleExpr.getStatementBinding().getSourceVariable().getName();
pathTupleExpr.getStatementBinding().getPredicateVariable().getName();
obj = pathTupleExpr.getStatementBinding().getTargetVariable().getName();
return true;
}
}
return false;
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class SEEQSource method getSignal.
/**
* Gets the signal.
*
* @param signal the signal
* @param customQueryOptions the custom query options
* @return the signal
* @throws HandledException the handled exception
*/
public Object getSignal(String signal, CustomQueryOptions customQueryOptions) throws HandledException {
String start = getStart(customQueryOptions);
String end = getEnd(customQueryOptions);
String aggregate = getAggregate(customQueryOptions);
String formula;
switch(aggregate) {
case INSTANT:
GetSampleOutputV1 signalValue = signalsApi.getSample(signal, end, null, null, null);
return signalValue.getSample().getValue();
case AVERAGE:
formula = "$tx01.average(capsule ('" + start + "','" + end + "')) ";
return executeFunction(signal, formula);
case MAXIMUM:
formula = "$tx01.maxValue(capsule ('" + start + "','" + end + "')) ";
return executeFunction(signal, formula);
case MINIMUM:
formula = "$tx01.minValue(capsule ('" + start + "','" + end + "')) ";
return executeFunction(signal, formula);
case TOTALIZED:
formula = "$tx01.totalized(capsule ('" + start + "','" + end + "')) ";
return executeFunction(signal, formula);
default:
logger.error("SEEQ Invalid aggregate: {}", aggregate);
throw new HandledException(INVALIDAGGREGATE_EXCEPTION, aggregate);
}
// return (olgap.Value) null;
}
Aggregations