use of com.inova8.intelligentgraph.evaluator.Trace in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Example1_Tests method example1_1.
/**
* Example 1 1.
*/
@Test
@Order(1)
void example1_1() {
try {
Thing aPerson = source.getThing(":aPerson");
Trace trace = aPerson.traceFact(":hasBMI");
assertEquals(" 1. Getting facts ':hasBMI' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson>\n" + " 2. ...within contexts: [http://default, file://src/test/resources/example1.ttl]\n" + " 1. Evaluating predicate hasBMI <http://inova8.com/intelligentgraph/example1/hasBMI> of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> , by invoking groovy script\n" + " 2. double height=_this.getFact(':hasHeight').doubleValue(); _this.getFact(':hasWeight').doubleValue()/(height*height)\n" + "\n" + " 1. Getting facts ':hasHeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson>\n" + " 2. Next fact 'http://inova8.com/intelligentgraph/example1/hasHeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 1.7\n" + " 3. Returned fact ':hasHeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 1.7^^decimal <http://www.w3.org/2001/XMLSchema#decimal>\n" + "\n" + " 4. Getting facts ':hasWeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson>\n" + " 5. Next fact 'http://inova8.com/intelligentgraph/example1/hasWeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 62\n" + " 6. Returned fact ':hasWeight' of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 62^^decimal <http://www.w3.org/2001/XMLSchema#decimal>\n" + "\n" + " 3. Evaluated hasBMI <http://inova8.com/intelligentgraph/example1/hasBMI> of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>\n" + " 3. Calculated hasBMI <http://inova8.com/intelligentgraph/example1/hasBMI> of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>\n" + " 4. Retrieved cached value hasBMI <http://inova8.com/intelligentgraph/example1/hasBMI> of aPerson <http://inova8.com/intelligentgraph/example1/aPerson> = 21.453287197231838^^double <http://www.w3.org/2001/XMLSchema#double>\n" + " 5. Returned fact 'http://inova8.com/intelligentgraph/example1/hasBMI' of aPerson <http://inova8.com/intelligentgraph/example1/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.evaluator.Trace 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.evaluator.Trace 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.evaluator.Trace 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());
}
}
}
use of com.inova8.intelligentgraph.evaluator.Trace in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentStatementResults method next.
/**
* Next.
*
* @return the intelligent statement
* @throws QueryEvaluationException the query evaluation exception
*/
@SuppressWarnings("deprecation")
@Override
public IntelligentStatement next() throws QueryEvaluationException {
BindingSet nextBindingset = getResultsIterator().next();
Binding subjBinding = nextBindingset.getBinding(subj);
Binding predBinding = StatementBinding.getAlternatePredicateBinding(nextBindingset, predicateVariable);
Binding objBinding = nextBindingset.getBinding(obj);
if (subjBinding != null && predBinding != null && objBinding != null) {
IRI parameterizedPredicate;
try {
parameterizedPredicate = this.pathElement.getParameterizedPredicate((IRI) predBinding.getValue());
} catch (URISyntaxException e) {
parameterizedPredicate = (IRI) predBinding.getValue();
}
Value subjectValue;
if (subjBinding != null)
subjectValue = subjBinding.getValue();
else
subjectValue = nextBindingset.getBinding(this.boundVariableName).getValue();
if (trace && this.evaluationContext != null) {
thing.getEvaluationContext().getTracer().traceFactReturnValue(thing, predBinding.getValue().stringValue(), objBinding.getValue());
return new IntelligentStatement((ContextStatement) simpleValueFactory.createStatement((Resource) subjectValue, parameterizedPredicate, literal(thing.getEvaluationContext().getTrace()), null), null, this.evaluationContext, customQueryOptions);
} else {
return new IntelligentStatement((ContextStatement) simpleValueFactory.createStatement((Resource) subjectValue, parameterizedPredicate, objBinding.getValue(), null), source, this.evaluationContext, customQueryOptions);
}
} else
return new IntelligentStatement(null, null, null);
}
Aggregations