Search in sources :

Example 36 with ResourceResults

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

the class Remote_PathQL_MultiGraphTests method test_50.

/**
 * Test 50.
 */
@Test
@Order(50)
void test_50() {
    try {
        // Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph5>");
        // source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
        Graph graph = source.openGraph("<http://inova8.com/calc2graph/testGraph5>");
        Thing myCountry = graph.getThing(":Country1");
        String performanceCalculation = "2*3";
        myCountry.addFact(":Attribute@:salesPerformance", performanceCalculation, SCRIPT.GROOVY);
        ResourceResults results = myCountry.getFacts(":Attribute@:salesPerformance");
        // if(results.hasNext()) {
        for (Resource result : results) {
            assertEquals("6", result.getValue().stringValue());
            break;
        }
        // source.removeGraph("<http://inova8.com/calc2graph/testGraph>");
        source.closeGraph("<http://inova8.com/calc2graph/testGraph5>");
    // }else {
    // fail();
    // }
    } catch (Exception e) {
        fail();
    }
}
Also used : Resource(com.inova8.intelligentgraph.model.Resource) Thing(com.inova8.intelligentgraph.model.Thing) 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 37 with ResourceResults

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

the class Example2_Tests method example2_2.

/**
 * Example 2 2.
 */
@Test
@Order(2)
void example2_2() {
    try {
        Thing personType = source.getThing(":Person");
        ResourceResults persons = personType.getFacts("^rdf:type");
        ArrayList<String> personValues = new ArrayList<String>();
        ;
        for (Resource person : persons) {
            personValues.add(person.getValue().stringValue());
        }
        assertEquals("[http://inova8.com/intelligentgraph/example2/Another1, http://inova8.com/intelligentgraph/example2/Another10, http://inova8.com/intelligentgraph/example2/Another11, http://inova8.com/intelligentgraph/example2/Another12, http://inova8.com/intelligentgraph/example2/Another2, http://inova8.com/intelligentgraph/example2/Another3, http://inova8.com/intelligentgraph/example2/Another4, http://inova8.com/intelligentgraph/example2/Another5, http://inova8.com/intelligentgraph/example2/Another6, http://inova8.com/intelligentgraph/example2/Another7, http://inova8.com/intelligentgraph/example2/Another8, http://inova8.com/intelligentgraph/example2/Another9, http://inova8.com/intelligentgraph/example2/aPerson]", personValues.toString());
    } catch (Exception e) {
        assertEquals("", e.getCause().getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) Resource(com.inova8.intelligentgraph.model.Resource) Thing(com.inova8.intelligentgraph.model.Thing) 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 38 with ResourceResults

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

the class Example2_Tests method example2_8.

/**
 * Example 2 8.
 */
@Test
@Order(8)
void example2_8() {
    try {
        Thing person = source.getThing(":Person");
        ResourceResults persons = person.getFacts("^rdf:type[:hasHeight [ ge '1.7'^^xsd:double  ; le '1.8'^^xsd:double  ]]");
        ArrayList<String> personValues = new ArrayList<String>();
        for (Resource person1 : persons) {
            personValues.add(person1.getValue().stringValue());
        }
        assertEquals("[http://inova8.com/intelligentgraph/example2/Another12, http://inova8.com/intelligentgraph/example2/Another2, http://inova8.com/intelligentgraph/example2/Another4, http://inova8.com/intelligentgraph/example2/Another7, http://inova8.com/intelligentgraph/example2/Another9, http://inova8.com/intelligentgraph/example2/aPerson]", personValues.toString());
    } catch (Exception e) {
        assertEquals("", e.getCause().getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) Resource(com.inova8.intelligentgraph.model.Resource) Thing(com.inova8.intelligentgraph.model.Thing) 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 39 with ResourceResults

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

the class IntelligentGraphRepository method getFacts.

public ResourceResults getFacts(String boundPredicatePattern, CustomQueryOptions customQueryOptions) {
    logger.debug("getFacts{}\n", boundPredicatePattern);
    // this.getEvaluationContext().getTracer().traceFacts(this, queryPattern);
    SimpleDataset dataset = 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 = preparePredicate(PATHQL.getFacts, boundPredicatePattern);
    if (this.getRepository() == null) {
        CloseableIteration<? extends Statement, QueryEvaluationException> localStatementIterator = this.getTripleSource().getStatements(null, predicate, null);
        results = new ResourceStatementResults(localStatementIterator, this, null, customQueryOptions);
    } else {
        CloseableIteration<Statement, RepositoryException> statementIterator = this.getRepository().getConnection().getStatements(null, 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) Resource(org.eclipse.rdf4j.model.Resource) 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 40 with ResourceResults

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

the class IntelligentGraphRepository method getFact.

public com.inova8.intelligentgraph.model.Resource getFact(String boundPredicatePattern, CustomQueryOptions customQueryOptions) {
    logger.debug("getFact{}\n", boundPredicatePattern);
    ResourceResults factValues = getFacts(boundPredicatePattern, customQueryOptions);
    if (factValues == null) {
        // return new NullResource();
        throw new NullValueReturnedException(String.format("No values found for pattern %s with customQueryOptions %s", boundPredicatePattern, 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 customQueryOptions %s", boundPredicatePattern, customQueryOptions));
    }
}
Also used : NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) ResourceResults(com.inova8.intelligentgraph.results.ResourceResults)

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