You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@opennlp.apache.org by Jörn Kottmann <ko...@gmail.com> on 2014/05/13 09:23:35 UTC

Re: svn commit: r1594063 - in /opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools: entitylinker/EntityLinker.java entitylinker/LinkedSpan.java namefind/NameFinderME.java namefind/TokenNameFinder.java sentdetect/SentenceDetectorME.java util/Span.java

Hello,

Span is an immutable object, the set prob method should return a new 
Span object
instead of modifying it.

Jörn

On 05/12/2014 09:20 PM, markg@apache.org wrote:
> Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
> URL:http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/Span.java?rev=1594063&r1=1594062&r2=1594063&view=diff
> ==============================================================================
> --- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/Span.java (original)
> +++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/Span.java Mon May 12 19:20:41 2014
> @@ -26,7 +26,7 @@ public class Span implements Comparable<
>   
>     private final int start;
>     private final int end;
> -
> +  private double prob=0d;//default is 0
>     private final String type;
>   
>     /**
> @@ -53,7 +53,24 @@ public class Span implements Comparable<
>       end = e;
>       this.type = type;
>     }
> + public Span(int s, int e, String type, double prob) {
> +
> +    if (s < 0) {
> +      throw new IllegalArgumentException("start index must be zero or greater: " + s);
> +    }
> +    if (e < 0) {
> +      throw new IllegalArgumentException("end index must be zero or greater: " + e);
> +    }
> +    if (s > e) {
> +      throw new IllegalArgumentException("start index must not be larger than end index: " +
> +          "start=" + s + ", end=" + e);
> +    }
>   
> +    start = s;
> +    end = e;
> +    this.prob=prob;
> +    this.type = type;
> +  }
>     /**
>      * Initializes a new Span Object.
>      *
> @@ -72,7 +89,7 @@ public class Span implements Comparable<
>      * @param offset
>      */
>     public Span(Span span, int offset) {
> -    this(span.start + offset, span.end + offset, span.getType());
> +    this(span.start + offset, span.end + offset, span.getType(), span.getProb());
>     }
>   
>     /**
> @@ -355,4 +372,12 @@ public class Span implements Comparable<
>       }
>       return chunks;
>     }
> +
> +  public double getProb() {
> +    return prob;
> +  }
> +
> +  public void setProb(double prob) {
> +    this.prob = prob;
> +  }