use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Remote_PathQL_MultiGraphTests method test_50.
/**
* Test 50.
*/
@Test
@Order(50)
void test_50() {
try {
// Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph5>");
// source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
Graph graph = source.openGraph("<http://inova8.com/calc2graph/testGraph5>");
Thing myCountry = graph.getThing(":Country1");
String performanceCalculation = "2*3";
myCountry.addFact(":Attribute@:salesPerformance", performanceCalculation, SCRIPT.GROOVY);
ResourceResults results = myCountry.getFacts(":Attribute@:salesPerformance");
// if(results.hasNext()) {
for (Resource result : results) {
assertEquals("6", result.getValue().stringValue());
break;
}
// source.removeGraph("<http://inova8.com/calc2graph/testGraph>");
source.closeGraph("<http://inova8.com/calc2graph/testGraph5>");
// }else {
// fail();
// }
} catch (Exception e) {
fail();
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method addGraph.
/**
* Adds the graph.
*
* @param graphName the graph name
* @return the graph
*/
public Graph addGraph(String graphName) {
ContextAwareConnection connection = this.getContextAwareConnection();
Model result;
IRI graphNameIri = null;
try {
graphNameIri = PathParser.parseIriRef(getRepositoryContext(), graphName).getIri();
result = new LinkedHashModel();
((Model) result).add(graphNameIri, SCRIPT.CACHE_DATE_TIME, literal(new Date()), graphNameIri);
((Model) result).add(graphNameIri, SCRIPT.ISPRIVATE, literal(true), graphNameIri);
connection.add((Model) result, graphNameIri);
Graph addedGraph = new Graph(this, graphNameIri);
graphs.put(graphNameIri, addedGraph);
getPublicContexts().add(graphNameIri);
logger.debug("Added new graph {} ", graphNameIri.stringValue());
} catch (Exception qe) {
throw new ServerException(FAILEDTOADDGRAPH_EXCEPTION, String.format("Failed to add graph %s with exception %s", graphName, qe.getMessage()), qe);
}
return new Graph(this, graphNameIri);
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph 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.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method openGraph.
/**
* Open graph.
*
* @param graphName the graph name
* @return the graph
*/
public Graph openGraph(String graphName) {
// .getContextAwareConnection();
RepositoryConnection connection = this.getRepository().getConnection();
IRI graphNameIri = null;
try {
graphNameIri = PathParser.parseIriRef(getRepositoryContext(), graphName).getIri();
@SuppressWarnings("deprecation") Boolean contextExists = connection.getContextIDs().asList().contains(graphNameIri);
if (!contextExists) {
addGraph(graphName);
} else {
getPublicContexts().add(graphNameIri);
}
logger.debug("Got graph {} ", graphNameIri.stringValue());
} catch (Exception qe) {
throw new ServerException(FAILEDTOOPENGRAPH_EXCEPTION, String.format("Failed to get graph %s with exception %s", graphName, qe.getMessage()), qe);
}
return new Graph(this, graphNameIri);
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Thing method create.
/**
* Creates the.
*
* @param source the source
* @param graphIri the graph iri
* @param superValue the super value
* @param evaluationContext the evaluation context
* @return the thing
*/
@SuppressWarnings("deprecation")
public static Thing create(IntelligentGraphRepository source, IRI graphIri, org.eclipse.rdf4j.model.Value superValue, EvaluationContext evaluationContext) {
Thing thing;
// graphIri.stringValue()+"~"+ superValue.stringValue();
String graphThingKey = superValue.stringValue();
if (superValue != null && source != null && source.getThings().containsKey(graphThingKey)) {
thing = source.getThings().get(graphThingKey);
thing.setSource(source);
if (evaluationContext != null) {
// if(thing.evaluationContext.getPrefixes()==null || thing.evaluationContext.getPrefixes().isEmpty())thing.evaluationContext.setPrefixes(evaluationContext.getPrefixes());
if (evaluationContext.getCustomQueryOptions() != null && !evaluationContext.getCustomQueryOptions().isEmpty())
thing.evaluationContext.setCustomQueryOptions(evaluationContext.getCustomQueryOptions());
if (evaluationContext.getTracer() != null && evaluationContext.getTracer().isTracing())
thing.evaluationContext.setTracer(evaluationContext.getTracer());
if (evaluationContext.getDataset() != null)
thing.evaluationContext.setDataset(evaluationContext.getDataset());
thing.evaluationContext.setContexts(evaluationContext.getContexts());
}
// Overwrite the graphName if not null
if (graphIri != null)
thing.graphName = graphIri;
return thing;
} else {
thing = new Thing(source, superValue, evaluationContext);
if (source != null)
source.getThings().put(graphThingKey, thing);
if (graphIri == null)
graphIri = Graph.DEFAULTGRAPH;
thing.graphName = graphIri;
}
if (evaluationContext != null)
thing.evaluationContext = evaluationContext;
else if (thing.evaluationContext == null)
thing.evaluationContext = new EvaluationContext();
return thing;
}
Aggregations