You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2013/08/29 15:06:56 UTC
svn commit: r1518631 - in
/stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize:
Sentiment.java SentimentSummarizationEngine.java
Author: rwesten
Date: Thu Aug 29 13:06:55 2013
New Revision: 1518631
URL: http://svn.apache.org/r1518631
Log:
STANBOL-760: fixed some NPE related to tokens without an POS tag (can only occur if the used POS engine does not add POS annotations to all tokens of the text)
Modified:
stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/Sentiment.java
stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/SentimentSummarizationEngine.java
Modified: stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/Sentiment.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/Sentiment.java?rev=1518631&r1=1518630&r2=1518631&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/Sentiment.java (original)
+++ stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/Sentiment.java Thu Aug 29 13:06:55 2013
@@ -79,22 +79,24 @@ public class Sentiment {
this.start = token.getStart();
this.end = token.getEnd();
List<Value<PosTag>> tags = token.getAnnotations(NlpAnnotations.POS_ANNOTATION);
- for(Value<PosTag> tag : tags){
- if(tag.probability() == Value.UNKNOWN_PROBABILITY ||
- tag.probability() >= MIN_POS_CONF ||
- !Collections.disjoint(tag.value().getCategories(),PREF_LEX_CAT)){
- posTag = tag.value();
- break;
+ if(tags != null && !tags.isEmpty()){
+ for(Value<PosTag> tag : tags){
+ if(tag.probability() == Value.UNKNOWN_PROBABILITY ||
+ tag.probability() >= MIN_POS_CONF ||
+ !Collections.disjoint(tag.value().getCategories(),PREF_LEX_CAT)){
+ posTag = tag.value();
+ break;
+ }
+ }
+ if(posTag == null){
+ posTag = tags.get(0).value();
+ }
+ if(posTag.hasCategory(LexicalCategory.Noun)){
+ addAbout(token); //add the token also as noun
+ }
+ if(posTag.hasCategory(LexicalCategory.Verb)){
+ setVerb(token);
}
- }
- if(posTag == null){
- posTag = tags.get(0).value();
- }
- if(posTag.hasCategory(LexicalCategory.Noun)){
- addAbout(token); //add the token also as noun
- }
- if(posTag.hasCategory(LexicalCategory.Verb)){
- setVerb(token);
}
}
Modified: stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/SentimentSummarizationEngine.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/SentimentSummarizationEngine.java?rev=1518631&r1=1518630&r2=1518631&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/SentimentSummarizationEngine.java (original)
+++ stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/SentimentSummarizationEngine.java Thu Aug 29 13:06:55 2013
@@ -416,9 +416,9 @@ public class SentimentSummarizationEngin
Integer[] context;
PosTag pos = sentiment.getPosTag();
boolean isPredicative;
- if(pos.getPosHierarchy().contains(Pos.PredicativeAdjective)){
+ if(pos != null && pos.getPosHierarchy().contains(Pos.PredicativeAdjective)){
isPredicative = true;
- } else if(pos.hasCategory(LexicalCategory.Adjective) &&
+ } else if(pos != null && pos.hasCategory(LexicalCategory.Adjective) &&
//Adjective that are not directly in front of a Noun
nouns.get(Integer.valueOf(index+1)) == null){
isPredicative = true;
@@ -492,14 +492,14 @@ public class SentimentSummarizationEngin
context = new Integer[]{Integer.valueOf(index-nounContext),
Integer.valueOf(index+nounContext)};
}
- } else if(pos.hasCategory(LexicalCategory.Adjective)){
+ } else if(pos != null && pos.hasCategory(LexicalCategory.Adjective)){
//for all other adjective the affected noun is expected directly
//after the noun
context = new Integer[]{index,Integer.valueOf(index+1)};
- } else if(pos.hasCategory(LexicalCategory.Noun)){
+ } else if(pos != null && pos.hasCategory(LexicalCategory.Noun)){
//a noun with an sentiment
context = new Integer[]{index,index};
- } else { //else return default
+ } else { //else (includes pos == null) return default
context = new Integer[]{Integer.valueOf(index-nounContext),
Integer.valueOf(index+nounContext)};
}
@@ -515,17 +515,17 @@ public class SentimentSummarizationEngin
private boolean isPronoun(Token token, String language) {
Value<PosTag> posAnnotation = token.getAnnotation(NlpAnnotations.POS_ANNOTATION);
- return posAnnotation.value().getPosHierarchy().contains(Pos.Pronoun);
+ return posAnnotation == null ? false : posAnnotation.value().getPosHierarchy().contains(Pos.Pronoun);
}
private boolean isVerb(Token token, String language) {
Value<PosTag> posAnnotation = token.getAnnotation(NlpAnnotations.POS_ANNOTATION);
- return posAnnotation.value().hasCategory(LexicalCategory.Verb);
+ return posAnnotation == null ? false : posAnnotation.value().hasCategory(LexicalCategory.Verb);
}
private boolean isCoordinatingConjuction(Token token, String language) {
Value<PosTag> posAnnotation = token.getAnnotation(NlpAnnotations.POS_ANNOTATION);
- return posAnnotation.value().getPosHierarchy().contains(Pos.CoordinatingConjunction);
+ return posAnnotation == null ? false : posAnnotation.value().getPosHierarchy().contains(Pos.CoordinatingConjunction);
}
private boolean isSectionBorder(Token token, String language) {