use of com.inova8.intelligentgraph.model.Resource in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method addFact.
/**
* Adds the fact.
*
* @param modify the modify
* @param thingresource the thingresource
* @param pathQL the path QL
* @param value the value
* @param contexts the contexts
* @throws RecognitionException the recognition exception
* @throws PathPatternException the path pattern exception
*/
private void addFact(UpdateContext modify, Resource thingresource, String pathQL, Value value, Resource... contexts) throws RecognitionException, PathPatternException {
IntelligentGraphRepository source = IntelligentGraphRepository.create(this);
Thing thing = Thing.create(source, thingresource, null);
PredicateElement predicateElement = (PredicateElement) PathParser.parsePathPattern(source.getRepositoryContext(), pathQL);
predicateElement.getSourceVariable().setValue(thing.getValue());
if (predicateElement.getIsReified()) {
ReificationType reificationType = source.getRepositoryContext().getReificationTypes().get(predicateElement.getReification().stringValue());
if (reificationType != null) {
IRI reification = iri(reificationType.getReificationType().stringValue() + "/" + thing.getIRI().hashCode() + "." + predicateElement.getPredicate().hashCode() + "." + value.hashCode());
super.addStatement(modify, reification, RDF.TYPE, predicateElement.getReification(), contexts);
super.addStatement(modify, reification, reificationType.getReificationSubject(), thing.getIRI(), contexts);
super.addStatement(modify, reification, reificationType.getReificationPredicate(), predicateElement.getPredicate(), contexts);
super.addStatement(modify, reification, reificationType.getReificationObject(), value, contexts);
} else {
logger.error("Reified type not supported:" + predicateElement.toString());
}
} else {
IRI propertyIri = predicateElement.getPredicate();
super.addStatement(modify, thing.getIRI(), propertyIri, value, contexts);
checkReificationsChanged(propertyIri);
}
}
use of com.inova8.intelligentgraph.model.Resource in project com.inova8.intelligentgraph by peterjohnlawrence.
the class ResourceStatementResults method next.
/**
* Next.
*
* @return the resource
* @throws QueryEvaluationException the query evaluation exception
*/
@Override
public Resource next() throws QueryEvaluationException {
if (statementSet != null) {
Statement next = getStatementSet().next();
// return Resource.create(thing.getSource(), next.getObject(), getEvaluationContext());
// Resource predicate, Boolean direction, IRI reification, Boolean isDereified,
Resource subject = Resource.create(getSource(), next.getSubject(), getEvaluationContext());
Predicate predicate;
try {
predicate = new Predicate(next.getPredicate());
} catch (URISyntaxException e) {
throw new QueryEvaluationException(e);
}
if (getEvaluationContext() != null)
getEvaluationContext().getTracer().traceFactNext(thing, predicate, next.getObject());
return Resource.create(getSource(), subject, predicate, next.getObject(), getEvaluationContext());
}
if (localStatementIterator != null) {
Statement next = localStatementIterator.next();
return Resource.create(getSource(), next.getObject(), getEvaluationContext());
}
return null;
}
use of com.inova8.intelligentgraph.model.Resource 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.Resource 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.Resource in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method getStatements.
/**
* Gets the statements.
*
* @param subj the subj
* @param pred the pred
* @param obj the obj
* @param includeInferred the include inferred
* @param contexts the contexts
* @return the statements
* @throws SailException the sail exception
*/
@Override
public CloseableIteration<? extends IntelligentStatement, SailException> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws SailException {
try {
Resource[] extendedContexts = contexts;
if (pred != null && !pred.stringValue().equals(SCRIPT.isprivate)) {
extendedContexts = getContexts(contexts);
}
String[] predicateParts;
if (pred != null) {
predicateParts = decodePredicate(pred);
switch(predicateParts[0]) {
case PATHQL.getFact:
case PATHQL.getFacts:
return getFacts(subj, decodePathQL(predicateParts, obj), obj, extendedContexts);
case PATHQL.getPath:
case PATHQL.getPaths:
return getPaths(subj, decodePathQL(predicateParts, obj), obj, extendedContexts);
case PATHQL.traceFact:
case PATHQL.traceFacts:
return traceFacts(subj, decodePathQL(predicateParts, obj), obj, extendedContexts);
case PATHQL.clearCache:
return clearCache(subj, pred, obj, extendedContexts);
case PATHQL.getScript:
return getScript(subj, decodePathQL(predicateParts, obj), obj, extendedContexts);
default:
return new IntelligentGraphStatementsIterator(super.getStatements(subj, pred, obj, includeInferred, extendedContexts), intelligentGraphSail, this, extendedContexts);
}
} else {
return new IntelligentGraphStatementsIterator(super.getStatements(subj, pred, obj, includeInferred, extendedContexts), intelligentGraphSail, this, extendedContexts);
}
} catch (Exception e) {
throw new SailException(e.getMessage(), e);
}
}
Aggregations