use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.
the class ClerezzaRDFUtils method makeConnected.
public static void makeConnected(Graph model, BlankNodeOrIRI root, IRI property) {
Set<BlankNodeOrIRI> roots = findRoots(model);
LOG.debug("Roots: {}", roots.size());
boolean found = roots.remove(root);
//connect all hanging roots to root by property
for (BlankNodeOrIRI n : roots) {
model.add(new TripleImpl(root, property, n));
}
}
use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.
the class EnhancementStructureHelper method validateLanguageAnnotations.
/**
* Validates the correctness of fise:TextAnnotations that annotate the language
* of the text as defined by
* <a href="https://issues.apache.org/jira/browse/STANBOL-613">STANBOL-613</a><p>
* Called by {@link #validateTextAnnotation(Graph, IRI, String, Map)}
* @param enhancements
* @param textAnnotation
*/
private static void validateLanguageAnnotations(Graph enhancements, IRI textAnnotation) {
Iterator<Triple> dcLanguageIterator = enhancements.filter(textAnnotation, DC_LANGUAGE, null);
if (dcLanguageIterator.hasNext()) {
//a language annotation
RDFTerm dcLanguageResource = dcLanguageIterator.next().getObject();
assertTrue("The dc:language value MUST BE a PlainLiteral", dcLanguageResource instanceof Literal);
assertTrue("The dc:language value '" + dcLanguageResource + "'MUST BE at least two chars long", ((Literal) dcLanguageResource).getLexicalForm().length() >= 2);
assertFalse("TextAnnotations with the dc:language property MUST only have a single dc:language value (uri " + textAnnotation + ")", dcLanguageIterator.hasNext());
Iterator<Triple> dcTypeIterator = enhancements.filter(textAnnotation, DC_TYPE, null);
assertTrue("TextAnnotations with the dc:language property MUST use dc:type dc:LinguisticSystem (uri " + textAnnotation + ")", dcTypeIterator.hasNext());
assertEquals("TextAnnotations with the dc:language property MUST use dc:type dc:LinguisticSystem (uri " + textAnnotation + ")", DCTERMS_LINGUISTIC_SYSTEM, dcTypeIterator.next().getObject());
assertFalse("TextAnnotations with the dc:language property MUST only have a single dc:type value (uri " + textAnnotation + ")", dcTypeIterator.hasNext());
//assert that the created TextAnnotation is correctly returned by the
//EnhancementEngineHelper methods
List<BlankNodeOrIRI> languageAnnotation = EnhancementEngineHelper.getLanguageAnnotations(enhancements);
assertTrue("Language annotation " + textAnnotation + " was not returned by " + "EnhancementEngineHelper.getLanguageAnnotations(..)!", languageAnnotation.contains(textAnnotation));
} else {
//no language annotation
Iterator<Triple> dcTypeIterator = enhancements.filter(textAnnotation, DC_TYPE, null);
while (dcTypeIterator.hasNext()) {
assertFalse("Only fise:TextAnnotations without a dc:language value MUST NOT use the " + "dc:type value dc:LinguisticSystem (uri " + textAnnotation + ")", DCTERMS_LINGUISTIC_SYSTEM.equals(dcTypeIterator.next().getObject()));
}
}
}
use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.
the class EnhancementJobHandler method handleEvent.
@Override
public void handleEvent(Event event) {
EnhancementJob job = (EnhancementJob) event.getProperty(PROPERTY_JOB_MANAGER);
BlankNodeOrIRI execution = (BlankNodeOrIRI) event.getProperty(PROPERTY_EXECUTION);
if (job == null || execution == null) {
log.warn("Unable to process EnhancementEvent where EnhancementJob " + "{} or Execution node {} is null -> ignore", job, execution);
}
try {
processEvent(job, execution);
} catch (Throwable t) {
String message = String.format("Unexpected Exception while processing " + "ContentItem %s with EnhancementJobManager: %s", job.getContentItem().getUri(), EventJobManagerImpl.class);
//this ensures that an runtime exception does not
job.setFailed(execution, null, new IllegalStateException(message, t));
log.error(message, t);
}
//(2) trigger the next actions
log.trace("++ w: {}", "check for next Executions");
job.getLock().writeLock().lock();
log.trace(">> w: {}", "check for next Executions");
try {
if (job.isFinished()) {
finish(job);
} else if (!job.isFailed()) {
if (!executeNextNodes(job) && job.getRunning().isEmpty()) {
log.warn("Unexpected state in the Execution of ContentItem {}:" + " Job is not finished AND no executions are running AND" + " no further execution could be started! -> finishing" + " this job :(");
finish(job);
}
//else execution started of other jobs are running
} else {
if (log.isInfoEnabled()) {
Collection<String> running = new ArrayList<String>(3);
for (BlankNodeOrIRI runningNode : job.getRunning()) {
running.add(getEngine(job.getExecutionPlan(), job.getExecutionNode(runningNode)));
}
log.info("Job {} failed, but {} still running!", job.getContentItem().getUri(), running);
}
}
} finally {
log.trace("<< w: {}", "check for next Executions");
job.getLock().writeLock().unlock();
}
}
use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.
the class EnhancementJobHandler method logJobInfo.
/**
* Logs basic infos about the Job as INFO and detailed infos as DEBUG
* @param job
*/
protected static void logJobInfo(Logger log, EnhancementJob job, String header, boolean logExecutions) {
if (header != null) {
log.info(header);
}
log.info(" finished: {}", job.isFinished());
log.info(" state: {}", job.isFailed() ? "failed" : "processing");
log.info(" chain: {}", job.getChainName());
log.info(" content-item: {}", job.getContentItem().getUri());
if (logExecutions) {
log.info(" executions:");
for (BlankNodeOrIRI completedExec : job.getCompleted()) {
log.info(" - {} completed", getEngine(job.getExecutionMetadata(), job.getExecutionNode(completedExec)));
}
for (BlankNodeOrIRI runningExec : job.getRunning()) {
log.info(" - {} running", getEngine(job.getExecutionMetadata(), job.getExecutionNode(runningExec)));
}
for (BlankNodeOrIRI executeable : job.getExecutable()) {
log.info(" - {} executeable", getEngine(job.getExecutionMetadata(), job.getExecutionNode(executeable)));
}
}
if (job.getErrorMessage() != null) {
log.info("Error Message: {}", job.getErrorMessage());
}
if (job.getError() != null) {
log.info("Reported Exception:", job.getError());
}
}
use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.
the class EnhancementJob method setRunning.
/**
* Sets the state of the parsed execution to running. This also validates if the new state
* confirms to the ExectionPlan (e.g. if all nodes the parsed node depends on are already marked as
* completed).
*
* @param execution
* the execution to be marked as running
* @throws IllegalArgumentException
* if <code>null</code> is parsed as execution node
* @throws IllegalStateException
* if the parsed execution node can not be marked as running because some of its depended
* nodes are not yet marked as completed.
*/
public void setRunning(BlankNodeOrIRI execution) {
if (execution == null) {
throw new IllegalArgumentException("The parsed em:Execution instance MUST NOT be NULL!");
}
BlankNodeOrIRI executionNode = getExecutionNode(execution);
String engine = getEngine(executionPlan, executionNode);
boolean optional = isOptional(executionPlan, executionNode);
Set<BlankNodeOrIRI> dependsOn = getDependend(executionPlan, executionNode);
log.trace("++ w: {}: {}", "setRunning", ExecutionPlanHelper.getEngine(executionPlan, executionNode));
writeLock.lock();
try {
log.trace(">> w: {}: {}", "setRunning", ExecutionPlanHelper.getEngine(executionPlan, executionNode));
if (completed.contains(executionNode)) {
String message = "Unable to set state of ExectionNode '" + executionNode + "'(chain '" + chain + "' | contentItem '" + contentItem.getUri() + "') to running, because" + "it is already marked as completed. This indicates " + "an Bug in the implementation of the JobManager " + "used to execute the ExecutionPlan (chain state: " + "completed " + completed + " | running " + running + ")!";
log.error(message);
throw new IllegalStateException(message);
}
if (!completed.containsAll(dependsOn)) {
// TODO maybe define an own Exception for such cases
String message = "Unable to set state of ExectionNode '" + executionNode + "' (chain '" + chain + "' | contentItem '" + contentItem.getUri() + "') to running, because " + "some of its depended nodes are not marked " + "completed yet. This indicates an Bug in the " + "implementation of the JobManager used to execute " + "the ExecutionPlan (this.dependsOn=" + dependsOn + "| chain.completed " + completed + " | chain.running " + running + ")!";
log.error(message);
throw new IllegalStateException(message);
}
if (!running.add(executionNode)) {
log.warn("Execution of Engine '{}' for ContentItem {} already " + "marked as running(chain: {}, node: {}, optional {})." + " -> call ignored", new Object[] { engine, contentItem.getUri().getUnicodeString(), chain, executionNode, optional });
return;
} else {
//added an engine to running
log.trace("Started Execution of '{}' for ContentItem {} " + "(chain: {}, node: {}, optional {})", new Object[] { engine, contentItem.getUri().getUnicodeString(), chain, executionNode, optional });
//set the status of the execution to be in progress
ExecutionMetadataHelper.setExecutionInProgress(executionMetadata, execution);
// update the executables ... this will also recognise if finished
updateRunningExec();
//update executables
checkExecutable();
}
} finally {
log.trace("<< w: {}: {}", "setRunning", ExecutionPlanHelper.getEngine(executionPlan, executionNode));
writeLock.unlock();
}
}
Aggregations