use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class Nlp2RdfMetadataEngine method computeEnhancements.
@Override
public void computeEnhancements(ContentItem ci) throws EngineException {
AnalysedText at = getAnalysedText(this, ci, true);
String lang = EnhancementEngineHelper.getLanguage(ci);
Language language = lang == null ? null : new Language(lang);
// now iterate over the AnalysedText data and create the RDF representation
// TODO: make configureable
boolean sentences = true;
boolean phrases = true;
boolean words = true;
EnumSet<SpanTypeEnum> activeTypes = EnumSet.noneOf(SpanTypeEnum.class);
if (sentences) {
activeTypes.add(SpanTypeEnum.Sentence);
}
if (phrases) {
activeTypes.add(SpanTypeEnum.Chunk);
}
if (words) {
activeTypes.add(SpanTypeEnum.Token);
}
Graph metadata = ci.getMetadata();
IRI base = ci.getUri();
ci.getLock().writeLock().lock();
try {
Iterator<Span> spans = at.getEnclosed(activeTypes);
IRI sentence = null;
IRI phrase = null;
IRI word = null;
boolean firstWordInSentence = true;
while (spans.hasNext()) {
Span span = spans.next();
// TODO: filter Spans based on additional requirements
// (1) write generic information about the span
IRI current = writeSpan(metadata, base, at, language, span);
// (2) add the relations between the different spans
switch(span.getType()) {
case Sentence:
if (sentence != null) {
metadata.add(new TripleImpl(sentence, SsoOntology.nextSentence.getUri(), current));
}
sentence = current;
firstWordInSentence = true;
break;
case Chunk:
if (sentence != null) {
metadata.add(new TripleImpl(current, StringOntology.superString.getUri(), sentence));
if (word != null) {
metadata.add(new TripleImpl(word, SsoOntology.lastWord.getUri(), sentence));
}
}
phrase = current;
break;
case Token:
if (sentence != null) {
metadata.add(new TripleImpl(current, SsoOntology.sentence.getUri(), sentence));
if (firstWordInSentence) {
metadata.add(new TripleImpl(current, SsoOntology.firstWord.getUri(), sentence));
firstWordInSentence = false;
}
}
if (phrase != null) {
metadata.add(new TripleImpl(current, SsoOntology.parent.getUri(), phrase));
}
if (word != null) {
metadata.add(new TripleImpl(word, SsoOntology.nextWord.getUri(), current));
metadata.add(new TripleImpl(current, SsoOntology.previousWord.getUri(), word));
}
word = current;
break;
default:
break;
}
// (3) add specific information such as POS, chunk type ...
writePos(metadata, span, current);
writePhrase(metadata, span, current);
// OlIA does not include Sentiments
Value<Double> sentiment = span.getAnnotation(NlpAnnotations.SENTIMENT_ANNOTATION);
if (sentiment != null && sentiment.value() != null) {
metadata.add(new TripleImpl(current, SENTIMENT_PROPERTY, lf.createTypedLiteral(sentiment.value())));
}
}
} finally {
ci.getLock().writeLock().unlock();
}
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class ConstantMapping method apply.
@Override
public boolean apply(Graph graph, BlankNodeOrIRI subject, Metadata metadata) {
for (RDFTerm value : values) {
graph.add(new TripleImpl(subject, ontProperty, value));
mappingLogger.log(subject, ontProperty, null, value);
}
return true;
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class ExecutionMetadataHelper method createEngineExecution.
public static BlankNodeOrIRI createEngineExecution(Graph graph, BlankNodeOrIRI chainExecution, BlankNodeOrIRI executionNode) {
BlankNodeOrIRI node = new BlankNode();
graph.add(new TripleImpl(node, RDF_TYPE, EXECUTION));
graph.add(new TripleImpl(node, RDF_TYPE, ENGINE_EXECUTION));
graph.add(new TripleImpl(node, EXECUTION_PART, chainExecution));
graph.add(new TripleImpl(node, EXECUTION_NODE, executionNode));
graph.add(new TripleImpl(node, STATUS, STATUS_SCHEDULED));
return node;
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class ExecutionMetadataHelper method setExecutionCompleted.
/**
* Sets the state of the ExecutionNode to completed
* @param graph
* @param execution
* @param message An optional message
*/
public static void setExecutionCompleted(Graph graph, BlankNodeOrIRI execution, String message) {
Literal dateTime = lf.createTypedLiteral(new Date());
setStatus(graph, execution, STATUS_COMPLETED);
graph.add(new TripleImpl(execution, COMPLETED, dateTime));
if (message != null) {
graph.add(new TripleImpl(execution, STATUS_MESSAGE, new PlainLiteralImpl(message)));
}
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class EnhancementEngineHelper method addContributingEngine.
/**
* Adds the parsed {@link EnhancementEngine} as dc:contributer to the
* enhancement and also sets the dc:modified property accordingly
* @param metadata the {@link ContentItem#getMetadata()}
* @param enhancement the enhancement
* @param engine the engine
*/
public static void addContributingEngine(Graph metadata, IRI enhancement, EnhancementEngine engine) {
LiteralFactory literalFactory = LiteralFactory.getInstance();
// TODO: use a public dereferencing URI instead?
metadata.add(new TripleImpl(enhancement, DC_CONTRIBUTOR, literalFactory.createTypedLiteral(engine.getClass().getName())));
// set the modification date to the current date.
set(metadata, enhancement, DC_MODIFIED, new Date(), literalFactory);
}
Aggregations