Search in sources :

Example 41 with ResourceResults

use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Thing method getFact.

// public  Resource getFact(IRI predicate, SimpleLiteral scriptString, CustomQueryOptions customQueryOptions, org.eclipse.rdf4j.model.Resource ... contexts) throws HandledException {
// Resource fact = processFactObjectValue(predicate,scriptString,  customQueryOptions ,contexts);
// return fact;
/**
 * Gets the fact.
 *
 * @param predicatePattern the predicate pattern
 * @param customQueryOptions the custom query options
 * @param bindValues the bind values
 * @return the fact
 */
// }
public Resource getFact(String predicatePattern, CustomQueryOptions customQueryOptions, Value... bindValues) {
    logger.debug("getFact{}\n", predicatePattern);
    ResourceResults factValues = getFacts(predicatePattern, customQueryOptions, bindValues);
    if (factValues == null) {
        throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s, customQueryOptions %s, and bind variables %s", predicatePattern, this, customQueryOptions, bindValues));
    } else if (factValues.hasNext()) {
        return factValues.next();
    } else {
        factValues.close();
        throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s, customQueryOptions %s, and bind variables %s", predicatePattern, this, customQueryOptions, bindValues));
    }
}
Also used : NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) ResourceResults(com.inova8.intelligentgraph.results.ResourceResults)

Example 42 with ResourceResults

use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Local_MultiGraphAddGetFact_Tests method test_50.

/**
 * Test 50.
 */
@Test
@Order(50)
void test_50() {
    try {
        Graph graph = source.openGraph("<http://inova8.com/calc2graph/testGraph5>");
        Thing myCountry = graph.getThing(":Country");
        String performanceCalculation = "2*3";
        myCountry.addFact(":Attribute@:salesPerformance", performanceCalculation, SCRIPT.GROOVY);
        ResourceResults results = myCountry.getFacts(":Attribute@:salesPerformance");
        for (Resource result : results) {
            assertEquals("6", result.getValue().stringValue());
            break;
        }
        source.removeGraph("<http://inova8.com/calc2graph/testGraph5>");
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) Resource(com.inova8.intelligentgraph.model.Resource) Thing(com.inova8.intelligentgraph.model.Thing) ResourceResults(com.inova8.intelligentgraph.results.ResourceResults) 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 43 with ResourceResults

use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Local_AddGetDeleteFact_Test method ig_0.

/**
 * Ig 0.
 */
@Test
@Order(0)
void ig_0() {
    try {
        IntelligentGraphRepository source = IntelligentGraphRepository.create(workingRep);
        source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
        Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph1>");
        Thing myCountry = graph.getThing(":Country1");
        myCountry.addFact(":sales", "1");
        myCountry.addFact(":sales", "2");
        myCountry.addFact(":sales", "3");
        myCountry.addFact(":sales", "4");
        ResourceResults facts = myCountry.getFacts(":sales[ge '2';lt '4']");
        Integer factsinrange = facts.count();
        assertEquals(2, factsinrange);
        // myCountry = graph.getThing(":Country1");////////////////////////////////////////////////////
        myCountry.deleteFacts(":sales[eq '3']");
        factsinrange = myCountry.getFacts(":sales[ge '2';lt '4']").count();
        assertEquals(1, factsinrange);
        // Boolean closed =source.closeGraph("<http://inova8.com/calc2graph/testGraph1>");
        source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
    // assertEquals(true, closed);
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) Graph(com.inova8.intelligentgraph.intelligentGraphRepository.Graph) 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 44 with ResourceResults

use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Local_GetFact_Tests method test_28.

/**
 * Test 28.
 */
@Test
@Order(28)
void test_28() {
    try {
        Thing _this = source.getThing(iri("http://inova8.com/calc2graph/id/BatteryLimit1"), null);
        ResourceResults results = _this.getFacts("(:Attribute@:density  |:density)");
        for (Resource result : results) {
            assertEquals(".42", result.stringValue());
        }
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : 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 45 with ResourceResults

use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Local_GetPath_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)

Aggregations

ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)46 Order (org.junit.jupiter.api.Order)42 Test (org.junit.jupiter.api.Test)42 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)42 Thing (com.inova8.intelligentgraph.model.Thing)33 Resource (com.inova8.intelligentgraph.model.Resource)23 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)12 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)7 ArrayList (java.util.ArrayList)7 NullValueReturnedException (com.inova8.intelligentgraph.exceptions.NullValueReturnedException)4 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)3 Path (com.inova8.intelligentgraph.path.Path)3 PathResults (com.inova8.intelligentgraph.results.PathResults)3 Trace (com.inova8.intelligentgraph.evaluator.Trace)2 ResourceStatementResults (com.inova8.intelligentgraph.results.ResourceStatementResults)2 PathPatternException (com.inova8.pathql.processor.PathPatternException)2 RecognitionException (org.antlr.v4.runtime.RecognitionException)2 IRI (org.eclipse.rdf4j.model.IRI)2 Statement (org.eclipse.rdf4j.model.Statement)2 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)2