Search in sources :

Example 21 with Resource

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

the class Local_BoundFact_Tests method test_24.

/**
 * Test 24.
 */
@Test
@Order(24)
void test_24() {
    try {
        Resource result = source.getFact("[eq <http://inova8.com/calc2graph/id/Unit2>]/:massThroughput");
        assertEquals("37.99999952316284", result.stringValue());
    } catch (Exception e) {
        assertEquals("", e.getMessage());
        e.printStackTrace();
    }
}
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 22 with Resource

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

the class Local_BoundPath_Tests method test_7.

/**
 * Test 7.
 */
@Test
@Order(7)
void test_7() {
    try {
        Thing _this = source.getThing(iri("http://inova8.com/calc2graph/id/Equipment_1"), null);
        ResourceResults results = _this.getFacts(":connectedTo{1,3}");
        ArrayList<String> resultsArrayList = new ArrayList<String>();
        for (Resource result : results) {
            resultsArrayList.add(result.stringValue());
        }
        assertEquals("[http://inova8.com/calc2graph/id/Equipment_2, http://inova8.com/calc2graph/id/Equipment_2_1, http://inova8.com/calc2graph/id/Equipment_3, http://inova8.com/calc2graph/id/Equipment_2_2, http://inova8.com/calc2graph/id/Equipment_4, http://inova8.com/calc2graph/id/Equipment_2_3]", resultsArrayList.toString());
        PathResults paths = _this.getPaths(":connectedTo{1,3}");
        ArrayList<String> pathArrayList = new ArrayList<String>();
        for (Path path : paths) {
            pathArrayList.add(path.toString());
        }
        assertEquals("[Path=[[http://inova8.com/calc2graph/id/Equipment_1,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_2,DIRECT]\r\n" + "]\r\n" + ", Path=[[http://inova8.com/calc2graph/id/Equipment_1,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_2_1,DIRECT]\r\n" + "]\r\n" + ", Path=[[http://inova8.com/calc2graph/id/Equipment_1,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_2,DIRECT]\r\n" + "[http://inova8.com/calc2graph/id/Equipment_2,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_3,DIRECT]\r\n" + "]\r\n" + ", Path=[[http://inova8.com/calc2graph/id/Equipment_1,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_2_1,DIRECT]\r\n" + "[http://inova8.com/calc2graph/id/Equipment_2_1,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_2_2,DIRECT]\r\n" + "]\r\n" + ", Path=[[http://inova8.com/calc2graph/id/Equipment_1,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_2,DIRECT]\r\n" + "[http://inova8.com/calc2graph/id/Equipment_2,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_3,DIRECT]\r\n" + "[http://inova8.com/calc2graph/id/Equipment_3,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_4,DIRECT]\r\n" + "]\r\n" + ", Path=[[http://inova8.com/calc2graph/id/Equipment_1,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_2_1,DIRECT]\r\n" + "[http://inova8.com/calc2graph/id/Equipment_2_1,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_2_2,DIRECT]\r\n" + "[http://inova8.com/calc2graph/id/Equipment_2_2,http://inova8.com/calc2graph/def/connectedTo,http://inova8.com/calc2graph/id/Equipment_2_3,DIRECT]\r\n" + "]\r\n" + "]", pathArrayList.toString());
    } catch (Exception e) {
        assertEquals("", e.getCause().getMessage());
        e.printStackTrace();
    }
}
Also used : Path(com.inova8.intelligentgraph.path.Path) ArrayList(java.util.ArrayList) Resource(com.inova8.intelligentgraph.model.Resource) PathResults(com.inova8.intelligentgraph.results.PathResults) 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 23 with Resource

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

the class Local_GetContextFact_Tests method test_2.

/**
 * Test 2.
 */
@Test
@Order(2)
void test_2() {
    try {
        IntelligentGraphRepository source = IntelligentGraphRepository.create(workingRep);
        source.removeGraph("<http://inova8.com/calc2graph/contextGraph>");
        Graph graph = source.addGraph("<http://inova8.com/calc2graph/contextGraph>");
        Thing myCountry = graph.getThing(":myCountry");
        myCountry.addFact(":myOption", "_customQueryOptions.get(\"time\").integerValue() ;", SCRIPT.GROOVY);
        CustomQueryOptions customQueryOptions1 = new CustomQueryOptions();
        customQueryOptions1.add("time", 42);
        customQueryOptions1.add("name", "Peter");
        Thing myCountry1 = graph.getThing(":myCountry");
        Trace result = myCountry1.traceFact("<http://inova8.com/calc2graph/def/myOption>", customQueryOptions1);
        Query.assertEqualsWOSpaces("<olstyle='list-style-type:none;'><li>Gettingfacts'&lt;http://inova8.com/calc2graph/def/myOption&gt;'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a></li></li><li>...usingoptions:[name=&quot;Peter&quot;&amp;time=&quot;42&quot;^^&lt;http://www.w3.org/2001/XMLSchema#int&gt;]</li></li><li>...withincontexts:[file://src/test/resources/calc2graph.def.ttl,http://inova8.com/calc2graph/contextGraph,file://src/test/resources/calc2graph.data.ttl]</li></li><olstyle='list-style-type:none;'><li>Evaluatingpredicate<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>,byinvoking<b>groovy</b>script</li></li><li><divstyle='border:1pxsolidblack;'><pre><code>_customQueryOptions.get(&quot;time&quot;).integerValue();</code></pre></div></li><olstyle='list-style-type:none;'></ol><li>Evaluated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li></ol><li>Calculated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Retrievedcachedvalue<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Returnedfact'http://inova8.com/calc2graph/def/myOption'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><p></ol>", result.asHTML());
        CustomQueryOptions customQueryOptions2 = new CustomQueryOptions();
        customQueryOptions2.add("time", 43);
        result = myCountry1.traceFact("<http://inova8.com/calc2graph/def/myOption>", customQueryOptions2);
        Query.assertEqualsWOSpaces("<olstyle='list-style-type:none;'><li>Gettingfacts'&lt;http://inova8.com/calc2graph/def/myOption&gt;'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a></li></li><li>...usingoptions:[time=&quot;43&quot;^^&lt;http://www.w3.org/2001/XMLSchema#int&gt;]</li></li><li>...withincontexts:[file://src/test/resources/calc2graph.def.ttl,http://inova8.com/calc2graph/contextGraph,file://src/test/resources/calc2graph.data.ttl]</li></li><olstyle='list-style-type:none;'><li>Evaluatingpredicate<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>,byinvoking<b>groovy</b>script</li></li><li><divstyle='border:1pxsolidblack;'><pre><code>_customQueryOptions.get(&quot;time&quot;).integerValue();</code></pre></div></li><olstyle='list-style-type:none;'></ol><li>Evaluated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=43^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li></ol><li>Calculated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=43^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Retrievedcachedvalue<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=43^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Returnedfact'http://inova8.com/calc2graph/def/myOption'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=43^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><p></ol>", result.asHTML());
        result = myCountry1.traceFact("<http://inova8.com/calc2graph/def/myOption>&time='2019'^^xsd:int");
        Query.assertEqualsWOSpaces("<olstyle='list-style-type:none;'><li>Gettingfacts'&lt;http://inova8.com/calc2graph/def/myOption&gt;&amp;time='2019'^^xsd:int'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a></li></li><li>...withincontexts:[file://src/test/resources/calc2graph.def.ttl,http://inova8.com/calc2graph/contextGraph,file://src/test/resources/calc2graph.data.ttl]</li></li><olstyle='list-style-type:none;'><li>Evaluatingpredicate<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>,byinvoking<b>groovy</b>script</li></li><li><divstyle='border:1pxsolidblack;'><pre><code>_customQueryOptions.get(&quot;time&quot;).integerValue();</code></pre></div></li><olstyle='list-style-type:none;'></ol><li>Evaluated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=2019^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li></ol><li>Calculated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=2019^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Retrievedcachedvalue<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=2019^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Returnedfact'http://inova8.com/calc2graph/def/myOption'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=2019^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><p></ol>", result.asHTML());
        ResourceResults results = myCountry1.getFacts("<http://inova8.com/calc2graph/def/myOption>&time='2020'^^xsd:int");
        for (Resource result1 : results) {
            Query.assertEqualsWOSpaces("2020", result1.stringValue());
        }
    } catch (Exception e) {
        assertEquals("", e.getMessage());
        e.printStackTrace();
    }
}
Also used : Trace(com.inova8.intelligentgraph.evaluator.Trace) IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) 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 24 with Resource

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

the class Local_AddGetDeleteFact_Test method ig_1.

/**
 * Ig 1.
 */
@Test
@Order(1)
void ig_1() {
    try {
        IntelligentGraphRepository source = IntelligentGraphRepository.create(workingRep);
        source.removeGraph("<http://inova8.com/calc2graph/testGraph2>");
        Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph2>");
        Thing myCountry = graph.getThing(":Country2");
        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);
        // double totalSales = 0;
        // int count = 0;
        // for(Resource sales : myCountry.getFacts(":Attribute@:sales")){
        // totalSales +=  sales.doubleValue();
        // count++;
        // };
        // double averagesales= totalSales/count;
        String averageSalesScript = "totalSales=0; count=0;for(sales in _this.getFacts(\":Attribute@:sales\")){totalSales +=  sales.doubleValue();count++}; return totalSales/count;";
        myCountry.addFact(":averageSales", averageSalesScript, SCRIPT.GROOVY);
        Resource averageSales = myCountry.getFact(":averageSales");
        assertEquals(2.3333333333333335, averageSales.doubleValue());
        // Thing country3= myCountry.getThing(":Country3");
        Thing country3 = graph.getThing(":Country3");
        String averageSalesScript3 = "totalSales=0; count=0; myCountry=_this.getThing(\":Country2\"); for(sales in myCountry.getFacts(\":Attribute@:sales\")){totalSales +=  sales.doubleValue();count++}; return totalSales/count;";
        country3.addFact(":averageSales", averageSalesScript3, SCRIPT.GROOVY);
        Resource averageSales3 = myCountry.getFact(":averageSales");
        assertEquals(2.3333333333333335, averageSales3.doubleValue());
        Boolean closed = source.closeGraph("<http://inova8.com/calc2graph/testGraph2>");
        assertEquals(true, closed);
    } 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 25 with Resource

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

the class Local_BoundFact_Tests method test_26.

/**
 * Test 26.
 */
@Test
@Order(26)
void test_26() {
    try {
        Resource result = source.getFact("[eq <http://inova8.com/calc2graph/id/Unit3>]/:massThroughput");
        assertEquals("24.77999922633171", result.stringValue());
    } catch (Exception e) {
        assertEquals("", e.getMessage());
        e.printStackTrace();
    }
}
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)

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