use of com.inova8.intelligentgraph.context.CustomQueryOptions 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.context.CustomQueryOptions 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();
}
}
Aggregations