Search in sources :

Example 26 with IntelligentGraphRepository

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());
    }
}
Also used : Repository(org.eclipse.rdf4j.repository.Repository) RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Resource(com.inova8.intelligentgraph.model.Resource) Thing(com.inova8.intelligentgraph.model.Thing) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 27 with IntelligentGraphRepository

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());
    }
}
Also used : IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Resource(com.inova8.intelligentgraph.model.Resource) Thing(com.inova8.intelligentgraph.model.Thing) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 28 with IntelligentGraphRepository

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());
    }
}
Also used : IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Thing(com.inova8.intelligentgraph.model.Thing) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 29 with IntelligentGraphRepository

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());
    }
}
Also used : IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Thing(com.inova8.intelligentgraph.model.Thing) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 30 with IntelligentGraphRepository

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());
    }
}
Also used : IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Resource(com.inova8.intelligentgraph.model.Resource) Thing(com.inova8.intelligentgraph.model.Thing) ResourceResults(com.inova8.intelligentgraph.results.ResourceResults) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Aggregations

IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)37 Thing (com.inova8.intelligentgraph.model.Thing)36 Order (org.junit.jupiter.api.Order)24 Test (org.junit.jupiter.api.Test)24 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)24 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)20 Resource (com.inova8.intelligentgraph.model.Resource)15 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)11 IRI (org.eclipse.rdf4j.model.IRI)9 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)9 Repository (org.eclipse.rdf4j.repository.Repository)8 EvaluationContext (com.inova8.intelligentgraph.evaluator.EvaluationContext)7 ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)7 Trace (com.inova8.intelligentgraph.evaluator.Trace)6 Value (org.eclipse.rdf4j.model.Value)5 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)5 ValueExprEvaluationException (org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException)5 PathElement (com.inova8.pathql.element.PathElement)4 SimpleLiteral (org.eclipse.rdf4j.model.impl.SimpleLiteral)4 BindingSet (org.eclipse.rdf4j.query.BindingSet)4