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/10/18 14:34:13 UTC

svn commit: r1533421 - in /stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize: Sentiment.java SentimentPhrase.java SentimentSummarizationEngine.java

Author: rwesten
Date: Fri Oct 18 12:34:13 2013
New Revision: 1533421

URL: http://svn.apache.org/r1533421
Log:
STANBOL-760: improved java doc and some code clean ups

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/SentimentPhrase.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=1533421&r1=1533420&r2=1533421&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 Fri Oct 18 12:34:13 2013
@@ -24,7 +24,6 @@ import java.util.Set;
 
 import org.apache.stanbol.enhancer.nlp.NlpAnnotations;
 import org.apache.stanbol.enhancer.nlp.model.AnalysedText;
-import org.apache.stanbol.enhancer.nlp.model.Section;
 import org.apache.stanbol.enhancer.nlp.model.Sentence;
 import org.apache.stanbol.enhancer.nlp.model.Token;
 import org.apache.stanbol.enhancer.nlp.model.annotation.Value;
@@ -32,11 +31,15 @@ import org.apache.stanbol.enhancer.nlp.p
 import org.apache.stanbol.enhancer.nlp.pos.PosTag;
 
 /**
- * This class is used to allow adding negations to sentiments even if the
- * sentiment was already assigned to an SentimentInfo. In addition this class
- * stores the token for the sentiment AND the tokens causing the negations. No
- * support for multiple negations - meaning that the sentiment value is inverted
- * if 1..* negations are present.
+ * This class is used to represents a {@link Token} that holds a Sentiment in the
+ * context of a {@link Sentence}. Sentiment might be {@link #addNegate(Token) negated}
+ * and be {@link #addAbout(Token) assigned} to a Noun or Pronoun via a
+ * {@link #getVerb() Verb}. The {@link #getStart()} and {@link #getEnd()} values
+ * return the span selected by this Sentiment. This are the lowest start and
+ * highest end values of any token related with this sentiment. Those spans are
+ * used by the {@link SentimentPhrase} class for clustering {@link Sentiment}s
+ * to phrases.
+ * 
  * @author Rupert Westenthaler
  *
  */
@@ -53,16 +56,47 @@ public class Sentiment {
      * {@link #PREF_LEX_CAT}.
      */
     private static final Set<LexicalCategory> PREF_LEX_CAT = EnumSet.of(LexicalCategory.Adjective);
-    
+    /**
+     * The token holding the sentiment
+     */
     private final Token token;
+    /**
+     * The (not negated) value of the sentiment
+     */
     private final double value;
+    /**
+     * The Sentence of the {@link #token}
+     */
     private final Sentence sentence;
+    /**
+     * List of tokens that negate this sentiment. <code>null</code> if no
+     * negation was added
+     */
     private List<Token> negated;
+    /**
+     * The Nouns and/or Pronouns this sentiment is about. <code>null</code> if
+     * no aboutness is defined
+     */
     private List<Token> aboutness;
-    private PosTag posTag;
+    /**
+     * The PosTag of the of the {@link #token}
+     */
+    private final PosTag posTag;
 
+    /**
+     * The start position of this sentiment. This is the lowest start of any
+     * token added to this sentiment. This field is set by {@link #checkSpan(Token)}
+     */
     private int start;
+    /**
+     * The end position of this sentiment. This is the highest end of any
+     * token added to this sentiment. This field is set by {@link #checkSpan(Token)}
+     */
     private int end;
+    /**
+     * The verb assigning this sentiment to the Nouns and/or Pronouns added
+     * by {@link #addAbout(Token)}.
+     */
     private Token verb;
     
     /**
@@ -79,6 +113,7 @@ public class Sentiment {
         this.start = token.getStart();
         this.end = token.getEnd();
         List<Value<PosTag>> tags = token.getAnnotations(NlpAnnotations.POS_ANNOTATION);
+        PosTag posTag = null;
         if(tags != null && !tags.isEmpty()){
             for(Value<PosTag> tag : tags){
                 if(tag.probability() == Value.UNKNOWN_PROBABILITY ||
@@ -98,9 +133,13 @@ public class Sentiment {
                 setVerb(token);
             }
         }
+        this.posTag = posTag;
     }
-    
-    public void negate(Token token){
+    /**
+     * Adds an Token that negates this Sentiment
+     * @param token the token
+     */
+    protected void addNegate(Token token){
         if(negated == null){ //most of the time a singeltonList will do
             negated = Collections.singletonList(token);
         } else if(negated.size() == 1){
@@ -111,12 +150,12 @@ public class Sentiment {
         }
         checkSpan(token);
     }
-    protected final void setVerb(Token verb) {
+    protected void setVerb(Token verb) {
         this.verb = verb;
         checkSpan(verb);
     }
 
-    protected final void addAbout(Token noun) {
+    protected void addAbout(Token noun) {
         if(aboutness == null){
             aboutness = new ArrayList<Token>(4);
         }
@@ -125,8 +164,9 @@ public class Sentiment {
     }
     /**
      * Checks the {@link #start} {@link #end} values against the span selected
-     * by the parsed token
-     * @param token
+     * by the parsed token.<p>
+     * This method is called by all others that do add tokens.
+     * @param token the added token
      */
     private void checkSpan(Token token) {
         if(start > token.getStart()){
@@ -144,30 +184,44 @@ public class Sentiment {
     public PosTag getPosTag() {
         return posTag;
     }
+    /**
+     * The Sentiment value (considering possible negations)
+     * @return the sentiment value
+     */
     public double getValue() {
         return negated == null ? value : value*-1;
     }
-
+    /**
+     * The Token holding the sentiment
+     * @return the token
+     */
     public Token getToken() {
         return token;
     }
     public Sentence getSentence() {
         return sentence;
     }
+    /**
+     * The {@link AnalysedText Text}
+     * @return the text
+     */
     public AnalysedText getAnalysedText(){
         return token.getContext();
     }
-    
+    /**
+     * The tokens negating this Sentiment
+     * @return the tokens or an empty list if none
+     */
     public List<Token> getNegates() {
-        return negated == null ? Collections.EMPTY_LIST : negated;
+        return negated == null ? Collections.<Token>emptyList() : negated;
     }
 
     /**
-     * The Nouns or Pronoun(s) the Adjectives are about
-     * @return
+     * The Nouns or Pronoun(s) the Sentiment is about
+     * @return the tokens or an empty list if none.
      */
     public List<Token> getAboutness() {
-        return aboutness == null ? Collections.EMPTY_LIST : aboutness;
+        return aboutness == null ? Collections.<Token>emptyList() : aboutness;
     }
     /**
      * The verb used to assign Adjectives to the Nouns (or Pronouns)
@@ -176,11 +230,19 @@ public class Sentiment {
     public Token getVerb() {
         return verb;
     }
-    
+    /**
+     * The start position of this sentiment. This is the lowest start of any
+     * token linked to this sentiment
+     * @return the start position
+     */
     public int getStart(){
         return start;
     }
-    
+    /**
+     * The end position of this sentiment. This is the highest end of any
+     * token linked to this sentiment
+     * @return the end position
+     */
     public int getEnd(){
         return end;
     }

Modified: stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/SentimentPhrase.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/SentimentPhrase.java?rev=1533421&r1=1533420&r2=1533421&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/SentimentPhrase.java (original)
+++ stanbol/trunk/enhancement-engines/sentiment-summarization/src/main/java/org/apache/stanbol/enhancer/engines/sentiment/summarize/SentimentPhrase.java Fri Oct 18 12:34:13 2013
@@ -25,7 +25,8 @@ import org.apache.stanbol.enhancer.nlp.m
 import org.apache.stanbol.enhancer.nlp.model.Token;
 
 /**
- * Used to collect {@link Sentiment}s that refer the same 
+ * Represents phrases in a sentence that do hold a Sentiment value.
+ * Phrases are defined by collecting {@link Sentiment}s that refer the same 
  * {@link Sentiment#getAboutness()}
  * @author Rupert Westenthaler
  */
@@ -48,7 +49,10 @@ public class SentimentPhrase {
     public SentimentPhrase(Sentiment sentiment) {
         addSentiment(sentiment);
     }
-
+    /**
+     * Adds a Sentiment to the Phrase
+     * @param sentiment the sentiment to add
+     */
     public void addSentiment(Sentiment sentiment){
         sentiments.add(sentiment);
         nouns.addAll(sentiment.getAboutness());
@@ -89,9 +93,13 @@ public class SentimentPhrase {
         }
         return __sentiment[2];
     }
-    
+    /**
+     * The Sentence containing this phrase or <code>null</code> if no
+     * {@link Sentiment} was yet added
+     * @return the sentence
+     */
     public Sentence getSentence(){
-        return sentiments.get(0).getSentence();
+        return sentiments.isEmpty() ? null : sentiments.get(0).getSentence();
     }
     
     private void summarizeSentimentValues(){

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=1533421&r1=1533420&r2=1533421&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 Fri Oct 18 12:34:13 2013
@@ -16,8 +16,6 @@
  */
 package org.apache.stanbol.enhancer.engines.sentiment.summarize;
 
-import static org.apache.stanbol.enhancer.nlp.NlpAnnotations.PHRASE_ANNOTATION;
-import static org.apache.stanbol.enhancer.nlp.NlpAnnotations.POS_ANNOTATION;
 import static org.apache.stanbol.enhancer.nlp.NlpAnnotations.SENTIMENT_ANNOTATION;
 import static org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.createTextEnhancement;
 import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.DC_TYPE;
@@ -35,11 +33,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.NavigableMap;
-import java.util.SortedMap;
 import java.util.TreeMap;
 
-import javax.swing.DebugGraphics;
-
 import org.apache.clerezza.rdf.core.Language;
 import org.apache.clerezza.rdf.core.LiteralFactory;
 import org.apache.clerezza.rdf.core.MGraph;
@@ -61,7 +56,6 @@ import org.apache.stanbol.enhancer.nlp.m
 import org.apache.stanbol.enhancer.nlp.model.Span.SpanTypeEnum;
 import org.apache.stanbol.enhancer.nlp.model.Token;
 import org.apache.stanbol.enhancer.nlp.model.annotation.Value;
-import org.apache.stanbol.enhancer.nlp.phrase.PhraseTag;
 import org.apache.stanbol.enhancer.nlp.pos.LexicalCategory;
 import org.apache.stanbol.enhancer.nlp.pos.Pos;
 import org.apache.stanbol.enhancer.nlp.pos.PosTag;
@@ -379,7 +373,7 @@ public class SentimentSummarizationEngin
                 //for negation use the negation context
                 Integer[] context = getNegationContext(index, conjunctions, searchSpan);
                 for(Token negationToken : negations.subMap(context[0] , true, context[1], true).values()){
-                    sentiment.negate(negationToken);
+                    sentiment.addNegate(negationToken);
                 }
                 //for nouns use the sentiment context
                 context = getSentimentContext(index, sentiment, verbs, conjunctions, nounsAndPronouns, searchSpan);