Search in sources :

Example 6 with Resource

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

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

the class ResourceStatementResults method next.

/**
 * Next.
 *
 * @return the resource
 * @throws QueryEvaluationException the query evaluation exception
 */
@Override
public Resource next() throws QueryEvaluationException {
    if (statementSet != null) {
        Statement next = getStatementSet().next();
        // return Resource.create(thing.getSource(), next.getObject(), getEvaluationContext());
        // Resource predicate, Boolean direction, IRI reification, Boolean isDereified,
        Resource subject = Resource.create(getSource(), next.getSubject(), getEvaluationContext());
        Predicate predicate;
        try {
            predicate = new Predicate(next.getPredicate());
        } catch (URISyntaxException e) {
            throw new QueryEvaluationException(e);
        }
        if (getEvaluationContext() != null)
            getEvaluationContext().getTracer().traceFactNext(thing, predicate, next.getObject());
        return Resource.create(getSource(), subject, predicate, next.getObject(), getEvaluationContext());
    }
    if (localStatementIterator != null) {
        Statement next = localStatementIterator.next();
        return Resource.create(getSource(), next.getObject(), getEvaluationContext());
    }
    return null;
}
Also used : QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Statement(org.eclipse.rdf4j.model.Statement) Resource(com.inova8.intelligentgraph.model.Resource) URISyntaxException(java.net.URISyntaxException) Predicate(com.inova8.intelligentgraph.model.Predicate)

Example 8 with Resource

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

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

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

the class IntelligentGraphConnection method getStatements.

/**
 * Gets the statements.
 *
 * @param subj the subj
 * @param pred the pred
 * @param obj the obj
 * @param includeInferred the include inferred
 * @param contexts the contexts
 * @return the statements
 * @throws SailException the sail exception
 */
@Override
public CloseableIteration<? extends IntelligentStatement, SailException> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws SailException {
    try {
        Resource[] extendedContexts = contexts;
        if (pred != null && !pred.stringValue().equals(SCRIPT.isprivate)) {
            extendedContexts = getContexts(contexts);
        }
        String[] predicateParts;
        if (pred != null) {
            predicateParts = decodePredicate(pred);
            switch(predicateParts[0]) {
                case PATHQL.getFact:
                case PATHQL.getFacts:
                    return getFacts(subj, decodePathQL(predicateParts, obj), obj, extendedContexts);
                case PATHQL.getPath:
                case PATHQL.getPaths:
                    return getPaths(subj, decodePathQL(predicateParts, obj), obj, extendedContexts);
                case PATHQL.traceFact:
                case PATHQL.traceFacts:
                    return traceFacts(subj, decodePathQL(predicateParts, obj), obj, extendedContexts);
                case PATHQL.clearCache:
                    return clearCache(subj, pred, obj, extendedContexts);
                case PATHQL.getScript:
                    return getScript(subj, decodePathQL(predicateParts, obj), obj, extendedContexts);
                default:
                    return new IntelligentGraphStatementsIterator(super.getStatements(subj, pred, obj, includeInferred, extendedContexts), intelligentGraphSail, this, extendedContexts);
            }
        } else {
            return new IntelligentGraphStatementsIterator(super.getStatements(subj, pred, obj, includeInferred, extendedContexts), intelligentGraphSail, this, extendedContexts);
        }
    } catch (Exception e) {
        throw new SailException(e.getMessage(), e);
    }
}
Also used : Resource(org.eclipse.rdf4j.model.Resource) 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)

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