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="Peter"&time="42"^^<http://www.w3.org/2001/XMLSchema#int>]</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("<http://inova8.com/calc2graph/def/sales>")){totalSales += sales.doubleValue();count++}; return totalSales/count;</code></pre></div></li><ol style='list-style-type:none;'><li>Getting facts '<http://inova8.com/calc2graph/def/sales>' 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());
}
}
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();
}
}
Aggregations