use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.
the class IndexedGraphTest method remove.
@Test(expected = ConcurrentModificationException.class)
public void remove() {
Graph itc = new IndexedGraph();
itc.add(triple1);
itc.add(triple2);
itc.add(triple3);
itc.add(triple4);
itc.add(triple5);
Iterator<Triple> iter = itc.filter(uriRef1, null, null);
while (iter.hasNext()) {
Triple triple = iter.next();
itc.remove(triple);
}
Assert.assertEquals(3, itc.size());
}
use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.
the class IndexedGraphTest method filterIteratorRemove.
@Test
public void filterIteratorRemove() {
Graph itc = new IndexedGraph();
itc.add(triple1);
itc.add(triple2);
itc.add(triple3);
itc.add(triple4);
itc.add(triple5);
Iterator<Triple> iter = itc.filter(uriRef1, null, null);
while (iter.hasNext()) {
iter.next();
iter.remove();
}
Assert.assertEquals(3, itc.size());
}
use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.
the class IndexedGraphTest method iteratorRemove.
@Test
public void iteratorRemove() {
Graph itc = new IndexedGraph();
itc.add(triple1);
itc.add(triple2);
itc.add(triple3);
itc.add(triple4);
itc.add(triple5);
Iterator<Triple> iter = itc.iterator();
while (iter.hasNext()) {
iter.next();
iter.remove();
}
Assert.assertEquals(0, itc.size());
}
use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.
the class IndexedGraphTest method bNodeConsitency.
@Test
public void bNodeConsitency() {
Graph mGraph = getEmptyGraph();
final BlankNode bNode = new BlankNode() {
@Override
public int hashCode() {
return -1;
}
@Override
public boolean equals(Object o) {
return o instanceof BlankNode;
}
};
final BlankNode bNodeClone = new BlankNode() {
@Override
public int hashCode() {
return -1;
}
@Override
public boolean equals(Object o) {
return o instanceof BlankNode;
}
};
mGraph.add(new TripleImpl(bNode, uriRef1, uriRef2));
mGraph.add(new TripleImpl(bNodeClone, uriRef2, uriRef3));
BlankNodeOrIRI bNodeBack = mGraph.filter(null, uriRef1, uriRef2).next().getSubject();
Assert.assertEquals("The bnode we get back is not equals to the one we added", bNode, bNodeBack);
BlankNodeOrIRI bNodeBack2 = mGraph.filter(null, uriRef2, uriRef3).next().getSubject();
Assert.assertEquals("The returnned bnodes are no longer equals", bNodeBack, bNodeBack2);
Assert.assertTrue("Not finding a triple when searching with equal bNode", mGraph.filter(bNodeBack, uriRef2, null).hasNext());
}
use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.
the class ListChain method activate.
@Override
protected void activate(ComponentContext ctx) throws ConfigurationException {
super.activate(ctx);
Object value = ctx.getProperties().get(PROPERTY_ENGINE_LIST);
List<String> configuredChain = new ArrayList<String>();
if (value instanceof String[]) {
configuredChain.addAll(Arrays.asList((String[]) value));
} else if (value instanceof List<?>) {
for (Object o : (List<?>) value) {
if (o != null) {
configuredChain.add(o.toString());
}
}
} else {
throw new ConfigurationException(PROPERTY_ENGINE_LIST, "The engines of a List Chain MUST BE configured as Array/List of " + "Strings (parsed: " + (value != null ? value.getClass() : "null") + ")");
}
Set<String> engineNames = new HashSet<String>(configuredChain.size());
BlankNodeOrIRI last = null;
Graph ep = new SimpleGraph();
BlankNodeOrIRI epNode = createExecutionPlan(ep, getName(), getChainProperties());
log.debug("Parse ListChain config:");
for (String line : configuredChain) {
try {
Entry<String, Map<String, List<String>>> parsed = ConfigUtils.parseConfigEntry(line);
if (!engineNames.add(parsed.getKey())) {
throw new ConfigurationException(PROPERTY_ENGINE_LIST, "The EnhancementEngine '" + parsed.getKey() + "' is mentioned" + "twice in the configured list!");
}
boolean optional = getState(parsed.getValue(), "optional");
log.debug(" > Engine: {} ({})", parsed.getKey(), optional ? "optional" : "required");
last = writeExecutionNode(ep, epNode, parsed.getKey(), optional, last == null ? null : Collections.singleton(last), getEnhancementProperties(parsed.getValue()));
} catch (IllegalArgumentException e) {
throw new ConfigurationException(PROPERTY_ENGINE_LIST, "Unable to parse Chain Configuraiton (message: '" + e.getMessage() + "')!", e);
}
}
if (engineNames.isEmpty()) {
throw new ConfigurationException(PROPERTY_ENGINE_LIST, "The configured chain MUST at least contain a single valid entry!");
}
this.engineNames = Collections.unmodifiableSet(engineNames);
this.executionPlan = ep.getImmutableGraph();
}
Aggregations