use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Local_TutorialTests method test_4.
/**
* Test 4.
*/
@SuppressWarnings("resource")
@Test
@Order(4)
void test_4() {
try {
org.eclipse.rdf4j.repository.Repository workingRep = Query.createNativeLuceneIntelligentGraphRepository("src/test/resources/datadir/Local_TutorialTests4/");
RepositoryConnection conn = workingRep.getConnection();
conn.setNamespace("", "http://inova8.com/intelligentgraph/example4/");
conn.setNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
conn.setNamespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
IntelligentGraphRepository source = IntelligentGraphRepository.create(workingRep);
source.removeGraph("<http://inova8.com/intelligentgraph/example4>");
Graph graph = source.addGraph("<http://inova8.com/intelligentgraph/example4>");
Thing Person = graph.getThing(":Person");
@SuppressWarnings("unused") Thing locationAverageBMI = graph.getThing(":LocationAverageBMI").addFact(SCRIPT.SCRIPTCODE, "_this.getFacts('^:hasLocation/:hasBMI')average()", SCRIPT.GROOVY);
@SuppressWarnings("unused") Thing genderLocationAverageBMI = graph.getThing(":Gender_LocationAverageBMI").addFact(SCRIPT.SCRIPTCODE, "gender=_this.getFact(':hasGender');\n" + "location=_this.getFact(':hasLocation');\n" + "location.getFacts('^:hasLocation[:hasGender %1]/:hasBMI',gender).average()", SCRIPT.GROOVY);
Thing Location = graph.getThing(":Location");
Thing Maidstone = graph.getThing(":Maidstone").addFact(RDF.TYPE, Location).addFact(":averageBMI", "<:LocationAverageBMI>", SCRIPT.GROOVY);
Thing Tideswell = graph.getThing(":Tideswell").addFact(RDF.TYPE, Location).addFact(":averageBMI", "<:LocationAverageBMI>", SCRIPT.GROOVY);
Thing Gender = graph.getThing(":Gender");
Thing Male = graph.getThing(":Male").addFact(RDF.TYPE, Gender);
Thing Female = graph.getThing(":Female").addFact(RDF.TYPE, Gender);
graph.getThing(":aPerson").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.7", XSD.DOUBLE).addFact(":hasWeight", "62", XSD.DOUBLE).addFact(":hasLocation", Tideswell).addFact(":hasGender", Male);
graph.getThing(":Another1").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.9", XSD.DOUBLE).addFact(":hasWeight", "72", XSD.DOUBLE).addFact(":hasLocation", Tideswell).addFact(":hasGender", Male);
graph.getThing(":Another2").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.7", XSD.DOUBLE).addFact(":hasWeight", "65", XSD.DOUBLE).addFact(":hasLocation", Maidstone).addFact(":hasGender", Male);
graph.getThing(":Another3").addFact(RDF.TYPE, Person).addFact(":hasHeight", "2", XSD.DOUBLE).addFact(":hasWeight", "59", XSD.DOUBLE).addFact(":hasLocation", Maidstone).addFact(":hasGender", Female);
graph.getThing(":Another4").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.8", XSD.DOUBLE).addFact(":hasWeight", "47", XSD.DOUBLE).addFact(":hasLocation", Maidstone).addFact(":hasGender", Male);
graph.getThing(":Another5").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.5", XSD.DOUBLE).addFact(":hasWeight", "70", XSD.DOUBLE).addFact(":hasLocation", Maidstone).addFact(":hasGender", Female);
graph.getThing(":Another6").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.5", XSD.DOUBLE).addFact(":hasWeight", "56", XSD.DOUBLE).addFact(":hasLocation", Maidstone).addFact(":hasGender", Male);
graph.getThing(":Another7").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.7", XSD.DOUBLE).addFact(":hasWeight", "63", XSD.DOUBLE).addFact(":hasLocation", Maidstone).addFact(":hasGender", Female);
graph.getThing(":Another8").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.6", XSD.DOUBLE).addFact(":hasWeight", "66", XSD.DOUBLE).addFact(":hasLocation", Maidstone).addFact(":hasGender", Male);
graph.getThing(":Another9").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.7", XSD.DOUBLE).addFact(":hasWeight", "46", XSD.DOUBLE).addFact(":hasLocation", Maidstone).addFact(":hasGender", Female);
graph.getThing(":Another10").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.9", XSD.DOUBLE).addFact(":hasWeight", "61", XSD.DOUBLE).addFact(":hasLocation", Tideswell).addFact(":hasGender", Female);
graph.getThing(":Another11").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.5", XSD.DOUBLE).addFact(":hasWeight", "61", XSD.DOUBLE).addFact(":hasLocation", Tideswell).addFact(":hasGender", Male);
graph.getThing(":Another12").addFact(RDF.TYPE, Person).addFact(":hasHeight", "1.8", XSD.DOUBLE).addFact(":hasWeight", "75", XSD.DOUBLE).addFact(":hasLocation", Tideswell).addFact(":hasGender", Female);
@SuppressWarnings("unused") Thing BMI = graph.getThing(":BMI").addFact(SCRIPT.SCRIPTCODE, "height=_this.getFact(':hasHeight').doubleValue(); _this.getFact(':hasWeight').doubleValue()/(height*height)", SCRIPT.GROOVY);
@SuppressWarnings("unused") Thing relativeBMI = graph.getThing(":RelativeBMI").addFact("<http://inova8.com/script/scriptCode>", "double averageBMI = _this.getFact('rdf:type/:averageBMI').doubleValue(); _this.getFact(':hasBMI').doubleValue()/averageBMI;", SCRIPT.GROOVY);
for (Resource person : graph.getThing(":Person").getFacts("^rdf:type")) {
((Thing) person).addFact(":hasBMI", "<:BMI>", SCRIPT.GROOVY).addFact(":hasRelativeBMI", "<:RelativeBMI>", SCRIPT.GROOVY);
}
Person.addFact(":averageBMI", "_this.getFacts('^rdf:type/:hasBMI').average()", SCRIPT.GROOVY);
Thing Gender_Location = graph.getThing(":Gender_Location");
graph.getThing(":Male_Tideswell").addFact(RDF.TYPE, Gender_Location).addFact(":hasGender", Male).addFact(":hasLocation", Tideswell);
graph.getThing(":Female_Tideswell").addFact(RDF.TYPE, Gender_Location).addFact(":hasGender", Female).addFact(":hasLocation", Tideswell);
graph.getThing(":Male_Maidstone").addFact(RDF.TYPE, Gender_Location).addFact(":hasGender", Male).addFact(":hasLocation", Maidstone);
graph.getThing(":Female_Maidstone").addFact(RDF.TYPE, Gender_Location).addFact(":hasGender", Female).addFact(":hasLocation", Maidstone);
for (Resource person : graph.getThing(":Gender_Location").getFacts("^rdf:type")) {
((Thing) person).addFact(":averageBMI", "<:Gender_LocationAverageBMI>", SCRIPT.GROOVY);
}
assertEquals("22.836332215431028", graph.getThing(":Male_Tideswell").getFact(":averageBMI").stringValue());
@SuppressWarnings("unused") Thing genderLocationRelativeBMI = graph.getThing(":GenderLocationRelativeBMI").addFact(SCRIPT.SCRIPTCODE, "BMI=_this.getFact(':hasBMI').doubleValue();\n" + "gender=_this.getFact(':hasGender');\n" + "location=_this.getFact(':hasLocation');\n" + "genderLocationAverageBMI = _this.getThing(':Gender_Location').getFact('^rdf:type[:hasGender %1; :hasLocation %2]/:averageBMI',gender,location).doubleValue();\n" + "BMI/genderLocationAverageBMI;", SCRIPT.GROOVY);
for (Resource person : graph.getThing(":Person").getFacts("^rdf:type")) {
((Thing) person).addFact(":hasGenderLocationRelativeBMI", "<:GenderLocationRelativeBMI>", SCRIPT.GROOVY);
}
assertEquals("0.9394366395990406", graph.getThing(":aPerson").getFact(":hasGenderLocationRelativeBMI").stringValue());
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Remote_GettingStartedTests method test_1.
/**
* Test 1.
*/
@Test
@Order(1)
void test_1() {
try {
IntelligentGraphRepository source = IntelligentGraphRepository.create("http://localhost:8080/rdf4j-server", "tutorial");
source.prefix("<http://inova8.com/calc2graph/testGraph1/>");
source.prefix("rdfs", "<http://www.w3.org/2000/01/rdf-schema#>");
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");
myCountry.addFact(":sales", "5");
String averageSalesScript = "totalSales=0; count=0;for(sales in _this.getFacts(':sales')){totalSales += sales.doubleValue();count++}; if(count==0) return Double.POSITIVE_INFINITY else return totalSales/count;";
myCountry.addFact(":averageSales", averageSalesScript, SCRIPT.GROOVY);
Resource average = myCountry.getFact(":averageSales");
assertEquals("3.0", average.stringValue());
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Remote_GettingStartedTests method test_20.
/**
* Test 20.
*/
@Test
@Order(20)
void test_20() {
try {
IntelligentGraphRepository source = IntelligentGraphRepository.create("http://localhost:8080/rdf4j-server", "tutorial");
source.prefix("<http://inova8.com/calc2graph/testGraph2/>");
source.removeGraph("<http://inova8.com/calc2graph/testGraph2>");
Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph2>");
Thing myCountry = graph.getThing(":Country1");
myCountry.addFact(":sales", "1");
myCountry.addFact(":sales", "2");
myCountry.addFact(":sales", "3");
myCountry.addFact(":sales", "4");
myCountry.addFact(":sales", "5");
myCountry.addFact(":sales", "60");
String averageSalesScript = "totalSales=0; count=0;for(sales in _this.getFacts(\"<http://inova8.com/calc2graph/testGraph2/sales>\")){totalSales += sales.doubleValue();count++}; return totalSales/count;";
myCountry.addFact(":averageSales", averageSalesScript, SCRIPT.GROOVY);
Double averageCountrySales = myCountry.getFact(":averageSales").doubleValue();
assertEquals(12.5, averageCountrySales);
// source.removeGraph("<http://inova8.com/calc2graph/testGraph2>");
source.closeGraph("<http://inova8.com/calc2graph/testGraph2>");
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Remote_GettingStartedTests method test_30.
/**
* Test 30.
*/
@Test
@Order(30)
void test_30() {
try {
IntelligentGraphRepository source = IntelligentGraphRepository.create("http://localhost:8080/rdf4j-server", "tutorial");
source.prefix("<http://inova8.com/calc2graph/testGraph3/>");
source.removeGraph("<http://inova8.com/calc2graph/testGraph3>");
Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph3>");
Thing myCountry = graph.getThing(":Country1");
myCountry.addFact(":sales", "10");
myCountry.addFact(":sales", "20");
myCountry.addFact(":sales", "30");
myCountry.addFact(":sales", "40");
myCountry.addFact(":sales", "50");
String totalSalesScript = "return _this.getFacts(\":sales\").total();";
myCountry.addFact(":totalSales", totalSalesScript, SCRIPT.GROOVY);
Double totalCountrySales = myCountry.getFact(":totalSales").doubleValue();
assertEquals(150.0, totalCountrySales);
source.closeGraph("<http://inova8.com/calc2graph/testGraph3>");
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Remote_GettingStartedTests method test_10.
/**
* Test 10.
*/
@Test
@Order(10)
void test_10() {
try {
IntelligentGraphRepository source = IntelligentGraphRepository.create("http://localhost:8080/rdf4j-server", "tutorial");
source.prefix("<http://inova8.com/calc2graph/testGraph1/>");
Graph graph1 = source.openGraph("<http://inova8.com/calc2graph/testGraph1>");
Thing myCountry = graph1.getThing(":Country1");
String performanceCalculation = "2*3";
myCountry.addFact(":salesPerformance", performanceCalculation, SCRIPT.GROOVY);
ResourceResults results = myCountry.getFacts(":salesPerformance");
for (Resource result : results) {
assertEquals("6", result.getValue().stringValue());
}
// source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
source.closeGraph("<http://inova8.com/calc2graph/testGraph1>");
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
Aggregations