use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Remote_PathQL_MultiGraphTests method ig_70.
/**
* Ig 70.
*/
@Test
@Order(70)
void ig_70() {
try {
Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph3>");
Thing myCountry = graph.getThing(":Country1");
myCountry.addFact(":sales", "100");
myCountry.addFact(":sales", "200");
myCountry.addFact(":sales", "300");
myCountry.addFact(":sales", "400");
myCountry.addFact(":sales", "500");
RepositoryConnection conn = source.getRepository().getConnection();
String totalSalesScript = "return _this.getFacts(\"<http://inova8.com/calc2graph/def/sales>\").total();";
myCountry.addFact(":totalSales", totalSalesScript, SCRIPT.GROOVY);
String queryString1 = "PREFIX : <http://inova8.com/calc2graph/def/> select ?s ?o " + "FROM <http://inova8.com/calc2graph/testGraph3>\r\n" + "FROM <http://default>\n" + // + "FROM <file://calc2graph.def.ttl>\r\n"
"{\r\n" + " ?s :totalSales ?o} limit 10";
String result = Query.runSPARQL(conn, queryString1);
assertEquals("s=http://inova8.com/calc2graph/def/Country;o=150.0;", result);
source.removeGraph("<http://inova8.com/calc2graph/testGraph3>");
result = Query.runSPARQL(conn, queryString1);
assertEquals("", result);
} catch (Exception e) {
fail();
e.printStackTrace();
} finally {
source.removeGraph("<http://inova8.com/calc2graph/testGraph3>");
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Remote_CRUD_Test method ig_0.
/**
* Ig 0.
*/
@Test
@Order(0)
void ig_0() {
try {
source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph1>");
source.prefix("<http://inova8.com/calc2graph/testGraph1/>");
Thing myCountry = graph.getThing(":Country1");
myCountry.addFact(":sales", "1");
myCountry.addFact(":sales", "2");
myCountry.addFact(":sales", "3");
myCountry.addFact(":sales", "4");
ResourceResults facts = myCountry.getFacts(":sales[ge '2';lt '4']");
Integer factsinrange = facts.count();
assertEquals(2, factsinrange);
myCountry.deleteFacts(":sales[eq '3']");
factsinrange = myCountry.getFacts(":sales[ge '2';lt '4']").count();
assertEquals(1, factsinrange);
Boolean closed = source.closeGraph("<http://inova8.com/calc2graph/testGraph1>");
assertEquals(true, closed);
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Remote_GettingStartedTests method test_40.
/**
* Test 40.
*/
@Test
@Order(40)
void test_40() {
try {
IntelligentGraphRepository source = IntelligentGraphRepository.create("http://localhost:8080/rdf4j-server", "tutorial");
source.prefix("<http://inova8.com/calc2graph/testGraph4/>");
source.removeGraph("<http://inova8.com/calc2graph/testGraph4>");
Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph4>");
Thing myCountry = graph.getThing(":Country1");
myCountry.addFact(":sales", "100");
myCountry.addFact(":sales", "200");
myCountry.addFact(":sales", "300");
myCountry.addFact(":sales", "400");
myCountry.addFact(":sales", "500");
String averageSalesScript = "return _this.getFacts(\":sales\").average();";
myCountry.addFact(":averageSales", averageSalesScript, SCRIPT.GROOVY);
Double averageCountrySales;
averageCountrySales = myCountry.getFact(":averageSales").doubleValue();
assertEquals(300.0, averageCountrySales);
averageCountrySales = myCountry.getFact(":averageSales").doubleValue();
assertEquals(300.0, averageCountrySales);
myCountry.addFact(":sales", "600");
averageCountrySales = myCountry.getFact(":averageSales").doubleValue();
assertEquals(350, averageCountrySales);
source.closeGraph("<http://inova8.com/calc2graph/testGraph4>");
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Local_TutorialTests method test_1.
/**
* Test 1.
*/
@Test
@Order(1)
void test_1() {
try {
Repository workingRep = Query.createNativeLuceneIntelligentGraphRepository("src/test/resources/datadir/Local_TutorialTests1/");
RepositoryConnection conn = workingRep.getConnection();
conn.setNamespace("", "http://inova8.com/intelligentgraph/example1/");
conn.setNamespace(XSD.PREFIX, XSD.NAMESPACE);
conn.setNamespace(RDF.PREFIX, RDF.NAMESPACE);
conn.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE);
conn.setNamespace(OWL.PREFIX, OWL.NAMESPACE);
IntelligentGraphRepository source = IntelligentGraphRepository.create(workingRep);
source.removeGraph("<http://inova8.com/intelligentgraph/example1>");
Graph graph = source.addGraph("<http://inova8.com/intelligentgraph/example1>");
source.removeGraph("<http://inova8.com/intelligentgraph/example1>");
graph = source.addGraph("<http://inova8.com/intelligentgraph/example1>");
Thing aPerson = graph.getThing(":aPerson");
Thing Person = graph.getThing(":Person");
aPerson.addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.7", XSD.DOUBLE).addFact(":hasWeight", "62", XSD.DOUBLE);
assertEquals("http://inova8.com/intelligentgraph/example1/aPerson", aPerson.stringValue());
aPerson.addFact(":hasBMI", "height=_this.getFact(':hasHeight').doubleValue(); _this.getFact(':hasWeight').doubleValue()/(height*height)", SCRIPT.GROOVY);
assertEquals(" 1. Getting facts ':hasBMI' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson>\n" + " 2. ...within contexts: [http://inova8.com/intelligentgraph/example1]\n" + " 1. Evaluating predicate hasBMI <http://inova8.com/intelligentgraph/example1/hasBMI> of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> , by invoking groovy script\n" + " 2. height=_this.getFact(':hasHeight').doubleValue(); _this.getFact(':hasWeight').doubleValue()/(height*height)\n" + "\n" + " 1. Getting facts ':hasHeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson>\n" + " 2. Next fact 'http://inova8.com/intelligentgraph/example1/hasHeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 1.7\n" + " 3. Returned fact ':hasHeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 1.7^^double <http://www.w3.org/2001/XMLSchema#double>\n" + "\n" + " 4. Getting facts ':hasWeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson>\n" + " 5. Next fact 'http://inova8.com/intelligentgraph/example1/hasWeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 62\n" + " 6. Returned fact ':hasWeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 62^^double <http://www.w3.org/2001/XMLSchema#double>\n" + "\n" + " 3. Evaluated hasBMI <http://inova8.com/intelligentgraph/example1/hasBMI> of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>\n" + " 3. Calculated hasBMI <http://inova8.com/intelligentgraph/example1/hasBMI> of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>\n" + " 4. Retrieved cached value hasBMI <http://inova8.com/intelligentgraph/example1/hasBMI> of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>\n" + " 5. Returned fact 'http://inova8.com/intelligentgraph/example1/hasBMI' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>", aPerson.traceFact(":hasBMI").asText());
assertEquals("21.453287197231838", aPerson.getFact(":hasBMI").stringValue());
assertEquals(" 1. Getting facts ':hasBMI' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson>\n" + " 2. ...within contexts: [http://inova8.com/intelligentgraph/example1]\n" + " 3. Retrieved cached value hasBMI <http://inova8.com/intelligentgraph/example1/hasBMI> of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>\n" + " 4. Retrieved cached value hasBMI <http://inova8.com/intelligentgraph/example1/hasBMI> of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>\n" + " 5. Returned fact 'http://inova8.com/intelligentgraph/example1/hasBMI' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>", aPerson.traceFact(":hasBMI").asText());
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph 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