Search in sources :

Example 36 with CustomQueryOptions

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;
}
Also used : QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) BindingSet(org.eclipse.rdf4j.query.BindingSet) EvaluationStrategy(org.eclipse.rdf4j.query.algebra.evaluation.EvaluationStrategy) StrictEvaluationStrategy(org.eclipse.rdf4j.query.algebra.evaluation.impl.StrictEvaluationStrategy) StrictEvaluationStrategy(org.eclipse.rdf4j.query.algebra.evaluation.impl.StrictEvaluationStrategy) CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) SimpleDataset(org.eclipse.rdf4j.query.impl.SimpleDataset) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) PathTupleExpr(com.inova8.intelligentgraph.path.PathTupleExpr) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet)

Example 37 with CustomQueryOptions

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;
}
Also used : CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions)

Example 38 with 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);
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) StatementBinding(com.inova8.intelligentgraph.path.StatementBinding) BindingSet(org.eclipse.rdf4j.query.BindingSet) IRI(org.eclipse.rdf4j.model.IRI) Value(org.eclipse.rdf4j.model.Value) URISyntaxException(java.net.URISyntaxException)

Example 39 with CustomQueryOptions

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;
    }
}
Also used : CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException)

Example 40 with CustomQueryOptions

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;
}
Also used : HandledException(com.inova8.intelligentgraph.exceptions.HandledException) GetSampleOutputV1(com.seeq.model.GetSampleOutputV1)

Aggregations

CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)27 Thing (com.inova8.intelligentgraph.model.Thing)16 IRI (org.eclipse.rdf4j.model.IRI)14 Resource (com.inova8.intelligentgraph.model.Resource)12 Value (org.eclipse.rdf4j.model.Value)11 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)10 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)9 PathTupleExpr (com.inova8.intelligentgraph.path.PathTupleExpr)9 Order (org.junit.jupiter.api.Order)9 Test (org.junit.jupiter.api.Test)9 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)9 SimpleLiteral (org.eclipse.rdf4j.model.impl.SimpleLiteral)8 EvaluationContext (com.inova8.intelligentgraph.evaluator.EvaluationContext)7 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)7 SimpleDataset (org.eclipse.rdf4j.query.impl.SimpleDataset)7 ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)6 Statement (org.eclipse.rdf4j.model.Statement)6 Join (org.eclipse.rdf4j.query.algebra.Join)6 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)6 ValueExprEvaluationException (org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException)5