You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@opennlp.apache.org by James Kosin <ja...@gmail.com> on 2011/09/21 05:46:44 UTC

Silly Question

Okay, it is late... so my brain cells may not be working correctly.

But, in Spans:
>   /**
>    * Returns the length of this span.
>    *
>    * @return the length of the span.
>    */
>   public int length() {
>     return end-start;
>   }

This means one of the endpoints in the span don't attribute to the
length of the span.  Is this correct?  Does this mean a span with a
start and end say at 1,1 has no length?  Or is it suppose to be 1?

I have similar problems when counting the number of locations to fill
for a memory block when doing (end - start) type arithmetic.  What
happens is the length ends up being one short.

Thanks,
James

Re: Silly Question

Posted by Jörn Kottmann <ko...@gmail.com>.
On 9/28/11 12:22 AM, william.colen@gmail.com wrote:
> Today the toString() method of Span is not printing the span type. Should we
> include this information?

+1, toString is mostly a debugging tool, so it would make sense to show 
this information.

Jörn


Re: Silly Question

Posted by "william.colen@gmail.com" <wi...@gmail.com>.
Today the toString() method of Span is not printing the span type. Should we
include this information?

On Fri, Sep 23, 2011 at 4:33 AM, Jörn Kottmann <ko...@gmail.com> wrote:

> On 9/23/11 2:19 AM, James Kosin wrote:
>
>> Would it be okay to define the toString() method to return the
>> mathmatical representation of the actual span?
>> example output:  [0..7)
>> To show the span contains 0 as one of the endpoints and does not include
>> 7.
>>
>
> Currently it is 0..7, right?
>
> I think that would be fine, but please do a quick search prior
> to check that no code is relying on the current format.
>
> Jörn
>

Re: Silly Question

Posted by Jörn Kottmann <ko...@gmail.com>.
On 9/23/11 2:19 AM, James Kosin wrote:
> Would it be okay to define the toString() method to return the
> mathmatical representation of the actual span?
> example output:  [0..7)
> To show the span contains 0 as one of the endpoints and does not include 7.

Currently it is 0..7, right?

I think that would be fine, but please do a quick search prior
to check that no code is relying on the current format.

Jörn

Re: Silly Question

Posted by James Kosin <ja...@gmail.com>.
On 9/22/2011 7:03 PM, Jörn Kottmann wrote:
> On 9/23/11 12:52 AM, James Kosin wrote:
>> Yes, that makes better sense... unfortunately, if the user uses the
>> getStart() and getEnd() methods for a Span and tried to use those
>> numbers it may add even more confusion; since the getEnd() returns one
>> past the last index in the span.
>> Maybe we should refactor the Span class to clarify the proper usage...
>> or provide better documentation.
>
> As far as I know it is quite common to define a range as we did. There
> are a couple
> of other APIs I know of which do it the same way.
>
> +1 to improve the documentation.
>
> Jörn
>
Would it be okay to define the toString() method to return the
mathmatical representation of the actual span?
example output:  [0..7)
To show the span contains 0 as one of the endpoints and does not include 7.

James

Re: Silly Question

Posted by Jörn Kottmann <ko...@gmail.com>.
On 9/23/11 12:52 AM, James Kosin wrote:
> Yes, that makes better sense... unfortunately, if the user uses the
> getStart() and getEnd() methods for a Span and tried to use those
> numbers it may add even more confusion; since the getEnd() returns one
> past the last index in the span.
> Maybe we should refactor the Span class to clarify the proper usage...
> or provide better documentation.

As far as I know it is quite common to define a range as we did. There 
are a couple
of other APIs I know of which do it the same way.

+1 to improve the documentation.

Jörn


Re: Silly Question

Posted by James Kosin <ja...@gmail.com>.
On 9/22/2011 6:12 PM, Jörn Kottmann wrote:
> On 9/22/11 2:17 AM, James Kosin wrote:
>>    public boolean contains(int index) {
>>      return start<= index&&  index<= end;
>>    }
>>
>> The first is okay, but the second definition is a bit odd; since, the
>> end is included as part of the span when using index as an input.  Is
>> this correct?
>>
>
> Good catch, doesn't make sense to me. It should only return true for
> indexes
> which point to elements which are included in the span, right?
>
> Jörn
Yes, that makes better sense... unfortunately, if the user uses the
getStart() and getEnd() methods for a Span and tried to use those
numbers it may add even more confusion; since the getEnd() returns one
past the last index in the span.
Maybe we should refactor the Span class to clarify the proper usage...
or provide better documentation.

James

Re: Silly Question

Posted by Jörn Kottmann <ko...@gmail.com>.
On 9/22/11 2:17 AM, James Kosin wrote:
>    public boolean contains(int index) {
>      return start<= index&&  index<= end;
>    }
>
> The first is okay, but the second definition is a bit odd; since, the
> end is included as part of the span when using index as an input.  Is
> this correct?
>

Good catch, doesn't make sense to me. It should only return true for indexes
which point to elements which are included in the span, right?

Jörn

Re: Silly Question

Posted by James Kosin <ja...@gmail.com>.
On 9/21/2011 4:58 PM, Jörn Kottmann wrote:
> On 9/21/11 5:46 AM, James Kosin wrote:
>> This means one of the endpoints in the span don't attribute to the
>> length of the span.  Is this correct?  Does this mean a span with a
>> start and end say at 1,1 has no length?  Or is it suppose to be 1?
>>
>> I have similar problems when counting the number of locations to fill
>> for a memory block when doing (end - start) type arithmetic.  What
>> happens is the length ends up being one short.
>
> Usually we have an array of items, or a list. The start index is
> always the
> item itself, e.g. 0 means the span begins just at the first item. The end
> index is always the index of the item after the last item in the span.
>
> So if you have just an array of length one, and want to define a span
> which covers it, it would be start=0 and end=1 that results in
> end-start=1.
>
> Jörn
>
The only problem is we define:
>   /**
>    * Returns true if the specified span is contained by this span.
>    * Identical spans are considered to contain each other.
>    *
>    * @param s The span to compare with this span.
>    *
>    * @return true is the specified span is contained by this span;
>    * false otherwise.
>    */
>   public boolean contains(Span s) {
>     return start <= s.getStart() && s.getEnd() <= end;
>   }
>
>   public boolean contains(int index) {
>     return start <= index && index <= end;
>   }
>
The first is okay, but the second definition is a bit odd; since, the
end is included as part of the span when using index as an input.  Is
this correct?


Re: Silly Question

Posted by Jörn Kottmann <ko...@gmail.com>.
On 9/21/11 5:46 AM, James Kosin wrote:
> This means one of the endpoints in the span don't attribute to the
> length of the span.  Is this correct?  Does this mean a span with a
> start and end say at 1,1 has no length?  Or is it suppose to be 1?
>
> I have similar problems when counting the number of locations to fill
> for a memory block when doing (end - start) type arithmetic.  What
> happens is the length ends up being one short.

Usually we have an array of items, or a list. The start index is always the
item itself, e.g. 0 means the span begins just at the first item. The end
index is always the index of the item after the last item in the span.

So if you have just an array of length one, and want to define a span
which covers it, it would be start=0 and end=1 that results in end-start=1.

Jörn


Re: Silly Question

Posted by James Kosin <ja...@gmail.com>.
Never mind, I see the light now.

On 9/20/2011 11:46 PM, James Kosin wrote:
> Okay, it is late... so my brain cells may not be working correctly.
>
> But, in Spans:
>>   /**
>>    * Returns the length of this span.
>>    *
>>    * @return the length of the span.
>>    */
>>   public int length() {
>>     return end-start;
>>   }
> This means one of the endpoints in the span don't attribute to the
> length of the span.  Is this correct?  Does this mean a span with a
> start and end say at 1,1 has no length?  Or is it suppose to be 1?
>
> I have similar problems when counting the number of locations to fill
> for a memory block when doing (end - start) type arithmetic.  What
> happens is the length ends up being one short.
>
> Thanks,
> James