use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Local_GetTraceFact_Tests method test_5.
/**
* Test 5.
*/
@Test
@Order(5)
void test_5() {
try {
IntelligentGraphRepository source = IntelligentGraphRepository.create(workingRep);
source.removeGraph("<http://inova8.com/calc2graph/contextGraph>");
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");
Trace result = myCountry1.traceFact("<http://inova8.com/calc2graph/def/myOption>", customQueryOptions1);
Query.assertEqualsWOSpaces(// assertEquals
"<olstyle='list-style-type:none;'><li>Gettingfacts'<http://inova8.com/calc2graph/def/myOption>'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a></li></li><li>...usingoptions:[name="Peter"&time="42"^^<http://www.w3.org/2001/XMLSchema#int>]</li></li><li>...withincontexts:[file://src/test/resources/calc2graph.def.ttl,http://inova8.com/calc2graph/contextGraph,file://src/test/resources/calc2graph.data.ttl]</li></li><olstyle='list-style-type:none;'><li>Evaluatingpredicate<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>,byinvoking<b>groovy</b>script</li></li><li><divstyle='border:1pxsolidblack;'><pre><code>_customQueryOptions.get("time").integerValue();</code></pre></div></li><olstyle='list-style-type:none;'></ol><li>Evaluated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li></ol><li>Calculated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Retrievedcachedvalue<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Returnedfact'http://inova8.com/calc2graph/def/myOption'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><p></ol>", result.asHTML());
CustomQueryOptions customQueryOptions2 = new CustomQueryOptions();
customQueryOptions2.add("time", 43);
result = myCountry1.traceFact("<http://inova8.com/calc2graph/def/myOption>", customQueryOptions2);
Query.assertEqualsWOSpaces(// assertEquals
"1.Gettingfacts'<http://inova8.com/calc2graph/def/myOption>'ofmyCountry<http://inova8.com/calc2graph/def/myCountry>2....usingoptions:[time=\"43\"^^<http://www.w3.org/2001/XMLSchema#int>]3....withincontexts:[file://src/test/resources/calc2graph.def.ttl,http://inova8.com/calc2graph/contextGraph,file://src/test/resources/calc2graph.data.ttl]1.EvaluatingpredicatemyOption<http://inova8.com/calc2graph/def/myOption>ofmyCountry<http://inova8.com/calc2graph/def/myCountry>,byinvokinggroovyscript2._customQueryOptions.get(\"time\").integerValue();3.EvaluatedmyOption<http://inova8.com/calc2graph/def/myOption>ofmyCountry<http://inova8.com/calc2graph/def/myCountry>=43^^int<http://www.w3.org/2001/XMLSchema#int>4.CalculatedmyOption<http://inova8.com/calc2graph/def/myOption>ofmyCountry<http://inova8.com/calc2graph/def/myCountry>=43^^int<http://www.w3.org/2001/XMLSchema#int>5.RetrievedcachedvaluemyOption<http://inova8.com/calc2graph/def/myOption>ofmyCountry<http://inova8.com/calc2graph/def/myCountry>=43^^int<http://www.w3.org/2001/XMLSchema#int>6.Returnedfact'http://inova8.com/calc2graph/def/myOption'ofmyCountry<http://inova8.com/calc2graph/def/myCountry>=43^^int<http://www.w3.org/2001/XMLSchema#int>", result.asText());
result = myCountry1.traceFact("<http://inova8.com/calc2graph/def/myOption>&time='2019'^^xsd:int");
Query.assertEqualsWOSpaces(// assertEquals
"1.Gettingfacts'<http://inova8.com/calc2graph/def/myOption>&time='2019'^^xsd:int'ofmyCountry<http://inova8.com/calc2graph/def/myCountry>2....withincontexts:[file://src/test/resources/calc2graph.def.ttl,http://inova8.com/calc2graph/contextGraph,file://src/test/resources/calc2graph.data.ttl]1.EvaluatingpredicatemyOption<http://inova8.com/calc2graph/def/myOption>ofmyCountry<http://inova8.com/calc2graph/def/myCountry>,byinvokinggroovyscript2._customQueryOptions.get(\"time\").integerValue();3.EvaluatedmyOption<http://inova8.com/calc2graph/def/myOption>ofmyCountry<http://inova8.com/calc2graph/def/myCountry>=2019^^int<http://www.w3.org/2001/XMLSchema#int>3.CalculatedmyOption<http://inova8.com/calc2graph/def/myOption>ofmyCountry<http://inova8.com/calc2graph/def/myCountry>=2019^^int<http://www.w3.org/2001/XMLSchema#int>4.RetrievedcachedvaluemyOption<http://inova8.com/calc2graph/def/myOption>ofmyCountry<http://inova8.com/calc2graph/def/myCountry>=2019^^int<http://www.w3.org/2001/XMLSchema#int>5.Returnedfact'http://inova8.com/calc2graph/def/myOption'ofmyCountry<http://inova8.com/calc2graph/def/myCountry>=2019^^int<http://www.w3.org/2001/XMLSchema#int>", result.asText());
ResourceResults results = myCountry1.getFacts("<http://inova8.com/calc2graph/def/myOption>&time='2020'^^xsd:int");
for (Resource result1 : results) {
Query.assertEqualsWOSpaces("2020", result1.stringValue());
}
} catch (Exception e) {
assertEquals("", e.getMessage());
e.printStackTrace();
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Local_MultiGraphAddGetFact_Tests method test_20.
/**
* Test 20.
*/
@Test
@Order(20)
void test_20() {
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");
Double averageCountrySales = myCountry.getFact(":averageSales", customQueryOptions).doubleValue();
source.removeGraph("<http://inova8.com/calc2graph/testGraph2>");
assertEquals(3.0, averageCountrySales);
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Local_GetFact_Tests method test_35.
/**
* Test 35.
*/
@Test
@Order(35)
void test_35() {
try {
source = IntelligentGraphRepository.create(workingRep);
source.removeGraph("<http://inova8.com/calc2graph/contextGraph>");
Graph graph = source.addGraph("<http://inova8.com/calc2graph/contextGraph>");
Thing myCountry = graph.getThing(":Country1");
myCountry.addFact(":time", "_customQueryOptions.get(\"time\") ;", SCRIPT.GROOVY);
CustomQueryOptions customQueryOptions = new CustomQueryOptions();
customQueryOptions.add("time", 42);
customQueryOptions.add("name", "Peter");
Thing myCountry1 = graph.getThing(":Country1");
Resource result = myCountry1.getFact("<http://inova8.com/calc2graph/def/time>", customQueryOptions);
assertEquals("42", result.stringValue());
} catch (Exception e) {
assertEquals("", e.getMessage());
e.printStackTrace();
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Local_GetFact_Tests method test_36.
/**
* Test 36.
*/
@Test
@Order(36)
void test_36() {
try {
source = IntelligentGraphRepository.create(workingRep);
source.removeGraph("<http://inova8.com/calc2graph/contextGraph>");
Graph graph = source.addGraph("<http://inova8.com/calc2graph/contextGraph>");
Thing myCountry = graph.getThing(":Country1");
myCountry.addFact(":time", "_customQueryOptions.get(\"time\") ;", SCRIPT.GROOVY);
Literal time = literal(42);
Literal time1 = literal(41);
CustomQueryOptions customQueryOptions = new CustomQueryOptions();
customQueryOptions.add("time", time);
Thing myCountry1 = graph.getThing(":Country1");
Resource result = myCountry1.getFact("<http://inova8.com/calc2graph/def/time>[eq %1; gt %2]", customQueryOptions, time, time1);
assertEquals("42", result.stringValue());
result = myCountry1.getFact("<http://inova8.com/calc2graph/def/time>[eq %1; gt %2]", customQueryOptions, time);
assertEquals("42", result.stringValue());
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PlantDemoTests method plantIIoTDemo_PathQL.
/**
* Plant I io T demo path QL.
*/
@Test
@Order(2)
void plantIIoTDemo_PathQL() {
try {
source.removeGraph("<http://inova8.com/intelligentgraph/plantdemo/>");
Graph graph = source.openGraph("<http://inova8.com/intelligentgraph/plantdemo/>");
Thing unit4 = graph.getThing(":Unit.4");
Thing feed41 = graph.getThing(":Feed.4.1");
Thing product41 = graph.getThing(":Product.4.1");
Thing product42 = graph.getThing(":Product.4.2");
Thing flare41 = graph.getThing(":Flare.4.1");
unit4.addFact(":hasFeed", feed41.addFact(":hasVolumeFlow", "_this.getSignal(\"<SEEQ://localhost:34216/api/signals/C8BB6BE4-1CC7-4803-B785-C383ACC31572>\", _customQueryOptions).doubleValue()", SCRIPT.GROOVY).addFact(":hasDensity", "0.85", XSD.DOUBLE));
unit4.addFact(":hasProduct", product41.addFact(":hasVolumeFlow", "_this.getSignal(\"<SEEQ://localhost:34216/api/signals/1C6EE32D-25D3-4C20-AACD-7C8B2BF44D4F>\", _customQueryOptions).doubleValue()", SCRIPT.GROOVY).addFact(":hasDensity", "0.55", XSD.DOUBLE));
unit4.addFact(":hasProduct", product42.addFact(":hasVolumeFlow", "_this.getSignal(\"<SEEQ://localhost:34216/api/signals/FF64D48B-B680-43E2-878F-17EA0E8DA3AA>\", _customQueryOptions).doubleValue()", SCRIPT.GROOVY).addFact(":hasDensity", "0.91", XSD.DOUBLE));
unit4.addFact(":hasProduct", flare41.addFact(":hasVolumeFlow", "_this.getSignal(\"<SEEQ://localhost:34216/api/signals/88A59116-DA7E-467E-B83F-7D2E130ED64D>\", _customQueryOptions).doubleValue()", SCRIPT.GROOVY).addFact(":hasDensity", "0.10", XSD.DOUBLE));
@SuppressWarnings("unused") Thing massFlow = graph.getThing(":MassFlow").addFact("<http://inova8.com/script/scriptCode>", "_this.getFact(':hasVolumeFlow', _customQueryOptions).doubleValue()* _this.getFact(':hasDensity', _customQueryOptions).doubleValue();", SCRIPT.GROOVY);
for (com.inova8.intelligentgraph.model.Resource stream : unit4.getFacts(":hasProduct|:hasFeed")) {
stream.addFact(":hasMassFlow", "<:MassFlow>", SCRIPT.GROOVY);
}
unit4.addFact(":totalProduction", "var totalProduction=_this.getFacts(':hasProduct/:hasMassFlow', _customQueryOptions).total(); return totalProduction; ", SCRIPT.GROOVY);
unit4.addFact(":totalFeed", "var totalFeed= _this.getFacts(':hasFeed/:hasMassFlow', _customQueryOptions).total(); return totalFeed ", SCRIPT.GROOVY);
unit4.addFact(":massBalance", "_this.getFact(':totalProduction', _customQueryOptions).doubleValue()-_this.getFact(':totalFeed', _customQueryOptions).doubleValue() ", SCRIPT.GROOVY);
unit4.addFact(":massBalanceRatio", "_this.getFact(':massBalance', _customQueryOptions).doubleValue()/_this.getFact(':totalFeed', _customQueryOptions).doubleValue() ", SCRIPT.GROOVY);
CustomQueryOptions customQueryOptions = new CustomQueryOptions();
customQueryOptions.add("end", literal("2021-08-02T10:00:00Z", XSD.DATETIMESTAMP));
assertEquals(42.778, feed41.getFact(":hasVolumeFlow", customQueryOptions).doubleValue());
assertEquals(27.165, product41.getFact(":hasVolumeFlow", customQueryOptions).doubleValue());
assertEquals(23.918333333333333, product42.getFact(":hasVolumeFlow", customQueryOptions).doubleValue());
assertEquals(0.40631, flare41.getFact(":hasVolumeFlow", customQueryOptions).doubleValue());
assertEquals(36.747064333333334, unit4.getFact(":totalProduction", customQueryOptions).doubleValue());
assertEquals(36.3613, unit4.getFact(":totalFeed", customQueryOptions).doubleValue());
assertEquals(0.38576433333333426, unit4.getFact(":massBalance", customQueryOptions).doubleValue());
assertEquals(0.010609200807818594, unit4.getFact(":massBalanceRatio", customQueryOptions).doubleValue());
@SuppressWarnings("unused") Thing massYield = graph.getThing(":MassYield").addFact("<http://inova8.com/script/scriptCode>", "_this.getFact(':hasMassFlow', _customQueryOptions).doubleValue()/ _this.getFact('^:hasProduct/:totalProduction', _customQueryOptions).doubleValue();", SCRIPT.GROOVY);
for (com.inova8.intelligentgraph.model.Resource product : unit4.getFacts(":hasProduct")) {
product.addFact(":hasMassYield", "<:MassYield>", SCRIPT.GROOVY);
}
assertEquals(0.4065834991462765, product41.getFact(":hasMassYield", customQueryOptions).doubleValue());
String result = Query.runQuery(conn, "PREFIX plantdemo: <http://inova8.com/intelligentgraph/plantdemo/>\r\n" + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#/>\r\n" + "SELECT ?g ?s ?p ?o ?end {VALUES(?s){(plantdemo:Feed.4.1)(plantdemo:Product.4.1)(plantdemo:Product.4.2)(plantdemo:Flare.4.1)} \r\n" + " VALUES(?p){(plantdemo:hasVolumeFlow)} \r\n" + " VALUES(?end){(\"2021-08-02T10:00:00Z\"^^xsd:dateTimeStamp)(\"2021-08-03T10:00:00Z\"^^xsd:dateTimeStamp)}\r\n" + " graph ?g {?s ?p ?o}}");
assertEquals("p=http://inova8.com/intelligentgraph/plantdemo/hasVolumeFlow;s=http://inova8.com/intelligentgraph/plantdemo/Feed.4.1;g=http://inova8.com/intelligentgraph/plantdemo/;end=2021-08-02T10:00:00Z;o=42.778;\r\n" + "p=http://inova8.com/intelligentgraph/plantdemo/hasVolumeFlow;s=http://inova8.com/intelligentgraph/plantdemo/Feed.4.1;g=http://inova8.com/intelligentgraph/plantdemo/;end=2021-08-03T10:00:00Z;o=42.431666666666665;\r\n" + "p=http://inova8.com/intelligentgraph/plantdemo/hasVolumeFlow;s=http://inova8.com/intelligentgraph/plantdemo/Product.4.1;g=http://inova8.com/intelligentgraph/plantdemo/;end=2021-08-02T10:00:00Z;o=27.165;\r\n" + "p=http://inova8.com/intelligentgraph/plantdemo/hasVolumeFlow;s=http://inova8.com/intelligentgraph/plantdemo/Product.4.1;g=http://inova8.com/intelligentgraph/plantdemo/;end=2021-08-03T10:00:00Z;o=27.136666666666667;\r\n" + "p=http://inova8.com/intelligentgraph/plantdemo/hasVolumeFlow;s=http://inova8.com/intelligentgraph/plantdemo/Product.4.2;g=http://inova8.com/intelligentgraph/plantdemo/;end=2021-08-02T10:00:00Z;o=23.918333333333333;\r\n" + "p=http://inova8.com/intelligentgraph/plantdemo/hasVolumeFlow;s=http://inova8.com/intelligentgraph/plantdemo/Product.4.2;g=http://inova8.com/intelligentgraph/plantdemo/;end=2021-08-03T10:00:00Z;o=24.605333333333334;\r\n" + "p=http://inova8.com/intelligentgraph/plantdemo/hasVolumeFlow;s=http://inova8.com/intelligentgraph/plantdemo/Flare.4.1;g=http://inova8.com/intelligentgraph/plantdemo/;end=2021-08-02T10:00:00Z;o=0.40631;\r\n" + "p=http://inova8.com/intelligentgraph/plantdemo/hasVolumeFlow;s=http://inova8.com/intelligentgraph/plantdemo/Flare.4.1;g=http://inova8.com/intelligentgraph/plantdemo/;end=2021-08-03T10:00:00Z;o=0.3337;\r\n" + "", result);
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
Aggregations