use of com.inova8.intelligentgraph.model.Thing in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method traceFacts.
/**
* Trace facts.
*
* @param thingresource the thingresource
* @param pathQLValue the path QL value
* @param contexts the contexts
* @return the closeable iteration<? extends intelligent statement, sail exception>
* @throws PathPatternException the path pattern exception
*/
@SuppressWarnings("deprecation")
private CloseableIteration<? extends IntelligentStatement, SailException> traceFacts(Resource thingresource, String pathQLValue, Value obj, Resource... contexts) throws PathPatternException {
IntelligentGraphRepository source = IntelligentGraphRepository.create(this);
Thing thing = Thing.create(source, thingresource, null);
thing.getEvaluationContext().setTracing(true);
thing.getEvaluationContext().getTracer().clear();
thing.getEvaluationContext().getTracer().traceFacts(thing, pathQLValue, source.getRepositoryContext().getPrefixes(), contexts);
String pathQL = pathQLValue;
PathElement pathElement = PathParser.parsePathPattern(source.getRepositoryContext(), pathQL);
pathElement.getSourceVariable().setValue(thing.getValue());
return traceThingFacts(source, thing, pathElement, contexts);
}
use of com.inova8.intelligentgraph.model.Thing in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method deleteFacts.
/**
* Delete facts.
*
* @param modify the modify
* @param thingresource the thingresource
* @param pathQLValue the path QL value
* @param contexts the contexts
* @throws PathPatternException the path pattern exception
*/
private void deleteFacts(UpdateContext modify, Resource thingresource, String pathQLValue, Value obj, Resource... contexts) throws PathPatternException {
IntelligentGraphRepository source = IntelligentGraphRepository.create(this);
Thing thing = Thing.create(source, thingresource, null);
// TODO toPathQLString(pathQLValue);
String pathQL = pathQLValue;
PathElement pathElement = PathParser.parsePathPattern(source.getRepositoryContext(), pathQL);
pathElement.getSourceVariable().setValue(thing.getValue());
deleteThingFacts(modify, source, thing, pathElement, contexts);
}
use of com.inova8.intelligentgraph.model.Thing in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method getFacts.
/**
* Gets the facts.
*
* @param thingresource the thingresource
* @param pathQLValue the path QL value
* @param contexts the contexts
* @return the facts
* @throws PathPatternException the path pattern exception
*/
private CloseableIteration<? extends IntelligentStatement, SailException> getFacts(Resource thingresource, String pathQLValue, Value obj, Resource... contexts) throws PathPatternException {
IntelligentGraphRepository source = IntelligentGraphRepository.create(this);
String pathQL = pathQLValue;
PathElement pathElement = PathParser.parsePathPattern(source.getRepositoryContext(), pathQL);
Thing thing = null;
if (thingresource != null) {
thing = Thing.create(source, thingresource, null);
pathElement.getSourceVariable().setValue(thing.getValue());
}
return getThingFacts(source, thing, pathElement, contexts);
}
use of com.inova8.intelligentgraph.model.Thing in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method deleteThingFacts.
/**
* Delete thing facts.
*
* @param modify the modify
* @param source the source
* @param thing the thing
* @param pathElement the path element
* @param contexts the contexts
* @throws PathPatternException the path pattern exception
*/
private void deleteThingFacts(UpdateContext modify, IntelligentGraphRepository source, Thing thing, PathElement pathElement, Resource... contexts) throws PathPatternException {
CloseableIteration<BindingSet, QueryEvaluationException> resultsIterator = getResultsIterator(source, thing, pathElement, 0, contexts);
if (((PredicateElement) pathElement).getIsReified()) {
String reified = ((PredicateElement) pathElement).getReifiedVariable().getName();
while (resultsIterator.hasNext()) {
BindingSet bindingSet = resultsIterator.next();
super.removeStatements((Resource) bindingSet.getBinding(reified).getValue(), null, null, contexts);
}
} else {
String subj = pathElement.getTargetSubject().getName();
String pred = pathElement.getTargetPredicate().getName();
String obj = pathElement.getTargetVariable().getName();
while (resultsIterator.hasNext()) {
BindingSet bindingSet = resultsIterator.next();
IRI predicate = (IRI) bindingSet.getBinding(pred).getValue();
super.removeStatements((Resource) bindingSet.getBinding(subj).getValue(), (IRI) bindingSet.getBinding(pred).getValue(), bindingSet.getBinding(obj).getValue(), contexts);
checkReificationsChanged(predicate);
}
}
}
use of com.inova8.intelligentgraph.model.Thing in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method getResultsIterator.
/**
* Gets the results iterator.
*
* @param source the source
* @param thing the thing
* @param pathElement the path element
* @param pathTupleExpr the path tuple expr
* @param contexts the contexts
* @return the results iterator
* @throws IllegalArgumentException the illegal argument exception
* @throws QueryEvaluationException the query evaluation exception
*/
CloseableIteration<BindingSet, QueryEvaluationException> getResultsIterator(IntelligentGraphRepository source, Thing thing, PathElement pathElement, PathTupleExpr pathTupleExpr, Resource... contexts) throws IllegalArgumentException, QueryEvaluationException {
TupleExpr tupleExpr = pathTupleExpr.getTupleExpr();
SimpleDataset dataset = prepareDataset(pathElement, source, contexts);
BindingSet bindings = new QueryBindingSet();
EvaluationStrategy evaluationStrategy = new StrictEvaluationStrategy(source.getTripleSource(), dataset, null);
CloseableIteration<BindingSet, QueryEvaluationException> resultsIterator = evaluationStrategy.evaluate(tupleExpr, bindings);
return resultsIterator;
}
Aggregations