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();
}
}
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();
}
}
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());
}
}
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();
}
}
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());
}
}
}
Aggregations