Search in sources :

Example 46 with Thing

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

the class Local_SPARQL_Tests method ig_80.

/**
 * Ig 80.
 */
@Test
@Order(80)
void ig_80() {
    try {
        Thing myCountry = addGraph4();
        String averageSalesScript = "return _this.getFacts(\"<http://inova8.com/calc2graph/def/sales>\").average();";
        myCountry.addFact(":averageSales", averageSalesScript, SCRIPT.GROOVY);
        conn.setNamespace("", "http://inova8.com/calc2graph/def/");
        conn.setNamespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
        String queryString1 = "PREFIX : <http://inova8.com/calc2graph/def/> select ?s ?o " + "FROM <http://inova8.com/calc2graph/testGraph4>\r\n" + // + "FROM <file://calc2graph.def.ttl>\r\n"
        "{\r\n" + "  ?s  :averageSales  ?o } limit 10";
        String result = Query.runSPARQL(conn, queryString1);
        assertEquals("s=http://inova8.com/calc2graph/def/Country;o=300.0;\r\n" + "", result);
    } catch (Exception e) {
        assertEquals("", e.getMessage());
        e.printStackTrace();
    }
}
Also used : Thing(com.inova8.intelligentgraph.model.Thing) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 47 with Thing

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

the class Local_SPARQL_Tests 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/testGraph2>");
    Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph2>");
    Thing myCountry = graph.getThing(":Country");
    myCountry.addFact(":sales", "1");
    myCountry.addFact(":sales", "2");
    myCountry.addFact(":sales", "3");
    myCountry.addFact(":sales", "4");
    myCountry.addFact(":sales", "5");
    // myCountry.addFact(":sales", "60");
    return myCountry;
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Thing(com.inova8.intelligentgraph.model.Thing)

Example 48 with Thing

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

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

use of com.inova8.intelligentgraph.model.Thing 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)

Aggregations

Thing (com.inova8.intelligentgraph.model.Thing)211 Order (org.junit.jupiter.api.Order)189 Test (org.junit.jupiter.api.Test)189 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)189 Resource (com.inova8.intelligentgraph.model.Resource)112 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)45 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)36 ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)33 PathResults (com.inova8.intelligentgraph.results.PathResults)29 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)20 IRI (org.eclipse.rdf4j.model.IRI)13 Value (org.eclipse.rdf4j.model.Value)13 Path (com.inova8.intelligentgraph.path.Path)11 PathPatternException (com.inova8.pathql.processor.PathPatternException)11 RecognitionException (org.antlr.v4.runtime.RecognitionException)11 Trace (com.inova8.intelligentgraph.evaluator.Trace)10 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)9 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)9 EvaluationContext (com.inova8.intelligentgraph.evaluator.EvaluationContext)8 SimpleLiteral (org.eclipse.rdf4j.model.impl.SimpleLiteral)8