Search in sources :

Example 11 with Resource

use of com.inova8.intelligentgraph.model.Resource 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 12 with Resource

use of com.inova8.intelligentgraph.model.Resource 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)

Example 13 with Resource

use of com.inova8.intelligentgraph.model.Resource 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 pathTupleExpr the path tuple expr
 * @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, PathTupleExpr pathTupleExpr, Resource... contexts) throws IllegalArgumentException, QueryEvaluationException {
    TupleExpr tupleExpr = pathTupleExpr.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) 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 14 with Resource

use of com.inova8.intelligentgraph.model.Resource in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphConnection method addStatement.

/**
 * Adds the statement.
 *
 * @param modify the modify
 * @param subj the subj
 * @param pred the pred
 * @param obj the obj
 * @param contexts the contexts
 * @throws SailException the sail exception
 */
@Override
public void addStatement(UpdateContext modify, Resource subj, IRI pred, Value obj, Resource... contexts) throws SailException {
    try {
        String[] predicateParts;
        if (pred != null) {
            // predicateParts= pred.stringValue().split(IntelligentGraphConstants.PATH_QL_REGEX);
            predicateParts = decodePredicate(pred);
            switch(predicateParts[0]) {
                case PATHQL.addFact:
                    addFact(modify, subj, predicateParts[1], obj, contexts);
                    break;
                default:
                    super.addStatement(modify, subj, pred, obj, contexts);
                    checkReificationsChanged(pred);
            }
        } else
            super.addStatement(modify, subj, pred, obj, contexts);
        this.intelligentGraphSail.clearCache();
    } catch (Exception e) {
        throw new SailException(e);
    }
}
Also used : SailException(org.eclipse.rdf4j.sail.SailException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) SailException(org.eclipse.rdf4j.sail.SailException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 15 with Resource

use of com.inova8.intelligentgraph.model.Resource in project com.inova8.intelligentgraph by peterjohnlawrence.

the class ResourceResults method toString.

/**
 * To string.
 *
 * @return the string
 */
public String toString() {
    String toString = "[";
    while (hasNext()) {
        Resource resource = (Resource) next();
        toString += resource.toString() + ";";
    }
    return toString + "]";
}
Also used : Resource(com.inova8.intelligentgraph.model.Resource)

Aggregations

Resource (com.inova8.intelligentgraph.model.Resource)140 Order (org.junit.jupiter.api.Order)135 Test (org.junit.jupiter.api.Test)135 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)135 Thing (com.inova8.intelligentgraph.model.Thing)113 ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)26 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)20 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)19 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)11 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)9 PathPatternException (com.inova8.pathql.processor.PathPatternException)8 RecognitionException (org.antlr.v4.runtime.RecognitionException)8 ArrayList (java.util.ArrayList)7 IRI (org.eclipse.rdf4j.model.IRI)7 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)7 Repository (org.eclipse.rdf4j.repository.Repository)6 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)6 NullValueReturnedException (com.inova8.intelligentgraph.exceptions.NullValueReturnedException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 BindingSet (org.eclipse.rdf4j.query.BindingSet)5