Author: rwesten
Date: Wed Jan  9 11:14:45 2013
New Revision: 1430789

URL: http://svn.apache.org/viewvc?rev=1430789&view=rev
Log:
fix for STANBOL-881; API changes as noted in the first comment of STANBOL-878

Modified:
    
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/NlpAnnotations.java
    
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/annotation/Annotated.java
    
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/annotation/Annotation.java
    
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/impl/AnnotatedImpl.java
    
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/pos/PosTag.java
    
stanbol/trunk/enhancer/generic/nlp/src/test/java/org/apache/stanbol/enhancer/nlp/model/AnalysedTextTest.java

Modified: 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/NlpAnnotations.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/NlpAnnotations.java?rev=1430789&r1=1430788&r2=1430789&view=diff
==============================================================================
--- 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/NlpAnnotations.java
 (original)
+++ 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/NlpAnnotations.java
 Wed Jan  9 11:14:45 2013
@@ -18,12 +18,12 @@ public interface NlpAnnotations {
      * The POS {@link Annotation} added by POS taggers to {@link Token}s of
      * an {@link AnalysedText}.
      */
-    Annotation<String,PosTag> POS_ANNOTATION = new Annotation<String,PosTag>(
+    Annotation<PosTag> POS_ANNOTATION = new Annotation<PosTag>(
             "stanbol.enhancer.nlp.pos", PosTag.class);
     /**
      * 
      */
-    Annotation<String,NerTag> NER_ANNOTATION = new Annotation<String,NerTag>(
+    Annotation<NerTag> NER_ANNOTATION = new Annotation<NerTag>(
             "stanbol.enhancer.nlp.ner", NerTag.class);
     
     /**
@@ -31,14 +31,14 @@ public interface NlpAnnotations {
      * [1..*] {@link Token}s.<p>
      * This annotation is typically found on {@link Chunk}s.
      */
-    Annotation<String,PhraseTag> PHRASE_ANNOTATION = new 
Annotation<String,PhraseTag>(
+    Annotation<PhraseTag> PHRASE_ANNOTATION = new Annotation<PhraseTag>(
             "stanbol.enhancer.nlp.phrase", PhraseTag.class);
     
     /**
      * The Sentiment {@link Annotation} added by a sentiment tagger typically
      * to single {@link Token}s that do carry a positive or negative sentiment.
      */
-    Annotation<String,Double> SENTIMENT_ANNOTATION = new 
Annotation<String,Double>(
+    Annotation<Double> SENTIMENT_ANNOTATION = new Annotation<Double>(
             "stanbol.enhancer.nlp.sentiment", Double.class);
     /**
      * {@link Annotation} representing the Morphological analysis of a word. 
@@ -49,28 +49,28 @@ public interface NlpAnnotations {
      * to be of one of the Tags the definitions of this {@link MorphoFeatures} 
can
      * be applied.
      */
-    Annotation<String,MorphoFeatures> MORPHO_ANNOTATION = new 
Annotation<String,MorphoFeatures>(
+    Annotation<MorphoFeatures> MORPHO_ANNOTATION = new 
Annotation<MorphoFeatures>(
             "stanbol.enhancer.nlp.morpho",MorphoFeatures.class);
 
     /* 
      * Currently only used as part of MorphoFeatures
      */
-//    Annotation<String,CaseTag> CASE_ANNOTATION = new 
Annotation<String,CaseTag>(
+//    Annotation<CaseTag> CASE_ANNOTATION = new Annotation<CaseTag>(
 //            "stanbol.enhancer.nlp.morpho.case",CaseTag.class);
 //
-//    Annotation<String,GenderTag> GENDER_ANNOTATION = new 
Annotation<String,GenderTag>(
+//    Annotation<GenderTag> GENDER_ANNOTATION = new Annotation<GenderTag>(
 //            "stanbol.enhancer.nlp.morpho.gender",GenderTag.class);
 //
-//    Annotation<String,NumberTag> NUMBER_ANNOTATION = new 
Annotation<String,NumberTag>(
+//    Annotation<NumberTag> NUMBER_ANNOTATION = new Annotation<NumberTag>(
 //            "stanbol.enhancer.nlp.morpho.number",NumberTag.class);
 //    
-//    Annotation<String,PersonTag> PERSON_ANNOTATION = new 
Annotation<String,PersonTag>(
+//    Annotation<PersonTag> PERSON_ANNOTATION = new Annotation<PersonTag>(
 //            "stanbol.enhancer.nlp.morpho.person",PersonTag.class);
 //
-//    Annotation<String,TenseTag> TENSE_ANNOTATION = new 
Annotation<String,TenseTag>(
+//    Annotation<TenseTag> TENSE_ANNOTATION = new Annotation<TenseTag>(
 //            "stanbol.enhancer.nlp.morpho.tense",TenseTag.class);
 //
-//    Annotation<String,VerbMoodTag> VERB_MOOD_ANNOTATION = new 
Annotation<String,VerbMoodTag>(
+//    Annotation<VerbMoodTag> VERB_MOOD_ANNOTATION = new 
Annotation<VerbMoodTag>(
 //            "stanbol.enhancer.nlp.morpho.verb-mood",VerbMoodTag.class);
 
 }

Modified: 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/annotation/Annotated.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/annotation/Annotated.java?rev=1430789&r1=1430788&r2=1430789&view=diff
==============================================================================
--- 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/annotation/Annotated.java
 (original)
+++ 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/annotation/Annotated.java
 Wed Jan  9 11:14:45 2013
@@ -1,10 +1,15 @@
 package org.apache.stanbol.enhancer.nlp.model.annotation;
 
 import java.util.List;
+import java.util.Set;
 
 public interface Annotated {
     
-    
+    /**
+     * Getter for all keys used by Annotations
+     * @return the Set with all keys. An empty Set if none
+     */
+    Set<String> getKeys();
 
     /**
      * Method for requesting Values of a given Key. This allows to request
@@ -12,7 +17,7 @@ public interface Annotated {
      * @param key the Key
      * @return the Value with the highest probability
      */
-    Value<?> getValue(Object key);
+    Value<?> getValue(String key);
     
     /**
      * Method for requesting the Value of an Annotation.
@@ -21,7 +26,7 @@ public interface Annotated {
      * @throws ClassCastException if values of {@link Annotation#getKey()} are
      * not of type V
      */
-    <V> Value<V> getAnnotation(Annotation<?,V> annotation);
+    <V> Value<V> getAnnotation(Annotation<V> annotation);
 
     /**
      * Method for requesting Values of a given Key. This allows to request
@@ -29,7 +34,7 @@ public interface Annotated {
      * @param key the Key
      * @return all Value sorted by probability
      */
-    List<Value<?>> getValues(Object key);
+    List<Value<?>> getValues(String key);
     
     /**
      * Method for requesting the Value of an Annotation.
@@ -38,33 +43,71 @@ public interface Annotated {
      * @throws ClassCastException if the returned value of 
      * {@link Annotation#getKey()} is not of type V
      */
-    <V> List<Value<V>> getAnnotations(Annotation<?,V> annotation);
+    <V> List<Value<V>> getAnnotations(Annotation<V> annotation);
     
     /**
      * Appends an Annotation to eventually already existing values 
      * @param annotation the annotation
      * @param value the value to append
      */
-    <K,V> void addAnnotation(Annotation<K,V> annotation, Value<V> value);
+    <V> void addAnnotation(Annotation<V> annotation, Value<V> value);
 
     /**
      * Replaces existing Annotations with the parsed one
      * @param annotation the annotation
      * @param value the value for the annotation
      */
-    <K,V> void setAnnotation(Annotation<K,V> annotation, Value<V> value);
+    <V> void setAnnotation(Annotation<V> annotation, Value<V> value);
     
     /**
+     * Appends an Value to the key. This method is intended for internal use (
+     * e.g. parsers). Users are encouraged to define type save
+     * {@link Annotation} objects and use {@link #addAnnotation(Annotation, 
Value)}
+     * instead. 
+     * @param key the key
+     * @param value the value
+     */
+    void addValue(String key, Value<?> value);
+    /**
+     * Replaces existing Values for a key with the parsed one. This method is 
+     * intended for internal use (e.g. parsers). Users are encouraged to 
define 
+     * type save {@link Annotation} objects and use 
+     * {@link #setAnnotation(Annotation, Value)} instead. 
+     * @param key the key
+     * @param value the value
+     */
+    void setValue(String key, Value<?> value);
+    /**
      * Appends an Annotation to eventually already existing values 
      * @param annotation the annotation
      * @param value the value to append
      */
-    <K,V> void addAnnotations(Annotation<K,V> annotation, List<Value<V>> 
values);
+    <V> void addAnnotations(Annotation<V> annotation, List<Value<V>> values);
 
     /**
      * Replaces existing Annotations with the parsed one
      * @param annotation the annotation
      * @param value the value for the annotation
      */
-    <K,V> void setAnnotations(Annotation<K,V> annotation, List<Value<V>> 
values);
+    <V> void setAnnotations(Annotation<V> annotation, List<Value<V>> values);
+    
+    /**
+     * Appends the parsed values to the key. This method is intended for 
internal use (
+     * e.g. parsers). Users are encouraged to define type save
+     * {@link Annotation} objects and use {@link #addAnnotations(Annotation, 
List)
+     * instead. 
+     * @param key the key
+     * @param value the value
+     */
+    void addValues(String key, List<Value<?>> values);
+    
+    /**
+     * Replaces existing Values for a key with the parsed one. This method is 
+     * intended for internal use (e.g. parsers). Users are encouraged to 
define 
+     * type save {@link Annotation} objects and use 
+     * {@link #setAnnotations(Annotation, List) instead. 
+     * @param key the key
+     * @param value the value
+     */
+    void setValues(String key, List<Value<?>> values);
 }

Modified: 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/annotation/Annotation.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/annotation/Annotation.java?rev=1430789&r1=1430788&r2=1430789&view=diff
==============================================================================
--- 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/annotation/Annotation.java
 (original)
+++ 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/annotation/Annotation.java
 Wed Jan  9 11:14:45 2013
@@ -9,18 +9,18 @@ package org.apache.stanbol.enhancer.nlp.
  * @param <K>
  * @param <V>
  */
-public final class Annotation<K,V> {
+public final class Annotation<V> {
 
     /**
      * The type of the used Key
      */
-    final K key;
+    final String key;
     /**
      * The type of the used Value
      */
     final Class<V> valueType;
     
-    public Annotation(K key,Class<V> valueType){
+    public Annotation(String key,Class<V> valueType){
         if(key == null || key == null){
             throw new IllegalArgumentException("Key and Value MUST NOT be 
NULL!");
         }
@@ -28,7 +28,7 @@ public final class Annotation<K,V> {
         this.valueType = valueType;
     }
  
-    public K getKey(){
+    public String getKey(){
         return key;
     }
     

Modified: 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/impl/AnnotatedImpl.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/impl/AnnotatedImpl.java?rev=1430789&r1=1430788&r2=1430789&view=diff
==============================================================================
--- 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/impl/AnnotatedImpl.java
 (original)
+++ 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/model/impl/AnnotatedImpl.java
 Wed Jan  9 11:14:45 2013
@@ -5,6 +5,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.stanbol.enhancer.nlp.model.annotation.Annotated;
 import org.apache.stanbol.enhancer.nlp.model.annotation.Annotation;
@@ -12,11 +13,15 @@ import org.apache.stanbol.enhancer.nlp.m
 
 public class AnnotatedImpl implements Annotated{
 
-    private Map<Object,Object> annotations;
+    private Map<String,Object> annotations;
     
+    @SuppressWarnings("unchecked")
+    public Set<String> getKeys(){
+        return annotations == null ? Collections.EMPTY_SET : 
annotations.keySet();
+    }
     
     @Override
-    public final Value<?> getValue(Object key) {
+    public final Value<?> getValue(String key) {
         if(annotations == null){
             return null;
         }
@@ -31,7 +36,7 @@ public class AnnotatedImpl implements An
     }
     @SuppressWarnings("unchecked")
     @Override
-    public final List<Value<?>> getValues(Object key) {
+    public final List<Value<?>> getValues(String key) {
         if(annotations == null){
             return Collections.emptyList();
         }
@@ -47,7 +52,7 @@ public class AnnotatedImpl implements An
     }
     @SuppressWarnings("unchecked")
     @Override
-    public final <V> Value<V> getAnnotation(Annotation<?,V> annotation) {
+    public final <V> Value<V> getAnnotation(Annotation<V> annotation) {
         if(annotations == null){
             return null;
         }
@@ -63,7 +68,7 @@ public class AnnotatedImpl implements An
     
     @SuppressWarnings("unchecked")
     @Override
-    public final <V> List<Value<V>> getAnnotations(Annotation<?,V> annotation) 
{
+    public final <V> List<Value<V>> getAnnotations(Annotation<V> annotation) {
         if(annotations == null){
             return Collections.emptyList();
         }
@@ -79,12 +84,24 @@ public class AnnotatedImpl implements An
     }
     
     @Override
-    public <K,V> void addAnnotations(Annotation<K,V> annotation, 
List<Value<V>> values) {
+    public <V> void addAnnotations(Annotation<V> annotation, List<Value<V>> 
values) {
+        addValuesInternal(annotation.getKey(), values);
+    }
+    @Override
+    public void addValues(String key, List<Value<?>> values) {
+        addValuesInternal(key, values);
+    }
+    /**
+     * Just here because of Java generics combined with Collections ...
+     * @param key
+     * @param values
+     */
+    private void addValuesInternal(String key, List<?> values) {
         if(values == null || values.isEmpty()){
             return;
         }
-        Map<Object, Object> map = initAnnotations();
-        Object currentValue = annotations.get(annotation.getKey());
+        Map<String, Object> map = initAnnotations();
+        Object currentValue = annotations.get(key);
         Object newValues;
         if(currentValue == null){
             if(values.size() == 1){
@@ -97,8 +114,8 @@ public class AnnotatedImpl implements An
             newValues = new Value<?>[values.size()+1];
             ((Value<?>[])newValues)[0] = (Value<?>)currentValue;
             int index = 1;
-            for(Value<V> value : values){
-                ((Value<?>[])newValues)[index] = value;
+            for(Object value : values){
+                ((Value<?>[])newValues)[index] = (Value<?>)value;
                 index++;
             }
             Arrays.sort((Value<?>[])newValues,Value.PROBABILITY_COMPARATOR);
@@ -106,68 +123,87 @@ public class AnnotatedImpl implements An
             int length = ((Value<?>[])currentValue).length;
             newValues = new Value<?>[values.size()+length];
             System.arraycopy(currentValue, 0, newValues, 0, length);
-            for(Value<V> value : values){
-                ((Value<?>[])newValues)[length] = value;
+            for(Object value : values){
+                ((Value<?>[])newValues)[length] = (Value<?>)value;
                 length++;
             }
             Arrays.sort((Value<?>[])newValues,Value.PROBABILITY_COMPARATOR);
         }
-        map.put(annotation.getKey(), newValues);
+        map.put(key, newValues);
+    }
+    @Override
+    public <V> void setAnnotations(Annotation<V> annotation, List<Value<V>> 
values) {
+        setValuesInternal(annotation.getKey(),values);
     }
     @Override
-    public <K,V> void setAnnotations(Annotation<K,V> annotation, 
List<Value<V>> value) {
-        Map<Object, Object> map = initAnnotations();
-        if(value == null || value.isEmpty()){
-            map.remove(annotation.getKey());
-        } else if(value.size() == 1){
-            map.put(annotation.getKey(), value.get(0));
+    public void setValues(String key, List<Value<?>> values){
+        setValuesInternal(key, values);
+    }
+    /**
+     * Just here because of Java generics combined with Collections ...
+     * @param key
+     * @param values
+     */
+    private void setValuesInternal(String key, List<?> values){
+        Map<String, Object> map = initAnnotations();
+        if(values == null || values.isEmpty()){
+            map.remove(key);
+        } else if(values.size() == 1){
+            map.put(key, values.get(0));
         } else {
             //we need to copy, because users might change the parsed Array!
-            Value<?>[] copy = value.toArray(new Value<?>[value.size()]);
+            Value<?>[] copy = values.toArray(new Value<?>[values.size()]);
             Arrays.sort(copy,Value.PROBABILITY_COMPARATOR);
-            map.put(annotation.getKey(),copy);
+            map.put(key,copy);
         }
         
     }
     
-    private Map<Object,Object> initAnnotations(){
+    private Map<String,Object> initAnnotations(){
         if(annotations == null){ //avoid sync for the typical case
-            annotations = new HashMap<Object,Object>();
+            annotations = new HashMap<String,Object>();
         }
         return annotations;
     }
     @Override
-    public <K,V> void addAnnotation(Annotation<K,V> annotation, Value<V> 
value) {
+    public <V> void addAnnotation(Annotation<V> annotation, Value<V> value) {
+        addValue(annotation.getKey(), value);
+    }
+    @Override
+    public void addValue(String key, Value<?> value) {
         if(value != null){
-          Map<Object,Object> map = initAnnotations();  
-          Object currentValue = map.get(annotation);
+          Map<String,Object> map = initAnnotations();  
+          Object currentValue = map.get(key);
           if(currentValue == null){
-              map.put(annotation.getKey(), value);
-          } else if (value instanceof Value<?>){
+              map.put(key, value);
+          } else if (currentValue instanceof Value<?>){
               Value<?>[] newValues =  new 
Value<?>[]{(Value<?>)currentValue,value};
               Arrays.sort(newValues,Value.PROBABILITY_COMPARATOR);
-              map.put(annotation.getKey(), newValues);
+              map.put(key, newValues);
           } else { //array
               int length = ((Value<?>[])currentValue).length;
               Value<?>[] newValues = new Value<?>[length+1];
               System.arraycopy(currentValue, 0, newValues, 0, length);
               newValues[length] = value;
               Arrays.sort(newValues,Value.PROBABILITY_COMPARATOR);
-              map.put(annotation.getKey(), newValues);
+              map.put(key, newValues);
           }
         } 
     }
     @Override
-    public <K,V> void setAnnotation(Annotation<K,V> annotation, Value<V> 
value) {
+    public <V> void setAnnotation(Annotation<V> annotation, Value<V> value) {
+        setValue(annotation.getKey(), value);
+    }
+    @Override
+    public void setValue(String key, Value<?> value) {
         if(annotations == null && value == null){
             return;
         }
-        Map<Object,Object> map = initAnnotations();
+        Map<String,Object> map = initAnnotations();
         if(value == null){
-            map.remove(annotation.getKey());
+            map.remove(key);
         } else {
-            map.put(annotation.getKey(),value);
+            map.put(key,value);
         }
-        
     }
 }

Modified: 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/pos/PosTag.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/pos/PosTag.java?rev=1430789&r1=1430788&r2=1430789&view=diff
==============================================================================
--- 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/pos/PosTag.java
 (original)
+++ 
stanbol/trunk/enhancer/generic/nlp/src/main/java/org/apache/stanbol/enhancer/nlp/pos/PosTag.java
 Wed Jan  9 11:14:45 2013
@@ -1,6 +1,7 @@
 package org.apache.stanbol.enhancer.nlp.pos;
 
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.Set;
@@ -33,18 +34,18 @@ public class PosTag extends Tag<PosTag>{
      * NOTE: NULL if {@link #pos} is empty!
      */
     private final Set<Pos> posHierarchy;
-//    /**
-//     * Creates a new POS tag for the parsed tag. The created Tag is not
-//     * assigned to any {@link LexicalCategory}.<p> This constructor can be 
used
-//     * by {@link EnhancementEngine}s that encounter an Tag they do not know 
-//     * (e.g. that is not defined by the configured {@link TagSet}).<p>
-//     * @param tag the Tag
-//     * @throws IllegalArgumentException if the parsed tag is 
<code>null</code>
-//     * or empty.
-//     */
-//    public PosTag(String tag){
-//        this(tag,(LexicalCategory)null);
-//    }
+    /**
+     * Creates a new POS tag for the parsed tag. The created Tag is not
+     * assigned to any {@link LexicalCategory}.<p> This constructor can be used
+     * by {@link EnhancementEngine}s that encounter an Tag they do not know 
+     * (e.g. that is not defined by the configured {@link TagSet}).<p>
+     * @param tag the Tag
+     * @throws IllegalArgumentException if the parsed tag is <code>null</code>
+     * or empty.
+     */
+    public PosTag(String tag){
+        this(tag,(LexicalCategory[])null);
+    }
     /**
      * Creates a PosTag that is assigned to a {@link LexicalCategory}
      * @param tag the tag
@@ -70,43 +71,39 @@ public class PosTag extends Tag<PosTag>{
      * or empty.
      */
     public PosTag(String tag,Pos pos,Pos...furtherPos){
-        this(tag, null,pos,furtherPos);
+        this(tag, EnumSet.noneOf(LexicalCategory.class), 
EnumSet.of(pos,furtherPos), false);
     }
     
     public PosTag(String tag,LexicalCategory category, Pos 
pos,Pos...furtherPos){
+        this(tag,category == null ? EnumSet.noneOf(LexicalCategory.class) : 
EnumSet.of(category),
+                EnumSet.of(pos,furtherPos),false);
+    }
+    public PosTag(String tag,Collection<LexicalCategory> categories, 
Collection<Pos> pos){
+        this(tag,categories,pos,true);
+    }
+    public PosTag(String tag,Collection<LexicalCategory> categories, 
Collection<Pos> pos, boolean copy){
         super(tag);
-        if(pos != null){
-            if(furtherPos == null || furtherPos.length < 1){
-                this.pos = Collections.singleton(pos);
-                this.posHierarchy = pos.hierarchy();
-                if(category == null){
-                    this.category = pos.categories();
-                } else {
-                    this.category = EnumSet.of(category);
-                    this.category.addAll(pos.categories());
-                }
-            } else { // in case of multiple Pos Tags
-                this.pos = EnumSet.of(pos,furtherPos);
-                //we need to collect categories
-                this.category = category == null ? 
-                        EnumSet.noneOf(LexicalCategory.class) :
-                            EnumSet.of(category);
-                //and the union over the pos parents
-                this.posHierarchy = EnumSet.noneOf(Pos.class);
-                for(Pos p : this.pos){
-                    this.posHierarchy.addAll(p.hierarchy());
-                    this.category.addAll(p.categories());
-                }
+        if(copy){
+            this.pos = EnumSet.noneOf(Pos.class);
+            if(pos != null){
+                this.pos.addAll(pos);
             }
         } else {
-            if(furtherPos != null && furtherPos.length > 0){
-                throw new IllegalArgumentException("furtherPos parameter MUST 
BE NULL "
-                    + "or empty if the pos parameter is NULL!");
+            this.pos = (EnumSet<Pos>)pos;
+        }
+        if(copy){
+            this.category = EnumSet.noneOf(LexicalCategory.class);
+            if(categories != null){
+                this.category.addAll(categories);
             }
-            this.category = category == null ? 
-                    Collections.EMPTY_SET : Collections.singleton(category);
-            this.pos = Collections.emptySet();
-            this.posHierarchy = Collections.emptySet();
+        } else {
+            this.category = (EnumSet<LexicalCategory>)categories;
+        }
+        //and the union over the pos parents
+        this.posHierarchy = EnumSet.noneOf(Pos.class);
+        for(Pos p : this.pos){
+            this.posHierarchy.addAll(p.hierarchy());
+            this.category.addAll(p.categories());
         }
     }
     /**

Modified: 
stanbol/trunk/enhancer/generic/nlp/src/test/java/org/apache/stanbol/enhancer/nlp/model/AnalysedTextTest.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/nlp/src/test/java/org/apache/stanbol/enhancer/nlp/model/AnalysedTextTest.java?rev=1430789&r1=1430788&r2=1430789&view=diff
==============================================================================
--- 
stanbol/trunk/enhancer/generic/nlp/src/test/java/org/apache/stanbol/enhancer/nlp/model/AnalysedTextTest.java
 (original)
+++ 
stanbol/trunk/enhancer/generic/nlp/src/test/java/org/apache/stanbol/enhancer/nlp/model/AnalysedTextTest.java
 Wed Jan  9 11:14:45 2013
@@ -1,8 +1,5 @@
 package org.apache.stanbol.enhancer.nlp.model;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertTrue;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -16,8 +13,6 @@ import java.util.List;
 import java.util.Map.Entry;
 import java.util.Set;
 
-import junit.framework.Assert;
-
 import org.apache.clerezza.rdf.core.UriRef;
 import 
org.apache.stanbol.enhancer.contentitem.inmemory.InMemoryContentItemFactory;
 import org.apache.stanbol.enhancer.nlp.model.Span.SpanTypeEnum;
@@ -28,6 +23,7 @@ import org.apache.stanbol.enhancer.servi
 import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
 import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
 import org.apache.stanbol.enhancer.servicesapi.impl.StringSource;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -48,8 +44,8 @@ public class AnalysedTextTest {
             "disambiguation it would even be able to detect the Comedian " +
             "Bob Marley trafeling to Paris in Texas.";
     
-    public static final Annotation<String,Number> testAnnotation = 
-            new Annotation<String,Number>("test", Number.class);
+    public static final Annotation<Number> testAnnotation = 
+            new Annotation<Number>("test", Number.class);
     
     /* -----
      * Test data creates within the BeforeClass
@@ -244,8 +240,8 @@ public class AnalysedTextTest {
             end = endPos[s]*sentenceLength;
             Sentence sent = at.addSentence(start, end);
             log.info("add {}",sent);
-            assertEquals(start, sent.getStart());
-            assertEquals(end, sent.getEnd());
+            Assert.assertEquals(start, sent.getStart());
+            Assert.assertEquals(end, sent.getEnd());
             sentences.add(sent);
         }
         //1.b iterate over the sentences while adding Chunks and Tokens to
@@ -261,8 +257,8 @@ public class AnalysedTextTest {
                 log.info("  add {}",chunk);
                 start = sent.getStart() + start;
                 end = sent.getStart() + end;
-                assertEquals(start, chunk.getStart());
-                assertEquals(end, chunk.getEnd());
+                Assert.assertEquals(start, chunk.getStart());
+                Assert.assertEquals(end, chunk.getEnd());
                 chunks.add(chunk);
                 for(int t=0;t<startPos.length;t++){
                     start = startPos[t]*tokenLength;
@@ -271,8 +267,8 @@ public class AnalysedTextTest {
                     log.info("    add {}",token);
                     start = chunk.getStart() + start;
                     end = chunk.getStart() + end;
-                    assertEquals(start, token.getStart());
-                    assertEquals(end, token.getEnd());
+                    Assert.assertEquals(start, token.getStart());
+                    Assert.assertEquals(end, token.getEnd());
                     tokens.add(token);
                 }
             }
@@ -288,30 +284,30 @@ public class AnalysedTextTest {
         log.info("--- iterating over Spans ---");
         log.info("{}",at);
         for(;sentIt.hasNext();s++){
-            assertTrue(sentences.size()+" Sentences Expected (found: 
"+(s+1)+")",s < sentences.size());
+            Assert.assertTrue(sentences.size()+" Sentences Expected (found: 
"+(s+1)+")",s < sentences.size());
             Sentence sent = sentIt.next();
             log.info("  {}",sent);
-            assertEquals(sentences.get(s), sent);
+            Assert.assertEquals(sentences.get(s), sent);
             Iterator<Chunk> chunkIt = sent.getChunks();
             int foundChunks = 0;
             for(;chunkIt.hasNext();c++){
-                assertTrue(chunks.size()+" Chunks Expected (found: 
"+(c+1)+")",c < chunks.size());
+                Assert.assertTrue(chunks.size()+" Chunks Expected (found: 
"+(c+1)+")",c < chunks.size());
                 Chunk chunk = chunkIt.next();
                 log.info("    {}",chunk);
-                assertEquals(chunks.get(c), chunk);
+                Assert.assertEquals(chunks.get(c), chunk);
                 Iterator<Token> tokenIt = chunk.getTokens();
                 int foundTokens = 0;
                 for(;tokenIt.hasNext();t++){
-                    assertTrue(tokens.size()+" Tokens Expected (found: 
"+(t+1)+")",t < tokens.size());
+                    Assert.assertTrue(tokens.size()+" Tokens Expected (found: 
"+(t+1)+")",t < tokens.size());
                     Token token = tokenIt.next();
                     log.info("      {}",token);
-                    assertEquals(tokens.get(t), token);
+                    Assert.assertEquals(tokens.get(t), token);
                     foundTokens++;
                 }
-                assertEquals(tokensInChunk+" Tokens expected in Chunk", 
tokensInChunk,foundTokens);
+                Assert.assertEquals(tokensInChunk+" Tokens expected in Chunk", 
tokensInChunk,foundTokens);
                 foundChunks++;
             }
-            assertEquals(chunksInSentence+" Chunks expected in Sentence", 
chunksInSentence,foundChunks);
+            Assert.assertEquals(chunksInSentence+" Chunks expected in 
Sentence", chunksInSentence,foundChunks);
             //also iterate over tokens within a sentence
             log.info("  {}",sent);
             Iterator<Token> tokenIt = sent.getTokens();
@@ -319,13 +315,13 @@ public class AnalysedTextTest {
             for(;tokenIt.hasNext();foundTokens++){
                 Token token = tokenIt.next();
                 log.info("    {}",token);
-                assertEquals(tokens.get(s*tokensInSentence+foundTokens), 
token);
+                
Assert.assertEquals(tokens.get(s*tokensInSentence+foundTokens), token);
             }
-            assertEquals(tokensInSentence+" Tokens expected in Sentence", 
tokensInSentence,foundTokens);
+            Assert.assertEquals(tokensInSentence+" Tokens expected in 
Sentence", tokensInSentence,foundTokens);
         }
-        assertEquals(sentences.size()+" Sentences Expected (found: "+s+")", 
sentences.size(),s);
-        assertEquals(chunks.size()+" Chunks Expected (found: "+c+")", 
chunks.size(),c);
-        assertEquals(tokens.size()+" Sentences Expected (found: "+t+")", 
tokens.size(),t);
+        Assert.assertEquals(sentences.size()+" Sentences Expected (found: 
"+s+")", sentences.size(),s);
+        Assert.assertEquals(chunks.size()+" Chunks Expected (found: "+c+")", 
chunks.size(),c);
+        Assert.assertEquals(tokens.size()+" Sentences Expected (found: 
"+t+")", tokens.size(),t);
         //also iterate over Chunks in AnalysedText
         Iterator<Chunk> chunkIt = at.getChunks();
         int foundChunks = 0;
@@ -333,9 +329,9 @@ public class AnalysedTextTest {
         for(;chunkIt.hasNext();foundChunks++){
             Chunk chunk = chunkIt.next();
             log.info("  {}",chunk);
-            assertEquals(chunks.get(foundChunks), chunk);
+            Assert.assertEquals(chunks.get(foundChunks), chunk);
         }
-        assertEquals(chunks.size()+" Chunks expected in AnalysedText", 
chunks.size(),foundChunks);
+        Assert.assertEquals(chunks.size()+" Chunks expected in AnalysedText", 
chunks.size(),foundChunks);
         //also iterate over Tokens in AnalysedText
         Iterator<Token> tokenIt = at.getTokens();
         int foundTokens = 0;
@@ -343,9 +339,9 @@ public class AnalysedTextTest {
         for(;tokenIt.hasNext();foundTokens++){
             Token token = tokenIt.next();
             log.info("  {}",token);
-            assertEquals(tokens.get(foundTokens), token);
+            Assert.assertEquals(tokens.get(foundTokens), token);
         }
-        assertEquals(tokens.size()+" Tokens expected in AnalysedText", 
tokens.size(),foundTokens);
+        Assert.assertEquals(tokens.size()+" Tokens expected in AnalysedText", 
tokens.size(),foundTokens);
 
       //Finally iterate over multiple token types
       Iterator<Span> sentencesAndChunks = at.getEnclosed(
@@ -357,17 +353,17 @@ public class AnalysedTextTest {
           Span span = sentencesAndChunks.next();
           log.info("  {}",span);
           if(span.getType() == SpanTypeEnum.Chunk){
-              assertEquals(chunks.get(c), span);
+              Assert.assertEquals(chunks.get(c), span);
               c++;
           } else if(span.getType() == SpanTypeEnum.Sentence){
-              assertEquals(sentences.get(s), span);
+              Assert.assertEquals(sentences.get(s), span);
               s++;
           } else {
               Assert.fail("Unexpected SpanType '"+span.getType()+" (Span: 
"+span.getClass()+")");
           }
       }
-      assertEquals(sentences.size()+" Sentences expected in AnalysedText", 
sentences.size(),s);
-      assertEquals((sentences.size()*chunksInSentence)+" Chunks expected in 
AnalysedText", 
+      Assert.assertEquals(sentences.size()+" Sentences expected in 
AnalysedText", sentences.size(),s);
+      Assert.assertEquals((sentences.size()*chunksInSentence)+" Chunks 
expected in AnalysedText", 
           (sentences.size()*chunksInSentence),c);
     }
     
@@ -380,21 +376,21 @@ public class AnalysedTextTest {
         values.add(new Value<Number>(25.0,0.8));
         at.addAnnotations(testAnnotation, values);
         Value<Number> value = at.getAnnotation(testAnnotation);
-        assertNotNull(value);
-        assertEquals(Double.valueOf(25.0), value.value());
-        assertEquals(0.8d, value.probability());
+        Assert.assertNotNull(value);
+        Assert.assertEquals(Double.valueOf(25.0), value.value());
+        Assert.assertEquals(0.8d, value.probability(), 0.0d);
         Number prev = Float.valueOf(24f);
         for(Value<Number> v : at.getAnnotations(testAnnotation)){
-            assertNotNull(v);
-            assertTrue(v.value().doubleValue() > prev.doubleValue());
+            Assert.assertNotNull(v);
+            Assert.assertTrue(v.value().doubleValue() > prev.doubleValue());
             prev = v.value();
         }
         //check that the order of Annotations without probability is kept
         at.addAnnotation(testAnnotation, new Value<Number>(29));
         prev = Integer.valueOf(24);
         for(Value<Number> v : at.getAnnotations(testAnnotation)){
-            assertNotNull(v);
-            assertTrue(v.value().intValue() > prev.intValue());
+            Assert.assertNotNull(v);
+            Assert.assertTrue(v.value().intValue() > prev.intValue());
             prev = v.value();
         }
         


Reply via email to