Search in sources :

Example 1 with ResourceResults

use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Thing method getFact.

/**
 * Gets the fact.
 *
 * @param predicatePattern the predicate pattern
 * @param bindValues the bind values
 * @return the fact
 */
public Resource getFact(String predicatePattern, Value... bindValues) {
    logger.debug("getFact{}\n", predicatePattern);
    // this.getEvaluationContext().getTracer().traceFact(this, predicatePattern);
    ResourceResults factValues = getFacts(predicatePattern, bindValues);
    if (factValues == null) {
        this.getEvaluationContext().getTracer().traceFactReturnNull(this, predicatePattern);
        throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s", predicatePattern, this));
    } else if (factValues.hasNext()) {
        Resource nextFact = factValues.next();
        this.getEvaluationContext().getTracer().traceFactReturnValue(this, predicatePattern, nextFact);
        return nextFact;
    } else {
        this.getEvaluationContext().getTracer().traceFactEmpty(this, predicatePattern);
        factValues.close();
        throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s", predicatePattern, this));
    }
}
Also used : NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) ResourceResults(com.inova8.intelligentgraph.results.ResourceResults)

Example 2 with ResourceResults

use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Thing method getFacts.

/**
 * Gets the facts.
 *
 * @param predicatePattern the predicate pattern
 * @param customQueryOptions the custom query options
 * @return the facts
 */
public ResourceResults getFacts(String predicatePattern, CustomQueryOptions customQueryOptions) {
    logger.debug("getFacts{}\n", predicatePattern);
    this.getEvaluationContext().getTracer().traceFacts(this, predicatePattern);
    SimpleDataset dataset = IntelligentGraphRepository.getDataset(customQueryOptions);
    dataset.addDefaultGraph(this.graphName);
    org.eclipse.rdf4j.model.Resource[] contextArray = dataset.getDefaultGraphs().toArray(new org.eclipse.rdf4j.model.Resource[0]);
    ResourceStatementResults results = null;
    IRI predicate = IntelligentGraphRepository.preparePredicate(PATHQL.getFacts, predicatePattern);
    if (this.getSource().getRepository() == null) {
        CloseableIteration<? extends Statement, QueryEvaluationException> localStatementIterator = this.getSource().getTripleSource().getStatements(this.getIRI(), predicate, null, contextArray);
        results = new ResourceStatementResults(localStatementIterator, this, null, customQueryOptions);
    } else {
        CloseableIteration<Statement, RepositoryException> statementIterator = this.getSource().getRepository().getConnection().getStatements(this.getIRI(), predicate, null, contextArray);
        results = new ResourceStatementResults(statementIterator, this, null, customQueryOptions);
    }
    return results;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Statement(org.eclipse.rdf4j.model.Statement) ResourceStatementResults(com.inova8.intelligentgraph.results.ResourceStatementResults) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) SimpleDataset(org.eclipse.rdf4j.query.impl.SimpleDataset) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException)

Example 3 with ResourceResults

use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Thing method getFact.

/**
 * Gets the fact.
 *
 * @param predicatePattern the predicate pattern
 * @param customQueryOptions the custom query options
 * @return the fact
 */
public Resource getFact(String predicatePattern, CustomQueryOptions customQueryOptions) {
    logger.debug("getFact{}\n", predicatePattern);
    ResourceResults factValues = getFacts(predicatePattern, customQueryOptions);
    if (factValues == null) {
        // return new NullResource();
        throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s and customQueryOptions %s", predicatePattern, this, customQueryOptions));
    } else if (factValues.hasNext()) {
        return factValues.next();
    } else {
        factValues.close();
        // return new NullResource();
        throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s and customQueryOptions %s", predicatePattern, this, customQueryOptions));
    }
}
Also used : NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) ResourceResults(com.inova8.intelligentgraph.results.ResourceResults)

Example 4 with ResourceResults

use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Local_BoundFact_Tests method test_1_1.

@Test
@Order(1_1)
void test_1_1() {
    try {
        ResourceResults results = source.getFacts(":hasProductBatteryLimit");
        assertEquals("[ {s=http://inova8.com/calc2graph/id/Unit1, p=http://inova8.com/calc2graph/def/hasProductBatteryLimit, o=http://inova8.com/calc2graph/id/BatteryLimit2}; {s=http://inova8.com/calc2graph/id/Unit1, p=http://inova8.com/calc2graph/def/hasProductBatteryLimit, o=http://inova8.com/calc2graph/id/BatteryLimit3};]", results.toString());
    } catch (Exception e) {
        assertEquals("Facts query unbound", e.getMessage());
    }
}
Also used : ResourceResults(com.inova8.intelligentgraph.results.ResourceResults) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 5 with ResourceResults

use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Local_BoundFact_Tests method test_1_2.

@Test
@Order(1_2)
void test_1_2() {
    try {
        ResourceResults results = source.getFacts("[eq *]/:hasProductBatteryLimit");
        assertEquals("[http://inova8.com/calc2graph/id/BatteryLimit2;http://inova8.com/calc2graph/id/BatteryLimit3;]", results.toString());
    } catch (Exception e) {
        assertEquals("[line 1:4 in \"[eq *]/:hasProductBatteryLimit\": no viable alternative at input '[eq*']", e.getCause().getMessage());
    }
}
Also used : ResourceResults(com.inova8.intelligentgraph.results.ResourceResults) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)46 Order (org.junit.jupiter.api.Order)42 Test (org.junit.jupiter.api.Test)42 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)42 Thing (com.inova8.intelligentgraph.model.Thing)33 Resource (com.inova8.intelligentgraph.model.Resource)23 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)12 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)7 ArrayList (java.util.ArrayList)7 NullValueReturnedException (com.inova8.intelligentgraph.exceptions.NullValueReturnedException)4 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)3 Path (com.inova8.intelligentgraph.path.Path)3 PathResults (com.inova8.intelligentgraph.results.PathResults)3 Trace (com.inova8.intelligentgraph.evaluator.Trace)2 ResourceStatementResults (com.inova8.intelligentgraph.results.ResourceStatementResults)2 PathPatternException (com.inova8.pathql.processor.PathPatternException)2 RecognitionException (org.antlr.v4.runtime.RecognitionException)2 IRI (org.eclipse.rdf4j.model.IRI)2 Statement (org.eclipse.rdf4j.model.Statement)2 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)2