Search in sources :

Example 41 with Graph

use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph 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 42 with Graph

use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Remote_CRUD_Test method ig_1.

/**
 * Ig 1.
 */
@Test
@Order(1)
void ig_1() {
    try {
        source.removeGraph("<http://inova8.com/calc2graph/testGraph2>");
        Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph2>");
        source.prefix("<http://inova8.com/calc2graph/testGraph2/>");
        Thing myCountry = graph.getThing(":Country2");
        Thing Attribute = graph.getThing(":Attribute").addFact(RDFS.SUBCLASSOF, RDF.STATEMENT);
        Thing AttributeType = graph.getThing(":AttributeType");
        graph.getThing(":attributeOf").addFact(RDFS.SUB_PROPERTY_OF, RDF.SUBJECT).addFact(RDFS.DOMAIN, Attribute).addFact(RDFS.RANGE, RDFS.RESOURCE);
        graph.getThing(":attributeType").addFact(RDFS.SUB_PROPERTY_OF, RDF.PREDICATE).addFact(RDFS.DOMAIN, Attribute).addFact(RDFS.RANGE, AttributeType);
        graph.getThing(":attributeMeasurement").addFact(RDFS.SUB_PROPERTY_OF, RDF.OBJECT).addFact(RDFS.DOMAIN, Attribute).addFact(RDFS.RANGE, XSD.STRING);
        myCountry.addFact(":Attribute@:sales", "1");
        myCountry.addFact(":Attribute@:sales", "2");
        myCountry.addFact(":Attribute@:sales", "3");
        myCountry.addFact(":Attribute@:sales", "4");
        ResourceResults facts = myCountry.getFacts(":Attribute@:sales[ge '2';lt '4']");
        Integer factsinrange = facts.count();
        assertEquals(2, factsinrange);
        myCountry.deleteFacts(":Attribute@:sales[eq '3']");
        facts = myCountry.getFacts(":Attribute@:sales[ge '2';lt '4']");
        factsinrange = facts.count();
        assertEquals(1, factsinrange);
        Boolean closed = source.closeGraph("<http://inova8.com/calc2graph/testGraph2>");
        assertEquals(true, closed);
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) 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)

Example 43 with Graph

use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph 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 44 with Graph

use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph 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 45 with Graph

use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph 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)

Aggregations

Thing (com.inova8.intelligentgraph.model.Thing)53 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)45 Order (org.junit.jupiter.api.Order)44 Test (org.junit.jupiter.api.Test)44 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)44 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)22 Resource (com.inova8.intelligentgraph.model.Resource)22 ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)14 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)13 PathPatternException (com.inova8.pathql.processor.PathPatternException)12 RecognitionException (org.antlr.v4.runtime.RecognitionException)12 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)8 Repository (org.eclipse.rdf4j.repository.Repository)8 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)6 NullValueReturnedException (com.inova8.intelligentgraph.exceptions.NullValueReturnedException)5 ServerException (com.inova8.intelligentgraph.exceptions.ServerException)5 ScriptException (javax.script.ScriptException)5 IRI (org.eclipse.rdf4j.model.IRI)5 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)5 Trace (com.inova8.intelligentgraph.evaluator.Trace)4