use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository 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 pathIteration the path iteration
* @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, Integer pathIteration, Resource... contexts) throws IllegalArgumentException, QueryEvaluationException {
CustomQueryOptions customQueryOptions = CustomQueryOption.getCustomQueryOptions(contexts, source.getRepositoryContext().getPrefixes());
TupleExpr tupleExpr = pathElement.pathPatternQuery(pathIteration, customQueryOptions).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;
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method addFact.
/**
* Adds the fact.
*
* @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(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(reification, RDF.TYPE, predicateElement.getReification(), contexts);
super.addStatement(reification, reificationType.getReificationSubject(), thing.getIRI(), contexts);
super.addStatement(reification, reificationType.getReificationPredicate(), predicateElement.getPredicate(), contexts);
super.addStatement(reification, reificationType.getReificationObject(), value, contexts);
} else {
logger.error("Reified type not supported:" + predicateElement.toString());
}
} else {
IRI propertyIri = predicateElement.getPredicate();
super.addStatement(thing.getIRI(), propertyIri, value, contexts);
checkReificationsChanged(propertyIri);
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method prepareCustomQueryOptions.
/**
* Prepare custom query options.
*
* @param pathElement the path element
* @param source the source
* @param contexts the contexts
* @return the custom query options
*/
private CustomQueryOptions prepareCustomQueryOptions(PathElement pathElement, IntelligentGraphRepository source, Resource... contexts) {
// TODOgetPrefixes());
CustomQueryOptions customQueryOptions = CustomQueryOption.getCustomQueryOptions(contexts, source.getRepositoryContext().getPrefixes());
CustomQueryOptions pathQLCustomQueryOptions = pathElement.getCustomQueryOptions();
if (pathQLCustomQueryOptions != null) {
pathQLCustomQueryOptions.addInherited(customQueryOptions);
customQueryOptions = pathQLCustomQueryOptions;
}
return customQueryOptions;
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method create.
/**
* Creates the.
*
* @param intelligentGraphConnection the intelligent graph connection
* @return the intelligent graph repository
*/
public static IntelligentGraphRepository create(IntelligentGraphConnection intelligentGraphConnection) {
IntelligentGraphSail sail = intelligentGraphConnection.getIntelligentGraphSail();
Integer key = sail.hashCode();
if (pathQLRepositories.containsKey(key)) {
return pathQLRepositories.get(key);
} else {
IntelligentGraphRepository pathQLRepository = new IntelligentGraphRepository(intelligentGraphConnection);
pathQLRepositories.put(key, pathQLRepository);
return pathQLRepository;
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Sources method getSource.
/**
* Gets the source.
*
* @param tripleSource the triple source
* @param args the args
* @return the source
*/
public IntelligentGraphRepository getSource(TripleSource tripleSource, Value[] args) {
Integer cacheHash;
if (args.length > 0) {
cacheHash = locateCachHashArgument(args);
if (cacheHash == null)
cacheHash = tripleSource.hashCode();
} else {
cacheHash = tripleSource.hashCode();
}
IntelligentGraphRepository source;
if (!sources.containsKey(cacheHash)) {
source = IntelligentGraphRepository.create(tripleSource);
sources.put(cacheHash, source);
logger.error("Failed to locate hash <{}>, new source created <{}>", locateCachHashArgument(args), cacheHash);
} else {
source = sources.get(cacheHash);
// Need to ensure we are using the latest triplesource, which changes even though from same triplestore
source.setTripleSource(tripleSource);
}
return source;
}
Aggregations