private void writeSentimentEnhancements(ContentItem ci, List<SentimentPhrase> sentimentPhrases, AnalysedText at, Language lang) {
// TODO Auto-generated method stub
MGraph metadata = ci.getMetadata();
Sentence currentSentence = null;
final List<SentimentPhrase> sentencePhrases = new ArrayList<SentimentPhrase>();
for(SentimentPhrase sentPhrase : sentimentPhrases){
Sentence sentence = sentPhrase.getSentence();
if(log.isDebugEnabled()){ //debug sentiment info
CharSequence phraseText = at.getText().subSequence(sentPhrase.getStartIndex(), sentPhrase.getEndIndex());
log.debug("Write SentimentPhrase for {} (sentence: {})", phraseText,
sentence == null ? "none" : sentence.getSpan().length() > 17 ? (sentence.getSpan().subSequence(0,17) + "...") : sentence.getSpan());
List<Sentiment> sentiments = sentPhrase.getSentiments();
log.debug(" > {} Sentiments:",sentiments.size());
for(int i = 0; i < sentiments.size(); i++){
log.debug(" {}. {}",i+1,sentiments.get(i));
}
}
if(writeSentimentPhrases){
UriRef enh = createTextEnhancement(ci, this);
String phraseText = at.getSpan().substring(sentPhrase.getStartIndex(), sentPhrase.getEndIndex());
metadata.add(new TripleImpl(enh, ENHANCER_SELECTED_TEXT,
new PlainLiteralImpl(phraseText, lang)));
if(sentPhrase.getSentence() == null){
metadata.add(new TripleImpl(enh, ENHANCER_SELECTION_CONTEXT,
new PlainLiteralImpl(getSelectionContext(
at.getSpan(), phraseText, sentPhrase.getStartIndex()),lang)));
} else {
metadata.add(new TripleImpl(enh, ENHANCER_SELECTION_CONTEXT,
new PlainLiteralImpl(sentPhrase.getSentence().getSpan(),lang)));
}
metadata.add(new TripleImpl(enh, ENHANCER_START,
lf.createTypedLiteral(sentPhrase.getStartIndex())));
metadata.add(new TripleImpl(enh, ENHANCER_END,
lf.createTypedLiteral(sentPhrase.getEndIndex())));
if(sentPhrase.getPositiveSentiment() != null){
metadata.add(new TripleImpl(enh, POSITIVE_SENTIMENT_PROPERTY,
lf.createTypedLiteral(sentPhrase.getPositiveSentiment())));
}
if(sentPhrase.getNegativeSentiment() != null){
metadata.add(new TripleImpl(enh, NEGATIVE_SENTIMENT_PROPERTY,
lf.createTypedLiteral(sentPhrase.getNegativeSentiment())));
}
metadata.add(new TripleImpl(enh, SENTIMENT_PROPERTY,
lf.createTypedLiteral(sentPhrase.getSentiment())));
//add the Sentiment type as well as the type of the SSO Ontology
metadata.add(new TripleImpl(enh, DC_TYPE, SENTIMENT_TYPE));
UriRef ssoType = NIFHelper.SPAN_TYPE_TO_SSO_TYPE.get(SpanTypeEnum.Chunk);
if(ssoType != null){
metadata.add(new TripleImpl(enh, DC_TYPE, ssoType));
}
}
if(writeSentencesSentimet && sentence != null){
if(sentence.equals(currentSentence)){
sentencePhrases.add(sentPhrase);
} else {
writeSentiment(ci, currentSentence,sentencePhrases);
//reset
currentSentence = sentence;