Search in sources :

Example 41 with CustomQueryOptions

use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.

the class SEEQSource method getEnd.

/**
 * Gets the end.
 *
 * @param customQueryOptions the custom query options
 * @return the end
 */
private String getEnd(CustomQueryOptions customQueryOptions) {
    if (customQueryOptions != null && customQueryOptions.containsKey(END)) {
        Resource endDateTime = customQueryOptions.get(END);
        return endDateTime.getValue().stringValue();
    } else {
        if (customQueryOptions != null && customQueryOptions.containsKey(START)) {
            Resource startDateTime = customQueryOptions.get(START);
            String start = startDateTime.getValue().stringValue();
            return start;
        } else {
            // LocalDateTime.now().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
            return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now().truncatedTo(ChronoUnit.HOURS));
        }
    }
}
Also used : Resource(com.inova8.intelligentgraph.model.Resource)

Example 42 with CustomQueryOptions

use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.

the class SEEQSource method getSEEQSignal.

/**
 * Gets the SEEQ signal.
 *
 * @param thing the thing
 * @param signal the signal
 * @param customQueryOptions the custom query options
 * @return the SEEQ signal
 * @throws ScriptFailedException the script failed exception
 */
public static Resource getSEEQSignal(Thing thing, String signal, CustomQueryOptions customQueryOptions) throws ScriptFailedException {
    signal = Utilities.trimIRIString(signal);
    String[] elements = signal.split("/");
    Object result;
    SEEQSource seeqSource = null;
    try {
        if (elements.length < 6) {
            thing.getEvaluationContext().getTracer().decrementLevel();
            String error = String.format("Unsupported signal source: %s", signal);
            logger.error(error);
            thing.getEvaluationContext().getTracer().traceSignalError(error);
            throw new ScriptFailedException(error);
        } else {
            thing.getEvaluationContext().getTracer().traceSEEQ(elements[5], customQueryOptions);
            seeqSource = thing.getSource().seeqSourceFactory(elements[2]);
            result = seeqSource.getSignal(elements[5], customQueryOptions);
            thing.getEvaluationContext().getTracer().decrementLevel();
            return Resource.create(thing.getSource(), literal((Double) result), thing.getEvaluationContext());
        }
    } catch (ScriptException e) {
        throw new ScriptFailedException(e);
    } catch (HandledException e) {
        throw new ScriptFailedException(e);
    }
}
Also used : HandledException(com.inova8.intelligentgraph.exceptions.HandledException) ScriptException(javax.script.ScriptException) ScriptFailedException(com.inova8.intelligentgraph.exceptions.ScriptFailedException)

Example 43 with CustomQueryOptions

use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentStatementPaths 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()) {
            CustomQueryOptions customQueryOptions = CustomQueryOption.getCustomQueryOptions(contexts, source.getRepositoryContext().getPrefixes());
            pathTupleExpr = pathElement.pathPatternQuery(pathIteration, customQueryOptions);
            if (this.thing == null && pathTupleExpr.getBoundVariable() == null) {
                throw new QueryEvaluationException("Paths query unbound");
            } else {
                this.boundVariableName = pathTupleExpr.getBoundVariable().getName();
            }
            pathIteration++;
            this.resultsIterator = intelligentGraphConnection.getResultsIterator(source, thing, pathElement, pathTupleExpr, contexts);
            boolean hasNext = resultsIterator.hasNext();
            if (hasNext)
                return true;
        }
        return false;
    }
}
Also used : CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException)

Example 44 with CustomQueryOptions

use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphRepository method getFacts.

public ResourceResults getFacts(String boundPredicatePattern, CustomQueryOptions customQueryOptions) {
    logger.debug("getFacts{}\n", boundPredicatePattern);
    // this.getEvaluationContext().getTracer().traceFacts(this, queryPattern);
    SimpleDataset dataset = getDataset(customQueryOptions);
    // dataset.addDefaultGraph(this.graphName);
    org.eclipse.rdf4j.model.Resource[] contextArray = dataset.getDefaultGraphs().toArray(new org.eclipse.rdf4j.model.Resource[0]);
    ResourceStatementResults results = null;
    IRI predicate = preparePredicate(PATHQL.getFacts, boundPredicatePattern);
    if (this.getRepository() == null) {
        CloseableIteration<? extends Statement, QueryEvaluationException> localStatementIterator = this.getTripleSource().getStatements(null, predicate, null);
        results = new ResourceStatementResults(localStatementIterator, this, null, customQueryOptions);
    } else {
        CloseableIteration<Statement, RepositoryException> statementIterator = this.getRepository().getConnection().getStatements(null, predicate, null, contextArray);
        results = new ResourceStatementResults(statementIterator, this, null, customQueryOptions);
    }
    return results;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Statement(org.eclipse.rdf4j.model.Statement) Resource(org.eclipse.rdf4j.model.Resource) ResourceStatementResults(com.inova8.intelligentgraph.results.ResourceStatementResults) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) SimpleDataset(org.eclipse.rdf4j.query.impl.SimpleDataset) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException)

Example 45 with CustomQueryOptions

use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphRepository method getCustomQueryOptions.

/**
 * Gets the custom query options.
 *
 * @param customQueryOptionsArray the custom query options array
 * @return the custom query options
 */
public CustomQueryOptions getCustomQueryOptions(Value[] customQueryOptionsArray) {
    CustomQueryOptions customQueryOptions = CustomQueryOptions.create(this, customQueryOptionsArray);
    if (customQueryOptions != null) {
        if (customQueryOptions.contains("service")) {
            com.inova8.intelligentgraph.model.Resource service = customQueryOptions.get("service");
            String serviceURL = service.toString();
            String serviceIRI = null;
            if (serviceURL.indexOf('?') > 0) {
                serviceIRI = serviceURL.substring(0, serviceURL.indexOf('?'));
            }
            if (serviceIRI != null)
                setCacheService(serviceIRI);
        }
    }
    return customQueryOptions;
}
Also used : CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions)

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