Search in sources :

Example 36 with IntelligentGraphRepository

use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository 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 IntelligentGraphRepository

use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphConnection method addFact.

/**
 * Adds the fact.
 *
 * @param thingresource the thingresource
 * @param pathQL the path QL
 * @param value the value
 * @param contexts the contexts
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
private void addFact(Resource thingresource, String pathQL, Value value, Resource... contexts) throws RecognitionException, PathPatternException {
    IntelligentGraphRepository source = IntelligentGraphRepository.create(this);
    Thing thing = Thing.create(source, thingresource, null);
    PredicateElement predicateElement = (PredicateElement) PathParser.parsePathPattern(source.getRepositoryContext(), pathQL);
    predicateElement.getSourceVariable().setValue(thing.getValue());
    if (predicateElement.getIsReified()) {
        ReificationType reificationType = source.getRepositoryContext().getReificationTypes().get(predicateElement.getReification().stringValue());
        if (reificationType != null) {
            IRI reification = iri(reificationType.getReificationType().stringValue() + "/" + thing.getIRI().hashCode() + "." + predicateElement.getPredicate().hashCode() + "." + value.hashCode());
            super.addStatement(reification, RDF.TYPE, predicateElement.getReification(), contexts);
            super.addStatement(reification, reificationType.getReificationSubject(), thing.getIRI(), contexts);
            super.addStatement(reification, reificationType.getReificationPredicate(), predicateElement.getPredicate(), contexts);
            super.addStatement(reification, reificationType.getReificationObject(), value, contexts);
        } else {
            logger.error("Reified type not supported:" + predicateElement.toString());
        }
    } else {
        IRI propertyIri = predicateElement.getPredicate();
        super.addStatement(thing.getIRI(), propertyIri, value, contexts);
        checkReificationsChanged(propertyIri);
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) ReificationType(com.inova8.pathql.context.ReificationType) PredicateElement(com.inova8.pathql.element.PredicateElement) Thing(com.inova8.intelligentgraph.model.Thing)

Example 38 with IntelligentGraphRepository

use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository 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 39 with IntelligentGraphRepository

use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphRepository method create.

/**
 * Creates the.
 *
 * @param intelligentGraphConnection the intelligent graph connection
 * @return the intelligent graph repository
 */
public static IntelligentGraphRepository create(IntelligentGraphConnection intelligentGraphConnection) {
    IntelligentGraphSail sail = intelligentGraphConnection.getIntelligentGraphSail();
    Integer key = sail.hashCode();
    if (pathQLRepositories.containsKey(key)) {
        return pathQLRepositories.get(key);
    } else {
        IntelligentGraphRepository pathQLRepository = new IntelligentGraphRepository(intelligentGraphConnection);
        pathQLRepositories.put(key, pathQLRepository);
        return pathQLRepository;
    }
}
Also used : IntelligentGraphSail(com.inova8.intelligentgraph.sail.IntelligentGraphSail)

Example 40 with IntelligentGraphRepository

use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Sources method getSource.

/**
 * Gets the source.
 *
 * @param tripleSource the triple source
 * @param args the args
 * @return the source
 */
public IntelligentGraphRepository getSource(TripleSource tripleSource, Value[] args) {
    Integer cacheHash;
    if (args.length > 0) {
        cacheHash = locateCachHashArgument(args);
        if (cacheHash == null)
            cacheHash = tripleSource.hashCode();
    } else {
        cacheHash = tripleSource.hashCode();
    }
    IntelligentGraphRepository source;
    if (!sources.containsKey(cacheHash)) {
        source = IntelligentGraphRepository.create(tripleSource);
        sources.put(cacheHash, source);
        logger.error("Failed to locate hash <{}>, new source created  <{}>", locateCachHashArgument(args), cacheHash);
    } else {
        source = sources.get(cacheHash);
        // Need to ensure we are using the latest triplesource, which changes even though from same triplestore
        source.setTripleSource(tripleSource);
    }
    return source;
}
Also used : IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)

Aggregations

IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)37 Thing (com.inova8.intelligentgraph.model.Thing)36 Order (org.junit.jupiter.api.Order)24 Test (org.junit.jupiter.api.Test)24 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)24 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)20 Resource (com.inova8.intelligentgraph.model.Resource)15 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)11 IRI (org.eclipse.rdf4j.model.IRI)9 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)9 Repository (org.eclipse.rdf4j.repository.Repository)8 EvaluationContext (com.inova8.intelligentgraph.evaluator.EvaluationContext)7 ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)7 Trace (com.inova8.intelligentgraph.evaluator.Trace)6 Value (org.eclipse.rdf4j.model.Value)5 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)5 ValueExprEvaluationException (org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException)5 PathElement (com.inova8.pathql.element.PathElement)4 SimpleLiteral (org.eclipse.rdf4j.model.impl.SimpleLiteral)4 BindingSet (org.eclipse.rdf4j.query.BindingSet)4