You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by "Stergos D. Afantenos" <st...@gmail.com> on 2008/06/19 17:00:06 UTC

REST sandbox component and spans

Hi,

I am using the REST sandbox component in order to publish a UIMA
annotator as a Web Service. Nevertheless, when I am trying to set the
spans for a jCas the Web Service returns a nasty exception (index out
of bounds for a string, which is actually thrown from the
getCoveredText() of the Annotation class).

Now, I do make explicitly sure that the Begin and End that I give to
the annotation are not bigger than the underlying CAS's text, and my
code runs smoothly if I run it normally (without being a Web Service).
In addition, the Web Service runs smoothly as well if leave the spans
alone, but in this case the start and end are 0, unfortunately.

Has anybody else experienced the same kind of problem? Is this a bug
on the REST sandbox component or maybe I have entirely missed
something important?

Thanks in advance,
Stergos.

Re: REST sandbox component and spans

Posted by "Stergos D. Afantenos" <st...@univ-nantes.fr>.
Thank you very much Thilo. I'll check this out and I'll keep you informed.

Thanks again,
Stergos.

On Thu, Jun 19, 2008 at 6:41 PM, Thilo Goetz <tw...@gmx.de> wrote:
> Hi Stergos,
>
> it looks to me like you're setting either the start or
> the end position to a negative value somewhere.  You
> won't notice this in a normal application because nobody
> accesses those values, hence no exceptions.  The service,
> on the other hand, explicitly accesses those values and
> will barf if it finds negative ones.
>
> You can inspect your offsets by running your app in CVD
> or DocumentAnalyzer, or by printing out the results
> manually.  If you have a JCas, you can do this:
>
>    FSIterator it = aJCas.getAnnotationIndex(Annotation.type).iterator();
>    while (it.hasNext()) {
>      Annotation annot = (Annotation) it.next();
>      System.out.println(annot.getType() + ":" + annot.getBegin() + ":" +
> annot.getEnd());
>    }
>
> I didn't test this, but something like this should work.
> Hope this helps.
>
> --Thilo
>
> Stergos D. Afantenos wrote:
>>
>> Dear Thilo,
>>
>>> we'll need more information to be able to help,
>>> the stack trace of the exception for one.
>>
>> Here is the stack trace :
>>
>> java.lang.StringIndexOutOfBoundsException: String index out of range: -1
>>        java.lang.String.substring(String.java:1932)
>>
>>  org.apache.uima.jcas.tcas.Annotation.getCoveredText(Annotation.java:119)
>>
>>  org.apache.uima.simpleserver.ResultExtractor.makeOutputs(ResultExtractor.java:176)
>>
>>  org.apache.uima.simpleserver.ResultExtractor.outputAll(ResultExtractor.java:158)
>>
>>  org.apache.uima.simpleserver.ResultExtractor.processTypes(ResultExtractor.java:111)
>>
>>  org.apache.uima.simpleserver.ResultExtractor.getResult(ResultExtractor.java:105)
>>        org.apache.uima.simpleserver.Service.process(Service.java:262)
>>
>>  org.apache.uima.simpleserver.servlet.SimpleServerServlet.analyze(SimpleServerServlet.java:204)
>>
>>  org.apache.uima.simpleserver.servlet.SimpleServerServlet.doPost(SimpleServerServlet.java:183)
>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>>
>>> Also,
>>> I do not understand what you mean when you say
>>> "I am trying to set the spans for a jCas".
>>
>> Of course. I realized my error once I had already sent the email, so
>> it was rather late to change it. What I meant to say is that I am
>> trying to set the spans of *an annotation* that is found inside a
>> JCas. So here is the piece code which causes me headaches:
>>
>>
>> String docText = aJCas.getDocumentText();
>>
>> String[] splittedLine = line.split(":");
>> int start = Integer.parseInt(splittedLine[0]) - 1;
>> if (start >= docText.length()) start = docText.length() - 1;
>> int end = Integer.parseInt(splittedLine[1]) - 1;
>> if (end >= docText.length()) end = docText.length() - 1;
>> NemesisNE annotationNemesis = new NemesisNE(aJCas);
>> annotationNemesis.setBegin(start);
>> annotationNemesis.setEnd(end);
>>  // adition of other attributes to annotationNemesis
>> annotationNemesis.addToIndexes();
>>
>> where the variable line is a ":" separated String whose first element
>> is the span start of the annotation that I am currently treating and
>> second element is the span end of the annotation that I am currently
>> treating.  In addition NemesisNE is a class that I have defined in the
>> Type System.
>>
>> The above piece of code works fine if run, for example, via the
>> cpeGui, but throws the aforementioned exception if deployed as a WS.
>> If I run the following code :
>>
>>
>> String docText = aJCas.getDocumentText();
>>
>> String[] splittedLine = line.split(":");
>> //int start = Integer.parseInt(splittedLine[0]) - 1;
>> //if (start >= docText.length()) start = docText.length() - 1;
>> //int end = Integer.parseInt(splittedLine[1]) - 1;
>> //if (end >= docText.length()) end = docText.length() - 1;
>> NemesisNE annotationNemesis = new NemesisNE(aJCas);
>> //annotationNemesis.setBegin(start);
>> //annotationNemesis.setEnd(end);
>>  // adition of other attributes to annotationNemesis
>> annotationNemesis.addToIndexes();
>>
>>
>> then everything runs just fine as both a WS and a normal application.
>> The problem is that in this case the spans are both 0.
>>
>> If there is any other kind of information that I could provide either
>> to you Thilo or somebody else I would be happy to do it.
>>
>> Again, thanks ( in advance :) )
>>
>> Stergos.
>

Re: REST sandbox component and spans

Posted by Thilo Goetz <tw...@gmx.de>.
Hi Stergos,

it looks to me like you're setting either the start or
the end position to a negative value somewhere.  You
won't notice this in a normal application because nobody
accesses those values, hence no exceptions.  The service,
on the other hand, explicitly accesses those values and
will barf if it finds negative ones.

You can inspect your offsets by running your app in CVD
or DocumentAnalyzer, or by printing out the results
manually.  If you have a JCas, you can do this:

     FSIterator it = aJCas.getAnnotationIndex(Annotation.type).iterator();
     while (it.hasNext()) {
       Annotation annot = (Annotation) it.next();
       System.out.println(annot.getType() + ":" + annot.getBegin() + ":" + annot.getEnd());
     }

I didn't test this, but something like this should work.
Hope this helps.

--Thilo

Stergos D. Afantenos wrote:
> Dear Thilo,
> 
>> we'll need more information to be able to help,
>> the stack trace of the exception for one.
> 
> Here is the stack trace :
> 
> java.lang.StringIndexOutOfBoundsException: String index out of range: -1
> 	java.lang.String.substring(String.java:1932)
> 	org.apache.uima.jcas.tcas.Annotation.getCoveredText(Annotation.java:119)
> 	org.apache.uima.simpleserver.ResultExtractor.makeOutputs(ResultExtractor.java:176)
> 	org.apache.uima.simpleserver.ResultExtractor.outputAll(ResultExtractor.java:158)
> 	org.apache.uima.simpleserver.ResultExtractor.processTypes(ResultExtractor.java:111)
> 	org.apache.uima.simpleserver.ResultExtractor.getResult(ResultExtractor.java:105)
> 	org.apache.uima.simpleserver.Service.process(Service.java:262)
> 	org.apache.uima.simpleserver.servlet.SimpleServerServlet.analyze(SimpleServerServlet.java:204)
> 	org.apache.uima.simpleserver.servlet.SimpleServerServlet.doPost(SimpleServerServlet.java:183)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
> 
>> Also,
>> I do not understand what you mean when you say
>> "I am trying to set the spans for a jCas".
> 
> Of course. I realized my error once I had already sent the email, so
> it was rather late to change it. What I meant to say is that I am
> trying to set the spans of *an annotation* that is found inside a
> JCas. So here is the piece code which causes me headaches:
> 
> 
> String docText = aJCas.getDocumentText();
> 
> String[] splittedLine = line.split(":");
> int start = Integer.parseInt(splittedLine[0]) - 1;
> if (start >= docText.length()) start = docText.length() - 1;
> int end = Integer.parseInt(splittedLine[1]) - 1;
> if (end >= docText.length()) end = docText.length() - 1;
> NemesisNE annotationNemesis = new NemesisNE(aJCas);
> annotationNemesis.setBegin(start);
> annotationNemesis.setEnd(end);
>   // adition of other attributes to annotationNemesis
> annotationNemesis.addToIndexes();
> 
> where the variable line is a ":" separated String whose first element
> is the span start of the annotation that I am currently treating and
> second element is the span end of the annotation that I am currently
> treating.  In addition NemesisNE is a class that I have defined in the
> Type System.
> 
> The above piece of code works fine if run, for example, via the
> cpeGui, but throws the aforementioned exception if deployed as a WS.
> If I run the following code :
> 
> 
> String docText = aJCas.getDocumentText();
> 
> String[] splittedLine = line.split(":");
> //int start = Integer.parseInt(splittedLine[0]) - 1;
> //if (start >= docText.length()) start = docText.length() - 1;
> //int end = Integer.parseInt(splittedLine[1]) - 1;
> //if (end >= docText.length()) end = docText.length() - 1;
> NemesisNE annotationNemesis = new NemesisNE(aJCas);
> //annotationNemesis.setBegin(start);
> //annotationNemesis.setEnd(end);
>   // adition of other attributes to annotationNemesis
> annotationNemesis.addToIndexes();
> 
> 
> then everything runs just fine as both a WS and a normal application.
> The problem is that in this case the spans are both 0.
> 
> If there is any other kind of information that I could provide either
> to you Thilo or somebody else I would be happy to do it.
> 
> Again, thanks ( in advance :) )
> 
> Stergos.

Re: REST sandbox component and spans

Posted by "Stergos D. Afantenos" <st...@gmail.com>.
Dear Thilo,

> we'll need more information to be able to help,
> the stack trace of the exception for one.

Here is the stack trace :

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	java.lang.String.substring(String.java:1932)
	org.apache.uima.jcas.tcas.Annotation.getCoveredText(Annotation.java:119)
	org.apache.uima.simpleserver.ResultExtractor.makeOutputs(ResultExtractor.java:176)
	org.apache.uima.simpleserver.ResultExtractor.outputAll(ResultExtractor.java:158)
	org.apache.uima.simpleserver.ResultExtractor.processTypes(ResultExtractor.java:111)
	org.apache.uima.simpleserver.ResultExtractor.getResult(ResultExtractor.java:105)
	org.apache.uima.simpleserver.Service.process(Service.java:262)
	org.apache.uima.simpleserver.servlet.SimpleServerServlet.analyze(SimpleServerServlet.java:204)
	org.apache.uima.simpleserver.servlet.SimpleServerServlet.doPost(SimpleServerServlet.java:183)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

> Also,
> I do not understand what you mean when you say
> "I am trying to set the spans for a jCas".

Of course. I realized my error once I had already sent the email, so
it was rather late to change it. What I meant to say is that I am
trying to set the spans of *an annotation* that is found inside a
JCas. So here is the piece code which causes me headaches:


String docText = aJCas.getDocumentText();

String[] splittedLine = line.split(":");
int start = Integer.parseInt(splittedLine[0]) - 1;
if (start >= docText.length()) start = docText.length() - 1;
int end = Integer.parseInt(splittedLine[1]) - 1;
if (end >= docText.length()) end = docText.length() - 1;
NemesisNE annotationNemesis = new NemesisNE(aJCas);
annotationNemesis.setBegin(start);
annotationNemesis.setEnd(end);
  // adition of other attributes to annotationNemesis
annotationNemesis.addToIndexes();

where the variable line is a ":" separated String whose first element
is the span start of the annotation that I am currently treating and
second element is the span end of the annotation that I am currently
treating.  In addition NemesisNE is a class that I have defined in the
Type System.

The above piece of code works fine if run, for example, via the
cpeGui, but throws the aforementioned exception if deployed as a WS.
If I run the following code :


String docText = aJCas.getDocumentText();

String[] splittedLine = line.split(":");
//int start = Integer.parseInt(splittedLine[0]) - 1;
//if (start >= docText.length()) start = docText.length() - 1;
//int end = Integer.parseInt(splittedLine[1]) - 1;
//if (end >= docText.length()) end = docText.length() - 1;
NemesisNE annotationNemesis = new NemesisNE(aJCas);
//annotationNemesis.setBegin(start);
//annotationNemesis.setEnd(end);
  // adition of other attributes to annotationNemesis
annotationNemesis.addToIndexes();


then everything runs just fine as both a WS and a normal application.
The problem is that in this case the spans are both 0.

If there is any other kind of information that I could provide either
to you Thilo or somebody else I would be happy to do it.

Again, thanks ( in advance :) )

Stergos.

Re: REST sandbox component and spans

Posted by Thilo Goetz <tw...@gmx.de>.
Stergos,

we'll need more information to be able to help,
the stack trace of the exception for one.  Also,
I do not understand what you mean when you say
"I am trying to set the spans for a jCas".

--Thilo

Stergos D. Afantenos wrote:
> Hi,
> 
> I am using the REST sandbox component in order to publish a UIMA
> annotator as a Web Service. Nevertheless, when I am trying to set the
> spans for a jCas the Web Service returns a nasty exception (index out
> of bounds for a string, which is actually thrown from the
> getCoveredText() of the Annotation class).
> 
> Now, I do make explicitly sure that the Begin and End that I give to
> the annotation are not bigger than the underlying CAS's text, and my
> code runs smoothly if I run it normally (without being a Web Service).
> In addition, the Web Service runs smoothly as well if leave the spans
> alone, but in this case the start and end are 0, unfortunately.
> 
> Has anybody else experienced the same kind of problem? Is this a bug
> on the REST sandbox component or maybe I have entirely missed
> something important?
> 
> Thanks in advance,
> Stergos.