use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Thing method getFact.
/**
* Gets the fact.
*
* @param predicatePattern the predicate pattern
* @param bindValues the bind values
* @return the fact
*/
public Resource getFact(String predicatePattern, Value... bindValues) {
logger.debug("getFact{}\n", predicatePattern);
// this.getEvaluationContext().getTracer().traceFact(this, predicatePattern);
ResourceResults factValues = getFacts(predicatePattern, bindValues);
if (factValues == null) {
this.getEvaluationContext().getTracer().traceFactReturnNull(this, predicatePattern);
throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s", predicatePattern, this));
} else if (factValues.hasNext()) {
Resource nextFact = factValues.next();
this.getEvaluationContext().getTracer().traceFactReturnValue(this, predicatePattern, nextFact);
return nextFact;
} else {
this.getEvaluationContext().getTracer().traceFactEmpty(this, predicatePattern);
factValues.close();
throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s", predicatePattern, this));
}
}
use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Thing method getFacts.
/**
* Gets the facts.
*
* @param predicatePattern the predicate pattern
* @param customQueryOptions the custom query options
* @return the facts
*/
public ResourceResults getFacts(String predicatePattern, CustomQueryOptions customQueryOptions) {
logger.debug("getFacts{}\n", predicatePattern);
this.getEvaluationContext().getTracer().traceFacts(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]);
ResourceStatementResults results = null;
IRI predicate = IntelligentGraphRepository.preparePredicate(PATHQL.getFacts, predicatePattern);
if (this.getSource().getRepository() == null) {
CloseableIteration<? extends Statement, QueryEvaluationException> localStatementIterator = this.getSource().getTripleSource().getStatements(this.getIRI(), predicate, null, contextArray);
results = new ResourceStatementResults(localStatementIterator, this, null, customQueryOptions);
} else {
CloseableIteration<Statement, RepositoryException> statementIterator = this.getSource().getRepository().getConnection().getStatements(this.getIRI(), predicate, null, contextArray);
results = new ResourceStatementResults(statementIterator, this, null, customQueryOptions);
}
return results;
}
use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Thing method getFact.
/**
* Gets the fact.
*
* @param predicatePattern the predicate pattern
* @param customQueryOptions the custom query options
* @return the fact
*/
public Resource getFact(String predicatePattern, CustomQueryOptions customQueryOptions) {
logger.debug("getFact{}\n", predicatePattern);
ResourceResults factValues = getFacts(predicatePattern, customQueryOptions);
if (factValues == null) {
// return new NullResource();
throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s and customQueryOptions %s", predicatePattern, this, 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 subject %s and customQueryOptions %s", predicatePattern, this, customQueryOptions));
}
}
use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Local_BoundFact_Tests method test_1_1.
@Test
@Order(1_1)
void test_1_1() {
try {
ResourceResults results = source.getFacts(":hasProductBatteryLimit");
assertEquals("[ {s=http://inova8.com/calc2graph/id/Unit1, p=http://inova8.com/calc2graph/def/hasProductBatteryLimit, o=http://inova8.com/calc2graph/id/BatteryLimit2}; {s=http://inova8.com/calc2graph/id/Unit1, p=http://inova8.com/calc2graph/def/hasProductBatteryLimit, o=http://inova8.com/calc2graph/id/BatteryLimit3};]", results.toString());
} catch (Exception e) {
assertEquals("Facts query unbound", e.getMessage());
}
}
use of com.inova8.intelligentgraph.results.ResourceResults in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Local_BoundFact_Tests method test_1_2.
@Test
@Order(1_2)
void test_1_2() {
try {
ResourceResults results = source.getFacts("[eq *]/:hasProductBatteryLimit");
assertEquals("[http://inova8.com/calc2graph/id/BatteryLimit2;http://inova8.com/calc2graph/id/BatteryLimit3;]", results.toString());
} catch (Exception e) {
assertEquals("[line 1:4 in \"[eq *]/:hasProductBatteryLimit\": no viable alternative at input '[eq*']", e.getCause().getMessage());
}
}
Aggregations