Search in sources :

Example 46 with Graph

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

Example 47 with Graph

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

the class Remote_GettingStartedTests method test_50.

/**
 * Test 50.
 */
@Test
@Order(50)
void test_50() {
    try {
        IntelligentGraphRepository source = IntelligentGraphRepository.create("http://localhost:8080/rdf4j-server", "tutorial");
        source.prefix("<http://inova8.com/calc2graph/testGraph5/>");
        Graph graph = source.openGraph("<http://inova8.com/calc2graph/testGraph5>");
        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);
        Thing myCountry = graph.getThing(":Country1");
        String performanceCalculation = "2*3";
        myCountry.addFact(":Attribute@:salesPerformance", performanceCalculation, SCRIPT.GROOVY);
        ResourceResults results = myCountry.getFacts(":Attribute@:salesPerformance");
        // if(results.hasNext()) {
        for (Resource result : results) {
            assertEquals("6", result.getValue().stringValue());
            break;
        }
        // source.removeGraph("<http://inova8.com/calc2graph/testGraph>");
        source.closeGraph("<http://inova8.com/calc2graph/testGraph5>");
    // }else {
    // fail();
    // }
    } 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)

Example 48 with Graph

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

the class Remote_PathQL_GetFactTests method test_31.

/**
 * Test 31.
 */
@Test
@Order(31)
void test_31() {
    try {
        source.removeGraph("<http://inova8.com/calc2graph/testGraph>");
        Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph>");
        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++}; return totalSales/count;";
        myCountry.addFact(":averageSales", averageSalesScript, SCRIPT.GROOVY);
        Value averageCountrySales = myCountry.getFact(":averageSales").getValue();
        assertEquals("3.0", averageCountrySales.stringValue());
    } catch (Exception e) {
        fail();
    }
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Value(org.eclipse.rdf4j.model.Value) 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 49 with Graph

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

the class Remote_PathQL_GetFactTests method test_32.

/**
 * Test 32.
 */
@Test
@Order(32)
void test_32() {
    try {
        source.removeGraph("<http://inova8.com/calc2graph/testGraph>");
        Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph>");
        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 totalSalesScript = "return $this.getFacts(\":sales\").total();";
        myCountry.addFact(":totalSales", totalSalesScript, SCRIPT.GROOVY);
        Value totalCountrySales = myCountry.getFact(":totalSales").getValue();
        assertEquals("15.0", totalCountrySales.stringValue());
    } catch (Exception e) {
        fail();
    }
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Value(org.eclipse.rdf4j.model.Value) 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 50 with Graph

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

the class Remote_PathQL_MultiGraphTests method test_30.

/**
 * Test 30.
 */
@Test
@Order(30)
void test_30() {
    try {
        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) {
        fail();
    }
}
Also used : 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