use of com.inova8.intelligentgraph.model 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.model in project com.inova8.intelligentgraph by peterjohnlawrence.
the class ObjectValue 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.debug("Evaluate for <{}> ,{}> with args <{}>", tripleSource, tripleSource.getValueFactory(), 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 = String.format("Subject and predicate must be valid IRI. Subject %s, Object %s", args[0], args[1]);
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);
// sources.getSource(tripleSource, argumentArray );
IntelligentGraphRepository source = IntelligentGraphRepository.create(tripleSource);
CustomQueryOptions customQueryOptions = source.getCustomQueryOptions(argumentArray);
EvaluationContext evaluationContext = new EvaluationContext(customQueryOptions);
// Thing subjectThing = source.thingFactory( null, subject, new Stack<String>(),customQueryOptions);
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) {
Value result = fact.getValue();
// source.writeModelToCache(result, cacheContext);
logger.debug("ObjectValue = {}", result);
return result;
} else {
return null;
}
} else {
return args[2];
}
} catch (Exception e) {
return tripleSource.getValueFactory().createLiteral(e.getMessage());
}
}
}
use of com.inova8.intelligentgraph.model in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method getCustomQueryOptions.
/**
* Gets the custom query options.
*
* @param customQueryOptionsArray the custom query options array
* @return the custom query options
*/
public CustomQueryOptions getCustomQueryOptions(Value[] customQueryOptionsArray) {
CustomQueryOptions customQueryOptions = CustomQueryOptions.create(this, customQueryOptionsArray);
if (customQueryOptions != null) {
if (customQueryOptions.contains("service")) {
com.inova8.intelligentgraph.model.Resource service = customQueryOptions.get("service");
String serviceURL = service.toString();
String serviceIRI = null;
if (serviceURL.indexOf('?') > 0) {
serviceIRI = serviceURL.substring(0, serviceURL.indexOf('?'));
}
if (serviceIRI != null)
setCacheService(serviceIRI);
}
}
return customQueryOptions;
}
use of com.inova8.intelligentgraph.model in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method getFact.
public com.inova8.intelligentgraph.model.Resource getFact(String boundPredicatePattern, CustomQueryOptions customQueryOptions) {
logger.debug("getFact{}\n", boundPredicatePattern);
ResourceResults factValues = getFacts(boundPredicatePattern, customQueryOptions);
if (factValues == null) {
// return new NullResource();
throw new NullValueReturnedException(String.format("No values found for pattern %s with customQueryOptions %s", boundPredicatePattern, customQueryOptions));
} else if (factValues.hasNext()) {
return factValues.next();
} else {
factValues.close();
// return new NullResource();
throw new NullValueReturnedException(String.format("No values found for pattern %s with customQueryOptions %s", boundPredicatePattern, customQueryOptions));
}
}
Aggregations