Search in sources :

Example 46 with CustomQueryOptions

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

the class IntelligentGraphRepository method getFact.

public com.inova8.intelligentgraph.model.Resource getFact(String boundPredicatePattern, CustomQueryOptions customQueryOptions) {
    logger.debug("getFact{}\n", boundPredicatePattern);
    ResourceResults factValues = getFacts(boundPredicatePattern, customQueryOptions);
    if (factValues == null) {
        // return new NullResource();
        throw new NullValueReturnedException(String.format("No values found for pattern %s with customQueryOptions %s", boundPredicatePattern, customQueryOptions));
    } else if (factValues.hasNext()) {
        return factValues.next();
    } else {
        factValues.close();
        // return new NullResource();
        throw new NullValueReturnedException(String.format("No values found for pattern %s with customQueryOptions %s", boundPredicatePattern, customQueryOptions));
    }
}
Also used : NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) ResourceResults(com.inova8.intelligentgraph.results.ResourceResults)

Example 47 with CustomQueryOptions

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

the class Thing method getFact.

// public  Resource getFact(IRI predicate, SimpleLiteral scriptString, CustomQueryOptions customQueryOptions, org.eclipse.rdf4j.model.Resource ... contexts) throws HandledException {
// Resource fact = processFactObjectValue(predicate,scriptString,  customQueryOptions ,contexts);
// return fact;
/**
 * Gets the fact.
 *
 * @param predicatePattern the predicate pattern
 * @param customQueryOptions the custom query options
 * @param bindValues the bind values
 * @return the fact
 */
// }
public Resource getFact(String predicatePattern, CustomQueryOptions customQueryOptions, Value... bindValues) {
    logger.debug("getFact{}\n", predicatePattern);
    ResourceResults factValues = getFacts(predicatePattern, customQueryOptions, bindValues);
    if (factValues == null) {
        throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s, customQueryOptions %s, and bind variables %s", predicatePattern, this, customQueryOptions, bindValues));
    } else if (factValues.hasNext()) {
        return factValues.next();
    } else {
        factValues.close();
        throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s, customQueryOptions %s, and bind variables %s", predicatePattern, this, customQueryOptions, bindValues));
    }
}
Also used : NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) ResourceResults(com.inova8.intelligentgraph.results.ResourceResults)

Example 48 with CustomQueryOptions

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

the class IntelligentEvaluator method processFactObjectValue.

/**
 * Process fact object value.
 *
 * @param thing the thing
 * @param predicate the predicate
 * @param objectValue the object value
 * @param customQueryOptions the custom query options
 * @param contexts the contexts
 * @return the resource
 * @throws QueryEvaluationException the query evaluation exception
 */
public static Resource processFactObjectValue(Thing thing, IRI predicate, Value objectValue, CustomQueryOptions customQueryOptions, org.eclipse.rdf4j.model.Resource... contexts) throws QueryEvaluationException {
    Resource returnResult = null;
    SimpleLiteral literalValue;
    {
        literalValue = (SimpleLiteral) objectValue;
        if (Evaluator.isScriptEngine(literalValue.getDatatype())) {
            org.eclipse.rdf4j.model.Resource customQueryOptionsContext;
            if (customQueryOptions != null)
                customQueryOptionsContext = customQueryOptions.getContext();
            else
                customQueryOptionsContext = CustomQueryOptions.getEmptyContext();
            FactCache factCache = thing.getSource().getIntelligentGraphConnection().getIntelligentGraphSail().getFactCache();
            if (/*notTracing() && */
            factCache.contains(thing.getIRI(), predicate, customQueryOptionsContext)) {
                Value resultValue = factCache.getFacts(thing.getIRI(), predicate, customQueryOptionsContext);
                logger.debug("Retrieved cache {} of {} = {}", predicate.stringValue(), thing.getSuperValue().stringValue(), resultValue.stringValue());
                thing.getEvaluationContext().getTracer().traceRetrievedCache(thing, predicate, resultValue);
                returnResult = Resource.create(thing.getSource(), resultValue, thing.getEvaluationContext());
            } else {
                Resource result = handleScript(thing, literalValue, predicate, customQueryOptions, contexts);
                if (result != null) {
                    // TODO validate caching
                    factCache.addFact(thing.getIRI(), predicate, result.getSuperValue(), customQueryOptionsContext);
                    thing.getEvaluationContext().getTracer().traceCalculated(thing, predicate, result);
                }
                returnResult = result;
            }
        } else {
            thing.getEvaluationContext().getTracer().traceRetrievedLiteral(thing, predicate, objectValue);
            returnResult = Resource.create(thing.getSource(), objectValue, thing.getEvaluationContext());
        }
    }
    return returnResult;
}
Also used : Resource(com.inova8.intelligentgraph.model.Resource) Value(org.eclipse.rdf4j.model.Value) SimpleLiteral(org.eclipse.rdf4j.model.impl.SimpleLiteral)

Example 49 with CustomQueryOptions

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

the class Thing method getPaths.

/**
 * Gets the paths.
 *
 * @param predicatePattern the predicate pattern
 * @param customQueryOptions the custom query options
 * @return the paths
 */
public PathResults getPaths(String predicatePattern, CustomQueryOptions customQueryOptions) {
    logger.debug("getPaths{}\n", predicatePattern);
    this.getEvaluationContext().getTracer().tracePaths(this, predicatePattern);
    SimpleDataset dataset = IntelligentGraphRepository.getDataset(customQueryOptions);
    dataset.addDefaultGraph(this.graphName);
    org.eclipse.rdf4j.model.Resource[] contextArray = dataset.getDefaultGraphs().toArray(new org.eclipse.rdf4j.model.Resource[0]);
    PathResults results = null;
    IRI predicate = IntelligentGraphRepository.preparePredicate(PATHQL.getPaths, predicatePattern);
    if (this.getSource().getRepository() == null) {
        CloseableIteration<? extends Statement, QueryEvaluationException> localPathIterator = this.getSource().getTripleSource().getStatements(this.getIRI(), predicate, null, contextArray);
        results = new PathResults(localPathIterator, this, null);
    } else {
        CloseableIteration<Statement, RepositoryException> pathIterator = this.getSource().getRepository().getConnection().getStatements(this.getIRI(), predicate, null, contextArray);
        results = new PathResults(pathIterator, this, null, customQueryOptions);
    }
    return results;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Statement(org.eclipse.rdf4j.model.Statement) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) SimpleDataset(org.eclipse.rdf4j.query.impl.SimpleDataset) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) PathResults(com.inova8.intelligentgraph.results.PathResults)

Example 50 with CustomQueryOptions

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

the class CustomQueryOptions method create.

/**
 * Creates the.
 *
 * @param bindValues the bind values
 * @return the custom query options
 */
public static CustomQueryOptions create(Value... bindValues) {
    if (bindValues.length > 0) {
        CustomQueryOptions customQueryOptions = new CustomQueryOptions();
        for (Integer bindIndex = 1; bindIndex <= bindValues.length; bindIndex++) {
            Value bindValue = bindValues[bindIndex - 1];
            if (bindValue.isLiteral())
                // ((Literal)bindValue).getSuperValue());
                customQueryOptions.add(bindIndex.toString(), bindValue);
            else if (bindValue.isIRI())
                customQueryOptions.add(bindIndex.toString(), ((Thing) bindValue).getIRI());
            else
                customQueryOptions.add(bindIndex.toString(), bindValue);
        }
        return customQueryOptions;
    } else
        return null;
}
Also used : CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) Value(org.eclipse.rdf4j.model.Value)

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