Search in sources :

Example 16 with Fact

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

the class Example5_Tests method example5_7.

/**
 * Example 5 7.
 */
@Test
@Order(7)
void example5_7() {
    try {
        Thing aPerson = source.getThing(":aPerson");
        Trace trace = aPerson.traceFact("^:measurementOf[:hasDate [lt %1]]/:hasBMI", literal(LocalDate.parse("2021-08-03")));
        Query.assertEqualsWOSpaces("   1. Getting facts '^:measurementOf[:hasDate [lt %1]]/:hasBMI' of aPerson <http://inova8.com/intelligentgraph/example5/aPerson>\r\n" + "   2. ...using options: [1=\"2021-08-03\"^^<http://www.w3.org/2001/XMLSchema#date>]\r\n" + "   3. ...within contexts: [file://src/test/resources/example5.ttl, http://default]\r\n" + "   4. Returned fact 'http://inova8.com/intelligentgraph/example5/hasBMI' of aPerson <http://inova8.com/intelligentgraph/example5/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>", trace.asText());
    } catch (Exception e) {
        fail();
        e.printStackTrace();
    }
}
Also used : Trace(com.inova8.intelligentgraph.evaluator.Trace) 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 17 with Fact

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

the class Example6_Tests method example6_7.

/**
 * Example 6 7.
 */
@Test
@Order(7)
void example6_7() {
    try {
        Thing aPerson = source.getThing(":aPerson");
        Trace trace = aPerson.traceFact(":Observation@:BMIObservation[:hasDate [lt %1]]/:hasBMI", literal(LocalDate.parse("2021-08-03")));
        Query.assertEqualsWOSpaces("   1. Getting facts ':Observation@:BMIObservation[:hasDate [lt %1]]/:hasBMI' of aPerson <http://inova8.com/intelligentgraph/example6/aPerson>\r\n" + "   2. ...using options: [1=\"2021-08-03\"^^<http://www.w3.org/2001/XMLSchema#date>]\r\n" + "   3. ...within contexts: [http://default, file://src/test/resources/example6.ttl]\r\n" + "   4. Returned fact 'http://inova8.com/intelligentgraph/example6/hasBMI' of aPerson <http://inova8.com/intelligentgraph/example6/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>", trace.asText());
    } catch (Exception e) {
        assertEquals("", e.getMessage());
        e.printStackTrace();
    }
}
Also used : Trace(com.inova8.intelligentgraph.evaluator.Trace) 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 18 with Fact

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

the class Example4_Tests method example4_91.

@Test
@Order(9)
void example4_91() {
    try {
        Resource fact = source.getFact("[ a owl:Class; eq :Gender]/^a/*");
        assertEquals(" {s=http://inova8.com/intelligentgraph/example4/Male, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type, o=http://inova8.com/intelligentgraph/example4/Gender}", fact.toString());
    } catch (Exception e) {
        assertEquals("", e.getCause().getMessage());
    }
}
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 19 with Fact

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

the class Remote_PathQL_GetFactTests method test_3.

/**
 * Test 3.
 */
@Test
@Order(3)
void test_3() {
    try {
        Thing $this = Thing.create(source, iri("http://inova8.com/calc2graph/id/Unit1"), null);
        Double fact = 0.0;
        for (Resource batterylimit : $this.getFacts(":hasProductBatteryLimit")) {
            @SuppressWarnings("unused") Resource factValue = batterylimit.getFact(":massFlow");
            fact += batterylimit.getFact(":massFlow").doubleValue();
        }
        ResourceResults batterylimits = $this.getFacts(":hasProductBatteryLimit");
        Resource batterylimit;
        while (batterylimits.hasNext()) {
            batterylimit = batterylimits.next();
            fact -= batterylimit.getFact(":massFlow").doubleValue();
        }
        ;
        assertEquals(0.0, fact);
    } catch (Exception e) {
        fail();
        e.printStackTrace();
    }
}
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 20 with Fact

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

the class ObjectProvenance method evaluate.

/**
 * Evaluate.
 *
 * @param tripleSource the triple source
 * @param args the args
 * @return the value
 * @throws ValueExprEvaluationException the value expr evaluation exception
 */
@Override
public Value evaluate(TripleSource tripleSource, Value... args) throws ValueExprEvaluationException {
    logger.trace("Evaluate for <{}> with args <{}>", tripleSource, args);
    if (args.length < 3) {
        String message = "At least subject,predicate, and objectscript arguments required";
        logger.error(message);
        return tripleSource.getValueFactory().createLiteral(message);
    } else {
        IRI subject;
        IRI predicate;
        try {
            subject = (IRI) args[0];
            predicate = (IRI) args[1];
        } catch (Exception e) {
            String message = "Subject and predicate must be valid IRI";
            logger.error(message);
            return tripleSource.getValueFactory().createLiteral(message);
        }
        SimpleLiteral literalValue;
        try {
            literalValue = (SimpleLiteral) args[2];
            if (isScriptEngine(literalValue.getDatatype())) {
                Value[] argumentArray = Arrays.copyOfRange(args, 3, args.length);
                IntelligentGraphRepository source = sources.getSource(tripleSource, argumentArray);
                CustomQueryOptions customQueryOptions = source.getCustomQueryOptions(argumentArray);
                EvaluationContext evaluationContext = new EvaluationContext(customQueryOptions);
                evaluationContext.setTracing(true);
                Thing subjectThing = Thing.create(source, subject, evaluationContext);
                com.inova8.intelligentgraph.model.Resource fact = IntelligentEvaluator.processFactObjectValue(subjectThing, predicate, literalValue, customQueryOptions);
                // TODO com.inova8.intelligentgraph.model.Resource fact = subjectThing.getFact( predicate,literalValue,customQueryOptions);
                if (fact != null) {
                    fact.getValue();
                    logger.debug("Trace\r\n" + evaluationContext.getTrace());
                    return tripleSource.getValueFactory().createLiteral(evaluationContext.getTrace());
                } else {
                    return null;
                }
            } else {
                return args[2];
            }
        } catch (Exception e) {
            return tripleSource.getValueFactory().createLiteral(e.getMessage());
        }
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) ValueExprEvaluationException(org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException) CustomQueryOptions(com.inova8.intelligentgraph.context.CustomQueryOptions) Value(org.eclipse.rdf4j.model.Value) SimpleLiteral(org.eclipse.rdf4j.model.impl.SimpleLiteral) EvaluationContext(com.inova8.intelligentgraph.evaluator.EvaluationContext) Thing(com.inova8.intelligentgraph.model.Thing)

Aggregations

Thing (com.inova8.intelligentgraph.model.Thing)19 Order (org.junit.jupiter.api.Order)11 Test (org.junit.jupiter.api.Test)11 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)11 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)9 Resource (com.inova8.intelligentgraph.model.Resource)8 IRI (org.eclipse.rdf4j.model.IRI)8 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)6 EvaluationContext (com.inova8.intelligentgraph.evaluator.EvaluationContext)6 ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)6 Value (org.eclipse.rdf4j.model.Value)6 SimpleLiteral (org.eclipse.rdf4j.model.impl.SimpleLiteral)6 Trace (com.inova8.intelligentgraph.evaluator.Trace)5 ValueExprEvaluationException (org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException)4 NullValueReturnedException (com.inova8.intelligentgraph.exceptions.NullValueReturnedException)3 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)3 PredicateElement (com.inova8.pathql.element.PredicateElement)3 BindingSet (org.eclipse.rdf4j.query.BindingSet)3 ReificationType (com.inova8.pathql.context.ReificationType)2 NoSuchElementException (java.util.NoSuchElementException)2