Search in sources :

Example 26 with Fact

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

the class Local_MultiGraphAddGetFact_Tests method test_25.

/**
 * Test 25.
 */
@Test
@Order(25)
void test_25() {
    try {
        // Thing myCountry = addGraph2();
        Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph2>");
        Thing myCountry = graph.getThing(":Country");
        myCountry.addFact(":sales", "1");
        myCountry.addFact(":sales", "2");
        myCountry.addFact(":sales", "3");
        myCountry.addFact(":sales", "4");
        myCountry.addFact(":sales", "5");
        String averageSalesScript = "totalSales=0; count=0;for(sales in _this.getFacts(\"<http://inova8.com/calc2graph/def/sales>\")){totalSales +=  sales.doubleValue();count++}; return totalSales/count;";
        myCountry.addFact(":averageSales", averageSalesScript, SCRIPT.GROOVY);
        CustomQueryOptions customQueryOptions = new CustomQueryOptions();
        customQueryOptions.add("time", 42);
        customQueryOptions.add("name", "Peter");
        Trace averageCountrySalesTrace = myCountry.traceFact(":averageSales", customQueryOptions);
        source.removeGraph("<http://inova8.com/calc2graph/testGraph2>");
        // Query.assertEqualsWOSpaces
        assertEquals("<ol style='list-style-type:none;'><li>Getting facts  ':averageSales' of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a></li></li><li>...using options: [name=&quot;Peter&quot;&amp;time=&quot;42&quot;^^&lt;http://www.w3.org/2001/XMLSchema#int&gt;]</li></li><li>...within contexts: [file://src/test/resources/calc2graph.def.ttl, http://inova8.com/calc2graph/testGraph2]</li></li><ol style='list-style-type:none;'><li>Evaluating predicate <a href='http://inova8.com/calc2graph/def/averageSales' target='_blank'>averageSales</a> of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a>, by invoking <b>groovy</b> script\n" + "</li></li><li><div  style='border: 1px solid black;'> <pre><code >totalSales=0; count=0;for(sales in _this.getFacts(&quot;&lt;http://inova8.com/calc2graph/def/sales&gt;&quot;)){totalSales += &nbsp;sales.doubleValue();count++}; return totalSales/count;</code></pre></div></li><ol style='list-style-type:none;'><li>Getting facts '&lt;http://inova8.com/calc2graph/def/sales&gt;' of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a> </li></li><li>Next fact 'http://inova8.com/calc2graph/def/sales' of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a> = 1</li></li><li>Next fact 'http://inova8.com/calc2graph/def/sales' of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a> = 2</li></li><li>Next fact 'http://inova8.com/calc2graph/def/sales' of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a> = 3</li></li><li>Next fact 'http://inova8.com/calc2graph/def/sales' of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a> = 4</li></li><li>Next fact 'http://inova8.com/calc2graph/def/sales' of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a> = 5</li></li></ol><li>Evaluated <a href='http://inova8.com/calc2graph/def/averageSales' target='_blank'>averageSales</a> of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a> =  3.0^^<a href='http://www.w3.org/2001/XMLSchema#double' target='_blank'>double</a></li></li></ol><li>Calculated <a href='http://inova8.com/calc2graph/def/averageSales' target='_blank'>averageSales</a> of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a> = 3.0^^<a href='http://www.w3.org/2001/XMLSchema#double' target='_blank'>double</a></li></li><li>Retrieved cached value <a href='http://inova8.com/calc2graph/def/averageSales' target='_blank'>averageSales</a> of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a> = 3.0^^<a href='http://www.w3.org/2001/XMLSchema#double' target='_blank'>double</a></li></li><li>Returned fact 'http://inova8.com/calc2graph/def/averageSales' of <a href='http://inova8.com/calc2graph/def/Country' target='_blank'>Country</a> = 3.0^^<a href='http://www.w3.org/2001/XMLSchema#double' target='_blank'>double</a></li></li><p></ol>", averageCountrySalesTrace.asHTML());
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : Trace(com.inova8.intelligentgraph.evaluator.Trace) Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) Thing(com.inova8.intelligentgraph.model.Thing) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 27 with Fact

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

Thing (com.inova8.intelligentgraph.model.Thing)19 Order (org.junit.jupiter.api.Order)11 Test (org.junit.jupiter.api.Test)11 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)11 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)9 Resource (com.inova8.intelligentgraph.model.Resource)8 IRI (org.eclipse.rdf4j.model.IRI)8 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)6 EvaluationContext (com.inova8.intelligentgraph.evaluator.EvaluationContext)6 ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)6 Value (org.eclipse.rdf4j.model.Value)6 SimpleLiteral (org.eclipse.rdf4j.model.impl.SimpleLiteral)6 Trace (com.inova8.intelligentgraph.evaluator.Trace)5 ValueExprEvaluationException (org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException)4 NullValueReturnedException (com.inova8.intelligentgraph.exceptions.NullValueReturnedException)3 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)3 PredicateElement (com.inova8.pathql.element.PredicateElement)3 BindingSet (org.eclipse.rdf4j.query.BindingSet)3 ReificationType (com.inova8.pathql.context.ReificationType)2 NoSuchElementException (java.util.NoSuchElementException)2