use of com.inova8.intelligentgraph.context.CustomQueryOptions 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));
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions 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));
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentEvaluator method processFactObjectValue.
/**
* Process fact object value.
*
* @param thing the thing
* @param predicate the predicate
* @param objectValue the object value
* @param customQueryOptions the custom query options
* @param contexts the contexts
* @return the resource
* @throws QueryEvaluationException the query evaluation exception
*/
public static Resource processFactObjectValue(Thing thing, IRI predicate, Value objectValue, CustomQueryOptions customQueryOptions, org.eclipse.rdf4j.model.Resource... contexts) throws QueryEvaluationException {
Resource returnResult = null;
SimpleLiteral literalValue;
{
literalValue = (SimpleLiteral) objectValue;
if (Evaluator.isScriptEngine(literalValue.getDatatype())) {
org.eclipse.rdf4j.model.Resource customQueryOptionsContext;
if (customQueryOptions != null)
customQueryOptionsContext = customQueryOptions.getContext();
else
customQueryOptionsContext = CustomQueryOptions.getEmptyContext();
FactCache factCache = thing.getSource().getIntelligentGraphConnection().getIntelligentGraphSail().getFactCache();
if (/*notTracing() && */
factCache.contains(thing.getIRI(), predicate, customQueryOptionsContext)) {
Value resultValue = factCache.getFacts(thing.getIRI(), predicate, customQueryOptionsContext);
logger.debug("Retrieved cache {} of {} = {}", predicate.stringValue(), thing.getSuperValue().stringValue(), resultValue.stringValue());
thing.getEvaluationContext().getTracer().traceRetrievedCache(thing, predicate, resultValue);
returnResult = Resource.create(thing.getSource(), resultValue, thing.getEvaluationContext());
} else {
Resource result = handleScript(thing, literalValue, predicate, customQueryOptions, contexts);
if (result != null) {
// TODO validate caching
factCache.addFact(thing.getIRI(), predicate, result.getSuperValue(), customQueryOptionsContext);
thing.getEvaluationContext().getTracer().traceCalculated(thing, predicate, result);
}
returnResult = result;
}
} else {
thing.getEvaluationContext().getTracer().traceRetrievedLiteral(thing, predicate, objectValue);
returnResult = Resource.create(thing.getSource(), objectValue, thing.getEvaluationContext());
}
}
return returnResult;
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Thing method getPaths.
/**
* Gets the paths.
*
* @param predicatePattern the predicate pattern
* @param customQueryOptions the custom query options
* @return the paths
*/
public PathResults getPaths(String predicatePattern, CustomQueryOptions customQueryOptions) {
logger.debug("getPaths{}\n", predicatePattern);
this.getEvaluationContext().getTracer().tracePaths(this, predicatePattern);
SimpleDataset dataset = IntelligentGraphRepository.getDataset(customQueryOptions);
dataset.addDefaultGraph(this.graphName);
org.eclipse.rdf4j.model.Resource[] contextArray = dataset.getDefaultGraphs().toArray(new org.eclipse.rdf4j.model.Resource[0]);
PathResults results = null;
IRI predicate = IntelligentGraphRepository.preparePredicate(PATHQL.getPaths, predicatePattern);
if (this.getSource().getRepository() == null) {
CloseableIteration<? extends Statement, QueryEvaluationException> localPathIterator = this.getSource().getTripleSource().getStatements(this.getIRI(), predicate, null, contextArray);
results = new PathResults(localPathIterator, this, null);
} else {
CloseableIteration<Statement, RepositoryException> pathIterator = this.getSource().getRepository().getConnection().getStatements(this.getIRI(), predicate, null, contextArray);
results = new PathResults(pathIterator, this, null, customQueryOptions);
}
return results;
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class CustomQueryOptions method create.
/**
* Creates the.
*
* @param bindValues the bind values
* @return the custom query options
*/
public static CustomQueryOptions create(Value... bindValues) {
if (bindValues.length > 0) {
CustomQueryOptions customQueryOptions = new CustomQueryOptions();
for (Integer bindIndex = 1; bindIndex <= bindValues.length; bindIndex++) {
Value bindValue = bindValues[bindIndex - 1];
if (bindValue.isLiteral())
// ((Literal)bindValue).getSuperValue());
customQueryOptions.add(bindIndex.toString(), bindValue);
else if (bindValue.isIRI())
customQueryOptions.add(bindIndex.toString(), ((Thing) bindValue).getIRI());
else
customQueryOptions.add(bindIndex.toString(), bindValue);
}
return customQueryOptions;
} else
return null;
}
Aggregations