Search in sources :

Example 1 with PathPatternException

use of com.inova8.pathql.processor.PathPatternException in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphConnection method addFact.

/**
 * Adds the fact.
 *
 * @param modify the modify
 * @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(UpdateContext modify, 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(modify, reification, RDF.TYPE, predicateElement.getReification(), contexts);
            super.addStatement(modify, reification, reificationType.getReificationSubject(), thing.getIRI(), contexts);
            super.addStatement(modify, reification, reificationType.getReificationPredicate(), predicateElement.getPredicate(), contexts);
            super.addStatement(modify, reification, reificationType.getReificationObject(), value, contexts);
        } else {
            logger.error("Reified type not supported:" + predicateElement.toString());
        }
    } else {
        IRI propertyIri = predicateElement.getPredicate();
        super.addStatement(modify, 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 2 with PathPatternException

use of com.inova8.pathql.processor.PathPatternException 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 3 with PathPatternException

use of com.inova8.pathql.processor.PathPatternException 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 4 with PathPatternException

use of com.inova8.pathql.processor.PathPatternException 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 5 with PathPatternException

use of com.inova8.pathql.processor.PathPatternException 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

PathElement (com.inova8.pathql.element.PathElement)25 Order (org.junit.jupiter.api.Order)17 Test (org.junit.jupiter.api.Test)17 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)17 Thing (com.inova8.intelligentgraph.model.Thing)15 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)9 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)6 PathBinding (com.inova8.intelligentgraph.path.PathBinding)5 PredicateElement (com.inova8.pathql.element.PredicateElement)4 PathPatternLexer (com.inova8.pathql.pathPattern.PathPatternLexer)3 PathPatternParser (com.inova8.pathql.pathPattern.PathPatternParser)3 PathPatternVisitor (com.inova8.pathql.processor.PathPatternVisitor)3 CharStream (org.antlr.v4.runtime.CharStream)3 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)3 IRI (org.eclipse.rdf4j.model.IRI)3 ReificationType (com.inova8.pathql.context.ReificationType)2 PathPatternException (com.inova8.pathql.processor.PathPatternException)2 IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)1 IriRefContext (com.inova8.pathql.pathPattern.PathPatternParser.IriRefContext)1 PathEltOrInverseContext (com.inova8.pathql.pathPattern.PathPatternParser.PathEltOrInverseContext)1