Search in sources :

Example 86 with Resource

use of com.inova8.intelligentgraph.model.Resource in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Local_TutorialTests method test_5.

/**
 * Test 5.
 */
@SuppressWarnings("resource")
@Test
@Order(5)
void test_5() {
    try {
        org.eclipse.rdf4j.repository.Repository workingRep = Query.createNativeLuceneIntelligentGraphRepository("src/test/resources/datadir/Local_TutorialTests5/");
        RepositoryConnection conn = workingRep.getConnection();
        conn.setNamespace("", "http://inova8.com/intelligentgraph/example5/");
        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/example5>");
        Graph graph = source.addGraph("<http://inova8.com/intelligentgraph/example5>");
        @SuppressWarnings("unused") Thing Person = graph.getThing(":Person");
        Thing aPerson = graph.getThing(":aPerson");
        Thing Measurement = graph.getThing(":Measurement");
        graph.getThing(":aPerson_Measurement_1").addFact(RDF.TYPE, Measurement).addFact(":hasHeight", "1.7", XSD.DOUBLE).addFact(":hasWeight", "62", XSD.DOUBLE).addFact(":hasDate", "2021-08-01", XSD.DATE).addFact(":measurementOf", aPerson);
        graph.getThing(":aPerson_Measurement_2").addFact(RDF.TYPE, Measurement).addFact(":hasHeight", "1.65", XSD.DOUBLE).addFact(":hasWeight", "60", XSD.DOUBLE).addFact(":hasDate", "2021-08-02", XSD.DATE).addFact(":measurementOf", aPerson);
        graph.getThing(":aPerson_Measurement_3").addFact(RDF.TYPE, Measurement).addFact(":hasHeight", "1.7", XSD.DOUBLE).addFact(":hasWeight", "65", XSD.DOUBLE).addFact(":hasDate", "2021-08-03", XSD.DATE).addFact(":measurementOf", aPerson);
        graph.getThing(":aPerson_Measurement_4").addFact(RDF.TYPE, Measurement).addFact(":hasHeight", "1.7", XSD.DOUBLE).addFact(":hasWeight", "57", XSD.DOUBLE).addFact(":hasDate", "2021-08-04", XSD.DATE).addFact(":measurementOf", aPerson);
        graph.getThing(":aPerson_Measurement_5").addFact(RDF.TYPE, Measurement).addFact(":hasHeight", "1.75", XSD.DOUBLE).addFact(":hasWeight", "61", XSD.DOUBLE).addFact(":hasDate", "2021-08-05", XSD.DATE).addFact(":measurementOf", aPerson);
        graph.getThing(":aPerson_Measurement_6").addFact(RDF.TYPE, Measurement).addFact(":hasHeight", "1.75", XSD.DOUBLE).addFact(":hasWeight", "63", XSD.DOUBLE).addFact(":hasDate", "2021-08-06", XSD.DATE).addFact(":measurementOf", aPerson);
        @SuppressWarnings("unused") Thing BMI = graph.getThing(":BMI").addFact(SCRIPT.SCRIPTCODE, "height=_this.getFact(':hasHeight').doubleValue(); _this.getFact(':hasWeight').doubleValue()/(height*height)", SCRIPT.GROOVY);
        for (Resource measurement : graph.getThing(":Measurement").getFacts("^rdf:type")) {
            ((Thing) measurement).addFact(":hasBMI", "<:BMI>", SCRIPT.GROOVY);
        }
        assertEquals("[ {s=http://inova8.com/intelligentgraph/example5/aPerson_Measurement_1, p=http://inova8.com/intelligentgraph/example5/hasBMI, o=\"21.453287197231838\"^^<http://www.w3.org/2001/XMLSchema#double>}; {s=http://inova8.com/intelligentgraph/example5/aPerson_Measurement_2, p=http://inova8.com/intelligentgraph/example5/hasBMI, o=\"22.03856749311295\"^^<http://www.w3.org/2001/XMLSchema#double>}; {s=http://inova8.com/intelligentgraph/example5/aPerson_Measurement_3, p=http://inova8.com/intelligentgraph/example5/hasBMI, o=\"22.49134948096886\"^^<http://www.w3.org/2001/XMLSchema#double>}; {s=http://inova8.com/intelligentgraph/example5/aPerson_Measurement_4, p=http://inova8.com/intelligentgraph/example5/hasBMI, o=\"19.723183391003463\"^^<http://www.w3.org/2001/XMLSchema#double>}; {s=http://inova8.com/intelligentgraph/example5/aPerson_Measurement_5, p=http://inova8.com/intelligentgraph/example5/hasBMI, o=\"19.918367346938776\"^^<http://www.w3.org/2001/XMLSchema#double>}; {s=http://inova8.com/intelligentgraph/example5/aPerson_Measurement_6, p=http://inova8.com/intelligentgraph/example5/hasBMI, o=\"20.571428571428573\"^^<http://www.w3.org/2001/XMLSchema#double>};]", graph.getThing(":aPerson").getFacts("^:measurementOf/:hasBMI").toString());
        assertEquals("22.03856749311295", graph.getThing(":aPerson").getFact("^:measurementOf[:hasDate %1]/:hasBMI", literal(LocalDate.parse("2021-08-02"))).stringValue());
        assertEquals("21.453287197231838", graph.getThing(":aPerson").getFact("^:measurementOf[:hasDate [lt %1]]/:hasBMI", literal(LocalDate.parse("2021-08-03"))).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 87 with Resource

use of com.inova8.intelligentgraph.model.Resource 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 88 with Resource

use of com.inova8.intelligentgraph.model.Resource in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Example4_Tests method example4_1.

/**
 * Example 4 1.
 */
@Test
@Order(1)
void example4_1() {
    try {
        Thing person = source.getThing(":Person");
        ResourceResults persons = person.getFacts("^rdf:type[:hasLocation :Tideswell  ; :hasGender :Male ]");
        // ResourceResults persons = person.getFacts("^rdf:type[:hasLocation :Tideswell ]");
        ArrayList<String> personValues = new ArrayList<String>();
        for (Resource person1 : persons) {
            personValues.add(person1.getValue().stringValue());
        }
        assertEquals("[http://inova8.com/intelligentgraph/example4/Another1, http://inova8.com/intelligentgraph/example4/Another11, http://inova8.com/intelligentgraph/example4/aPerson]", personValues.toString());
    } catch (Exception e) {
        assertEquals("", e.getMessage());
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) 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)

Example 89 with Resource

use of com.inova8.intelligentgraph.model.Resource in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Example4_Tests method example4_91.

@Test
@Order(9)
void example4_91() {
    try {
        Resource fact = source.getFact("[ a owl:Class; eq :Gender]/^a/*");
        assertEquals(" {s=http://inova8.com/intelligentgraph/example4/Male, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type, o=http://inova8.com/intelligentgraph/example4/Gender}", fact.toString());
    } catch (Exception e) {
        assertEquals("", e.getCause().getMessage());
    }
}
Also used : Resource(com.inova8.intelligentgraph.model.Resource) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 90 with Resource

use of com.inova8.intelligentgraph.model.Resource in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Example5_Tests method example5_2.

/**
 * Example 5 2.
 */
@Test
@Order(2)
void example5_2() {
    try {
        Thing aPerson_Measurement = source.getThing(":aPerson_Measurement_2");
        Resource bmi = aPerson_Measurement.getFact(":hasBMI");
        assertEquals("22.03856749311295", bmi.stringValue());
    } catch (Exception e) {
        fail();
        e.printStackTrace();
    }
}
Also used : 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)

Aggregations

Resource (com.inova8.intelligentgraph.model.Resource)140 Order (org.junit.jupiter.api.Order)135 Test (org.junit.jupiter.api.Test)135 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)135 Thing (com.inova8.intelligentgraph.model.Thing)113 ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)26 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)20 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)19 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)11 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)9 PathPatternException (com.inova8.pathql.processor.PathPatternException)8 RecognitionException (org.antlr.v4.runtime.RecognitionException)8 ArrayList (java.util.ArrayList)7 IRI (org.eclipse.rdf4j.model.IRI)7 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)7 Repository (org.eclipse.rdf4j.repository.Repository)6 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)6 NullValueReturnedException (com.inova8.intelligentgraph.exceptions.NullValueReturnedException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 BindingSet (org.eclipse.rdf4j.query.BindingSet)5