Search in sources :

Example 6 with IntelligentGraphRepository

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

the class IntelligentGraphEvaluator method nextGraph.

/**
 * Next graph.
 *
 * @return the binding set
 */
private BindingSet nextGraph() {
    BindingSet nextBindingSet = getEvaluator().next();
    try {
        if (nextBindingSet.hasBinding("subject") && nextBindingSet.hasBinding("predicate") && nextBindingSet.hasBinding("object")) {
            if (nextBindingSet.getValue("object").isLiteral()) {
                SimpleLiteral literalValue = (SimpleLiteral) (nextBindingSet.getValue("object"));
                if (Evaluator.getEngineNames().containsKey(literalValue.getDatatype())) {
                    QueryBindingSet modifiedBindingSet = new QueryBindingSet();
                    modifiedBindingSet.addBinding(nextBindingSet.getBinding("subject"));
                    modifiedBindingSet.addBinding(nextBindingSet.getBinding("predicate"));
                    IntelligentGraphRepository source = getSource();
                    EvaluationContext evaluationContext = new EvaluationContext(customQueryOptions, getDataset());
                    Thing subjectThing = Thing.create(source, nextBindingSet.getValue("subject"), evaluationContext);
                    try {
                        // TODOcom.inova8.intelligentgraph.model.Resource fact = subjectThing.getFact(	(IRI) nextBindingSet.getValue("predicate"),	literalValue,customQueryOptions);
                        com.inova8.intelligentgraph.model.Resource fact = IntelligentEvaluator.processFactObjectValue(subjectThing, (IRI) nextBindingSet.getValue("predicate"), literalValue, customQueryOptions);
                        Binding modifiedBindingValue = new SimpleBinding("object", fact.getValue());
                        modifiedBindingSet.addBinding(modifiedBindingValue);
                        return modifiedBindingSet;
                    } catch (Exception e) {
                        Binding modifiedBindingValue = new SimpleBinding("object", literal(StringEscapeUtils.escapeEcmaScript(e.getMessage())));
                        // literal(e.getMessage()));
                        modifiedBindingSet.addBinding(modifiedBindingValue);
                        return modifiedBindingSet;
                    }
                } else {
                    return locateCustomQueryOptions(nextBindingSet);
                }
            } else {
                return locateCustomQueryOptions(nextBindingSet);
            }
        } else {
            // Incomplete s p o within dataset so could not calculate
            return nextBindingSet;
        }
    } catch (Exception e) {
        // Should not be any exceptions that are not handled, but even so ...
        return nextBindingSet;
    }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) SimpleBinding(org.eclipse.rdf4j.query.impl.SimpleBinding) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) BindingSet(org.eclipse.rdf4j.query.BindingSet) IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) Resource(com.inova8.intelligentgraph.model.Resource) SimpleBinding(org.eclipse.rdf4j.query.impl.SimpleBinding) SimpleLiteral(org.eclipse.rdf4j.model.impl.SimpleLiteral) EvaluationContext(com.inova8.intelligentgraph.evaluator.EvaluationContext) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Thing(com.inova8.intelligentgraph.model.Thing) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) NoSuchElementException(java.util.NoSuchElementException)

Example 7 with IntelligentGraphRepository

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

the class IntelligentGraphConnection method traceFacts.

/**
 * Trace facts.
 *
 * @param thingresource the thingresource
 * @param pathQLValue the path QL value
 * @param contexts the contexts
 * @return the closeable iteration<? extends intelligent statement, sail exception>
 * @throws PathPatternException the path pattern exception
 */
@SuppressWarnings("deprecation")
private CloseableIteration<? extends IntelligentStatement, SailException> traceFacts(Resource thingresource, String pathQLValue, Value obj, Resource... contexts) throws PathPatternException {
    IntelligentGraphRepository source = IntelligentGraphRepository.create(this);
    Thing thing = Thing.create(source, thingresource, null);
    thing.getEvaluationContext().setTracing(true);
    thing.getEvaluationContext().getTracer().clear();
    thing.getEvaluationContext().getTracer().traceFacts(thing, pathQLValue, source.getRepositoryContext().getPrefixes(), contexts);
    String pathQL = pathQLValue;
    PathElement pathElement = PathParser.parsePathPattern(source.getRepositoryContext(), pathQL);
    pathElement.getSourceVariable().setValue(thing.getValue());
    return traceThingFacts(source, thing, pathElement, contexts);
}
Also used : IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) PathElement(com.inova8.pathql.element.PathElement) Thing(com.inova8.intelligentgraph.model.Thing)

Example 8 with IntelligentGraphRepository

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

the class IntelligentGraphConnection method deleteFacts.

/**
 * Delete facts.
 *
 * @param modify the modify
 * @param thingresource the thingresource
 * @param pathQLValue the path QL value
 * @param contexts the contexts
 * @throws PathPatternException the path pattern exception
 */
private void deleteFacts(UpdateContext modify, Resource thingresource, String pathQLValue, Value obj, Resource... contexts) throws PathPatternException {
    IntelligentGraphRepository source = IntelligentGraphRepository.create(this);
    Thing thing = Thing.create(source, thingresource, null);
    // TODO toPathQLString(pathQLValue);
    String pathQL = pathQLValue;
    PathElement pathElement = PathParser.parsePathPattern(source.getRepositoryContext(), pathQL);
    pathElement.getSourceVariable().setValue(thing.getValue());
    deleteThingFacts(modify, source, thing, pathElement, contexts);
}
Also used : IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) PathElement(com.inova8.pathql.element.PathElement) Thing(com.inova8.intelligentgraph.model.Thing)

Example 9 with IntelligentGraphRepository

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

the class IntelligentGraphConnection method getFacts.

/**
 * Gets the facts.
 *
 * @param thingresource the thingresource
 * @param pathQLValue the path QL value
 * @param contexts the contexts
 * @return the facts
 * @throws PathPatternException the path pattern exception
 */
private CloseableIteration<? extends IntelligentStatement, SailException> getFacts(Resource thingresource, String pathQLValue, Value obj, Resource... contexts) throws PathPatternException {
    IntelligentGraphRepository source = IntelligentGraphRepository.create(this);
    String pathQL = pathQLValue;
    PathElement pathElement = PathParser.parsePathPattern(source.getRepositoryContext(), pathQL);
    Thing thing = null;
    if (thingresource != null) {
        thing = Thing.create(source, thingresource, null);
        pathElement.getSourceVariable().setValue(thing.getValue());
    }
    return getThingFacts(source, thing, pathElement, contexts);
}
Also used : IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) PathElement(com.inova8.pathql.element.PathElement) Thing(com.inova8.intelligentgraph.model.Thing)

Example 10 with IntelligentGraphRepository

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

the class IntelligentGraphConnection method deleteThingFacts.

/**
 * Delete thing facts.
 *
 * @param modify the modify
 * @param source the source
 * @param thing the thing
 * @param pathElement the path element
 * @param contexts the contexts
 * @throws PathPatternException the path pattern exception
 */
private void deleteThingFacts(UpdateContext modify, IntelligentGraphRepository source, Thing thing, PathElement pathElement, Resource... contexts) throws PathPatternException {
    CloseableIteration<BindingSet, QueryEvaluationException> resultsIterator = getResultsIterator(source, thing, pathElement, 0, contexts);
    if (((PredicateElement) pathElement).getIsReified()) {
        String reified = ((PredicateElement) pathElement).getReifiedVariable().getName();
        while (resultsIterator.hasNext()) {
            BindingSet bindingSet = resultsIterator.next();
            super.removeStatements((Resource) bindingSet.getBinding(reified).getValue(), null, null, contexts);
        }
    } else {
        String subj = pathElement.getTargetSubject().getName();
        String pred = pathElement.getTargetPredicate().getName();
        String obj = pathElement.getTargetVariable().getName();
        while (resultsIterator.hasNext()) {
            BindingSet bindingSet = resultsIterator.next();
            IRI predicate = (IRI) bindingSet.getBinding(pred).getValue();
            super.removeStatements((Resource) bindingSet.getBinding(subj).getValue(), (IRI) bindingSet.getBinding(pred).getValue(), bindingSet.getBinding(obj).getValue(), contexts);
            checkReificationsChanged(predicate);
        }
    }
}
Also used : QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) BindingSet(org.eclipse.rdf4j.query.BindingSet) IRI(org.eclipse.rdf4j.model.IRI) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) PredicateElement(com.inova8.pathql.element.PredicateElement)

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