Search in sources :

Example 46 with ResourceResults

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

the class Local_GetContextFact_Tests method test_1.

/**
 * Test 1.
 */
@Test
@Order(1)
void test_1() {
    try {
        IntelligentGraphRepository source = IntelligentGraphRepository.create(workingRep);
        // source.prefix("<http://inova8.com/calc2graph/def/>");
        // source.prefix("rdfs", "<http://www.w3.org/2000/01/rdf-schema#>");
        source.removeGraph("<http://inova8.com/calc2graph/contextGraph>");
        // source.prefix("xsd", "<http://www.w3.org/2001/XMLSchema#>");
        Graph graph = source.addGraph("<http://inova8.com/calc2graph/contextGraph>");
        Thing myCountry = graph.getThing(":myCountry");
        myCountry.addFact(":myOption", "_customQueryOptions.get(\"time\").integerValue() ;", SCRIPT.GROOVY);
        CustomQueryOptions customQueryOptions1 = new CustomQueryOptions();
        customQueryOptions1.add("time", 42);
        customQueryOptions1.add("name", "Peter");
        Thing myCountry1 = graph.getThing(":myCountry");
        Resource result;
        result = myCountry1.getFact("<http://inova8.com/calc2graph/def/myOption>", customQueryOptions1);
        assertEquals("42", result.stringValue());
        CustomQueryOptions customQueryOptions2 = new CustomQueryOptions();
        customQueryOptions2.add("time", 43);
        result = myCountry1.getFact("<http://inova8.com/calc2graph/def/myOption>", customQueryOptions2);
        assertEquals("43", result.stringValue());
        CustomQueryOptions customQueryOptions3 = new CustomQueryOptions();
        customQueryOptions3.add("time", 2019);
        result = myCountry.getFact(":myOption&time='2019'^^xsd:int", customQueryOptions3);
        assertEquals("2019", result.stringValue());
        ResourceResults results = myCountry.getFacts("<http://inova8.com/calc2graph/def/myOption>&time='2020'^^xsd:int");
        for (Resource result1 : results) {
            assertEquals("2020", result1.stringValue());
        }
    } catch (Exception e) {
        assertEquals("", e.getMessage());
        e.printStackTrace();
    }
}
Also used : IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) 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 47 with ResourceResults

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

the class Local_GetFact_Tests method test_30.

/**
 * Test 30.
 */
@Test
@Order(30)
void test_30() {
    try {
        source.addGraph("http://inova8.com/calc2graph/testGraph");
        Thing _this = source.getThing(iri("http://inova8.com/calc2graph/id/BatteryLimit1"), null);
        ResourceResults results = _this.getFacts("(:Attribute@:density  |:density)");
        for (Resource result : results) {
            assertEquals(".42", result.stringValue());
        }
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
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 48 with ResourceResults

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

the class Local_GetFact_Tests method test_3.

/**
 * Test 3.
 */
@Test
@Order(3)
void test_3() {
    try {
        Thing _this = Thing.create(source, iri("http://inova8.com/calc2graph/id/Unit1"), null);
        Double fact = 0.0;
        for (Resource batterylimit : _this.getFacts(":hasProductBatteryLimit")) {
            fact += batterylimit.getFact(":massFlow").doubleValue();
        }
        ResourceResults batterylimits = _this.getFacts(":hasProductBatteryLimit");
        Resource batterylimit;
        while (batterylimits.hasNext()) {
            batterylimit = batterylimits.next();
            fact -= batterylimit.getFact(":massFlow").doubleValue();
        }
        ;
        assertEquals(0.0, fact);
    } catch (Exception e) {
        assertEquals("", e.getMessage());
        e.printStackTrace();
    }
}
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)

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