Search in sources :

Example 16 with Graph

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

the class Local_Sparql_IntelligentGraphTests method addGraph2.

/**
 * Adds the graph 2.
 *
 * @return the thing
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
private Thing addGraph2() throws RecognitionException, PathPatternException {
    source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph2>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph3>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph4>");
    Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph2>");
    Thing myCountry = graph.getThing(":Country2");
    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/def/sales>\")){totalSales +=  sales.doubleValue();count++}; return totalSales/count;";
    myCountry.addFact(":averageSales", averageSalesScript, SCRIPT.GROOVY);
    return myCountry;
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Thing(com.inova8.intelligentgraph.model.Thing)

Example 17 with Graph

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

the class Local_Sparql_IntelligentGraphTests method addGraph4.

/**
 * Adds the graph 4.
 *
 * @return the thing
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
private Thing addGraph4() throws RecognitionException, PathPatternException {
    source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph2>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph3>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph4>");
    Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph4>");
    Thing myCountry = graph.getThing(":Country4");
    myCountry.addFact(":sales", "100");
    myCountry.addFact(":sales", "200");
    myCountry.addFact(":sales", "300");
    myCountry.addFact(":sales", "400");
    myCountry.addFact(":sales", "500");
    String averageSalesScript = "return _this.getFacts(\":sales\").average();";
    myCountry.addFact(":averageSales", averageSalesScript, SCRIPT.GROOVY);
    return myCountry;
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Thing(com.inova8.intelligentgraph.model.Thing)

Example 18 with Graph

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

the class Local_Sparql_IntelligentGraphTests method addGraph3.

/**
 * Adds the graph 3.
 *
 * @return the thing
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
private Thing addGraph3() throws RecognitionException, PathPatternException {
    source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph2>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph3>");
    source.removeGraph("<http://inova8.com/calc2graph/testGraph4>");
    Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph3>");
    Thing myCountry = graph.getThing(":Country3");
    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);
    return myCountry;
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Thing(com.inova8.intelligentgraph.model.Thing)

Example 19 with Graph

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

the class Local_GetFact_Tests method test_35.

/**
 * Test 35.
 */
@Test
@Order(35)
void test_35() {
    try {
        source = IntelligentGraphRepository.create(workingRep);
        source.removeGraph("<http://inova8.com/calc2graph/contextGraph>");
        Graph graph = source.addGraph("<http://inova8.com/calc2graph/contextGraph>");
        Thing myCountry = graph.getThing(":Country1");
        myCountry.addFact(":time", "_customQueryOptions.get(\"time\") ;", SCRIPT.GROOVY);
        CustomQueryOptions customQueryOptions = new CustomQueryOptions();
        customQueryOptions.add("time", 42);
        customQueryOptions.add("name", "Peter");
        Thing myCountry1 = graph.getThing(":Country1");
        Resource result = myCountry1.getFact("<http://inova8.com/calc2graph/def/time>", customQueryOptions);
        assertEquals("42", result.stringValue());
    } catch (Exception e) {
        assertEquals("", e.getMessage());
        e.printStackTrace();
    }
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) 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 20 with Graph

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

the class Local_GetFact_Tests method test_36.

/**
 * Test 36.
 */
@Test
@Order(36)
void test_36() {
    try {
        source = IntelligentGraphRepository.create(workingRep);
        source.removeGraph("<http://inova8.com/calc2graph/contextGraph>");
        Graph graph = source.addGraph("<http://inova8.com/calc2graph/contextGraph>");
        Thing myCountry = graph.getThing(":Country1");
        myCountry.addFact(":time", "_customQueryOptions.get(\"time\") ;", SCRIPT.GROOVY);
        Literal time = literal(42);
        Literal time1 = literal(41);
        CustomQueryOptions customQueryOptions = new CustomQueryOptions();
        customQueryOptions.add("time", time);
        Thing myCountry1 = graph.getThing(":Country1");
        Resource result = myCountry1.getFact("<http://inova8.com/calc2graph/def/time>[eq %1; gt %2]", customQueryOptions, time, time1);
        assertEquals("42", result.stringValue());
        result = myCountry1.getFact("<http://inova8.com/calc2graph/def/time>[eq %1; gt %2]", customQueryOptions, time);
        assertEquals("42", result.stringValue());
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) Literal(org.eclipse.rdf4j.model.Literal) 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

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