use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method prefix.
/**
* Prefix.
*
* @param prefix the prefix
* @param IRI the iri
* @return the intelligent graph repository
*/
public IntelligentGraphRepository prefix(String prefix, String IRI) {
org.eclipse.rdf4j.model.IRI iri = Utilities.trimAndCheckIRIString(IRI);
if (iri != null) {
// } else {
try {
RepositoryConnection connection = this.getRepository().getConnection();
connection.setNamespace(prefix, iri.stringValue());
getRepositoryContext().getPrefixes().put(prefix, iri);
logger.debug("Added prefix {} for namespace {} ", prefix, iri);
} catch (Exception qe) {
throw new ServerException(FAILEDTOREMOVEGRAPH_EXCEPTION, String.format("Failed to add prefix/namespace", prefix, iri), qe);
}
// }
} else {
logger.error("Invalid IRI specified. Ensure enclosed in <...> ", IRI);
}
return this;
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method closeGraph.
/**
* Close graph.
*
* @param graphName the graph name
* @return the boolean
*/
@SuppressWarnings("deprecation")
public Boolean closeGraph(String graphName) {
RepositoryConnection connection = this.getContextAwareConnection();
IRI graphNameIri = null;
try {
graphNameIri = PathParser.parseIriRef(getRepositoryContext(), graphName).getIri();
Boolean contextExists = connection.getContextIDs().asList().contains(graphNameIri);
if (contextExists) {
getPublicContexts().remove(graphNameIri);
return true;
} else {
return false;
}
} catch (Exception qe) {
throw new ServerException(FAILEDTOCLOSEGRAPH_EXCEPTION, String.format("Failed to close graph %s with exception %s", graphName, qe.getMessage()), qe);
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method removeGraph.
/**
* Removes the graph.
*
* @param graphName the graph name
* @return the iri
*/
public IRI removeGraph(String graphName) {
// RepositoryConnection connection = this.getRepository().getConnection();//.getContextAwareConnection();
IRI graphNameIri = null;
try (RepositoryConnection connection = this.getRepository().getConnection()) {
graphNameIri = PathParser.parseIriRef(getRepositoryContext(), graphName).getIri();
@SuppressWarnings("deprecation") Boolean contextExists = connection.getContextIDs().asList().contains(graphNameIri);
if (contextExists) {
Resource[] contexts = { graphNameIri };
// connection.begin(IsolationLevels.SERIALIZABLE);
// connection.clear(graphNameIri);
// connection.clear();
connection.remove((IRI) null, (IRI) null, null, contexts);
// connection.remove(graphNameIri, (IRI) null, null,contexts);//graphNameIri);
// connection.remove((Resource) null, (IRI) null, null);//graphNameIri);
// connection.commit();
logger.debug("Removed graph {} ", graphNameIri.stringValue());
} else {
logger.error("Failed to remove graph {} ", graphNameIri.stringValue());
return null;
// throw new ServerException(FAILEDTOREMOVEGRAPH_EXCEPTION, String.format("Failed to remove graph %s. Does not exist", graphName));
}
} catch (Exception qe) {
throw new ServerException(FAILEDTOREMOVEGRAPH_EXCEPTION, String.format("Failed to remove graph %s", graphName, qe.getMessage()), qe);
}
return graphNameIri;
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphEvaluator method nextGraph.
/**
* Next graph.
*
* @return the binding set
*/
private BindingSet nextGraph() {
BindingSet nextBindingSet = getEvaluator().next();
try {
if (nextBindingSet.hasBinding("subject") && nextBindingSet.hasBinding("predicate") && nextBindingSet.hasBinding("object")) {
if (nextBindingSet.getValue("object").isLiteral()) {
SimpleLiteral literalValue = (SimpleLiteral) (nextBindingSet.getValue("object"));
if (Evaluator.getEngineNames().containsKey(literalValue.getDatatype())) {
QueryBindingSet modifiedBindingSet = new QueryBindingSet();
modifiedBindingSet.addBinding(nextBindingSet.getBinding("subject"));
modifiedBindingSet.addBinding(nextBindingSet.getBinding("predicate"));
IntelligentGraphRepository source = getSource();
EvaluationContext evaluationContext = new EvaluationContext(customQueryOptions, getDataset());
Thing subjectThing = Thing.create(source, nextBindingSet.getValue("subject"), evaluationContext);
try {
// TODOcom.inova8.intelligentgraph.model.Resource fact = subjectThing.getFact( (IRI) nextBindingSet.getValue("predicate"), literalValue,customQueryOptions);
com.inova8.intelligentgraph.model.Resource fact = IntelligentEvaluator.processFactObjectValue(subjectThing, (IRI) nextBindingSet.getValue("predicate"), literalValue, customQueryOptions);
Binding modifiedBindingValue = new SimpleBinding("object", fact.getValue());
modifiedBindingSet.addBinding(modifiedBindingValue);
return modifiedBindingSet;
} catch (Exception e) {
Binding modifiedBindingValue = new SimpleBinding("object", literal(StringEscapeUtils.escapeEcmaScript(e.getMessage())));
// literal(e.getMessage()));
modifiedBindingSet.addBinding(modifiedBindingValue);
return modifiedBindingSet;
}
} else {
return locateCustomQueryOptions(nextBindingSet);
}
} else {
return locateCustomQueryOptions(nextBindingSet);
}
} else {
// Incomplete s p o within dataset so could not calculate
return nextBindingSet;
}
} catch (Exception e) {
// Should not be any exceptions that are not handled, but even so ...
return nextBindingSet;
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Local_GetContextFact_Tests method test_2.
/**
* Test 2.
*/
@Test
@Order(2)
void test_2() {
try {
IntelligentGraphRepository source = IntelligentGraphRepository.create(workingRep);
source.removeGraph("<http://inova8.com/calc2graph/contextGraph>");
Graph graph = source.addGraph("<http://inova8.com/calc2graph/contextGraph>");
Thing myCountry = graph.getThing(":myCountry");
myCountry.addFact(":myOption", "_customQueryOptions.get(\"time\").integerValue() ;", SCRIPT.GROOVY);
CustomQueryOptions customQueryOptions1 = new CustomQueryOptions();
customQueryOptions1.add("time", 42);
customQueryOptions1.add("name", "Peter");
Thing myCountry1 = graph.getThing(":myCountry");
Trace result = myCountry1.traceFact("<http://inova8.com/calc2graph/def/myOption>", customQueryOptions1);
Query.assertEqualsWOSpaces("<olstyle='list-style-type:none;'><li>Gettingfacts'<http://inova8.com/calc2graph/def/myOption>'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a></li></li><li>...usingoptions:[name="Peter"&time="42"^^<http://www.w3.org/2001/XMLSchema#int>]</li></li><li>...withincontexts:[file://src/test/resources/calc2graph.def.ttl,http://inova8.com/calc2graph/contextGraph,file://src/test/resources/calc2graph.data.ttl]</li></li><olstyle='list-style-type:none;'><li>Evaluatingpredicate<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>,byinvoking<b>groovy</b>script</li></li><li><divstyle='border:1pxsolidblack;'><pre><code>_customQueryOptions.get("time").integerValue();</code></pre></div></li><olstyle='list-style-type:none;'></ol><li>Evaluated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li></ol><li>Calculated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Retrievedcachedvalue<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Returnedfact'http://inova8.com/calc2graph/def/myOption'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=42^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><p></ol>", result.asHTML());
CustomQueryOptions customQueryOptions2 = new CustomQueryOptions();
customQueryOptions2.add("time", 43);
result = myCountry1.traceFact("<http://inova8.com/calc2graph/def/myOption>", customQueryOptions2);
Query.assertEqualsWOSpaces("<olstyle='list-style-type:none;'><li>Gettingfacts'<http://inova8.com/calc2graph/def/myOption>'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a></li></li><li>...usingoptions:[time="43"^^<http://www.w3.org/2001/XMLSchema#int>]</li></li><li>...withincontexts:[file://src/test/resources/calc2graph.def.ttl,http://inova8.com/calc2graph/contextGraph,file://src/test/resources/calc2graph.data.ttl]</li></li><olstyle='list-style-type:none;'><li>Evaluatingpredicate<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>,byinvoking<b>groovy</b>script</li></li><li><divstyle='border:1pxsolidblack;'><pre><code>_customQueryOptions.get("time").integerValue();</code></pre></div></li><olstyle='list-style-type:none;'></ol><li>Evaluated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=43^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li></ol><li>Calculated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=43^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Retrievedcachedvalue<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=43^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Returnedfact'http://inova8.com/calc2graph/def/myOption'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=43^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><p></ol>", result.asHTML());
result = myCountry1.traceFact("<http://inova8.com/calc2graph/def/myOption>&time='2019'^^xsd:int");
Query.assertEqualsWOSpaces("<olstyle='list-style-type:none;'><li>Gettingfacts'<http://inova8.com/calc2graph/def/myOption>&time='2019'^^xsd:int'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a></li></li><li>...withincontexts:[file://src/test/resources/calc2graph.def.ttl,http://inova8.com/calc2graph/contextGraph,file://src/test/resources/calc2graph.data.ttl]</li></li><olstyle='list-style-type:none;'><li>Evaluatingpredicate<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>,byinvoking<b>groovy</b>script</li></li><li><divstyle='border:1pxsolidblack;'><pre><code>_customQueryOptions.get("time").integerValue();</code></pre></div></li><olstyle='list-style-type:none;'></ol><li>Evaluated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=2019^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li></ol><li>Calculated<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=2019^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Retrievedcachedvalue<ahref='http://inova8.com/calc2graph/def/myOption'target='_blank'>myOption</a>of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=2019^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><li>Returnedfact'http://inova8.com/calc2graph/def/myOption'of<ahref='http://inova8.com/calc2graph/def/myCountry'target='_blank'>myCountry</a>=2019^^<ahref='http://www.w3.org/2001/XMLSchema#int'target='_blank'>int</a></li></li><p></ol>", result.asHTML());
ResourceResults results = myCountry1.getFacts("<http://inova8.com/calc2graph/def/myOption>&time='2020'^^xsd:int");
for (Resource result1 : results) {
Query.assertEqualsWOSpaces("2020", result1.stringValue());
}
} catch (Exception e) {
assertEquals("", e.getMessage());
e.printStackTrace();
}
}
Aggregations