Search Mailing List Archives

Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[bioontology-support] Error using the Annotator service in Linux

Ray Fergerson ray.fergerson at
Tue Feb 18 14:09:40 PST 2014

Great. Glad you figured it out and that it is working now.


From: Leyla Jael García Castro [mailto:leylajael at]
Sent: Tuesday, February 18, 2014 1:28 PM
To: Ray Fergerson
Cc: at; support at
Subject: Re: [bioontology-support] Error using the Annotator service in

Hi Ray,

The problem was with a particular paragraph but it has now been solved,
nothing wrong in the annotator or the code itself but with the testing
environment configuration, a corrupted file. It took us a while to realize
about the real problem, but after testing and debugging we managed to
identify the source of the problem. So sorry about all the hassle.

Thanks all so much for your help,



On Tue, Feb 18, 2014 at 7:40 PM, Ray Fergerson
<ray.fergerson at> wrote:


It is not clear to me under what circumstances it fails. Let’s assume you
are running a single instance of the code you sent. Are you saying that
you can run this script once (for one paragraph) on a windows machine but
when you run the same script once on a Mac or a Linux box with the same
paragraph that it always fails? If so, then to debug this we just need
your sample paragraph.

Are you instead saying that you are seeing random failures running a
single version of this script from a single client? Or, is the problem
that when you run multiple copies of this script, perhaps from different
machines, simultaneously, that you see random failures (sometimes the
input text works and sometimes it fails)?


From: bioontology-support-bounces at
[mailto:bioontology-support-bounces at] On Behalf Of Leyla
Jael García Castro
Sent: Tuesday, February 18, 2014 3:46 AM
To: at; support at
Subject: Re: [bioontology-support] Error using the Annotator service in

Hi Darren,

The problematic text, with the same algorithm, works fine in a Windows
machine, but it returns an API key error message in Linux, also in Mac.
The Linux and Mac machines are both faster than the Windows one, so it
could be related with the number of requests per second to the annotator
with the same API key. As it work in Windows, I think the problem is not
the API key but something else. Is it possible that this API key error is
reported when some other error has been thrown? Is it possible to get the
full error somehow?



On Tue, Feb 18, 2014 at 12:15 AM, Darren Weber <dlweber at>

Hi Leyla,

If you have a specific example text that is always failing, we can try to
replicate it, using your parameters (other than API key).  If it's not
easily replicated, it's not likely we can resolve it.  Have you tried the
problematic text in the web UI?

-- Darren

On 2/17/14, 12:00 PM, Leyla Jael García Castro wrote:

Hi Darren,

Yes, my API key works fine with the URI{YOUR_API_KEY}, I get a JSON
file with a lot of information (administeredBy, acronym, name,
summaryOnly, etc.).

The code that I sent before is used in a loop. We have a text with several
paragraphs, all of the are sent to the annotator one by one. With all the
others paragraphs it works fine. I have checked some other texts, and it
seems to fail always with one of the last paragraphs. It makes me think
that the error response is wrong, the API key is working with other
paragraphs, there must be something else going on.

Thanks for your help,


On Mon, Feb 17, 2014 at 4:19 PM, Darren Weber <dlweber at>

Hi Leyla,

Can you login to the web site with that API key?  Does it work on this URI{YOUR_API_KEY}

-- Darren

On 2/16/14, 1:07 PM, Leyla Jael García Castro wrote:

Hi Paul,

We just realized that the parameter "stopWords" should be "stop_words",
but that was not the problem. Nor is the number of requests that we do.
Just tried to send all the paragraphs at once and it did not work,same
error about the API key. Would it help if I send you the file we are
annotating? Is RDF/XML.



On Sat, Feb 15, 2014 at 9:55 PM, Leyla Jael García Castro
<leylajael at> wrote:

Hi Paul,

Here is the excerpt of the code that is calling the annotation. btw, I
have been playing around with the text that is giving us troubles, for
instance I moved it above other paragraphs that are correctly annotated.
Then, it was another paragraph the one that gave us the error. Is there
maybe a maximum API calls per second? Could be that why at some point the
API key seems to be not valid any more? I tried to look for hidden chars
but there was nothing special, just regular text with tabs and spaces.

We also tried to replace the "+" added by the encoder instead of the
spaces to "%20", and to spaces again, but  we got the same API key

String ontologiesToAnnotate =

String annotatorURL = "";

String stopwords =
//and some others

        try {

        paragraph =
paragraph.replaceAll("[^\\p{Alpha}\\p{Z}\\p{P}\\p{N}]", "_");

        paragraph = URLEncoder.encode(paragraph,

        System.out.println("TO ANNOT: " + urlContext + "\n" + paragraph);

            HttpClient client = new HttpClient();

"Annotator Client Scientific Publications");  //Set this string for your

            PostMethod method = new PostMethod(annotatorURL);

            // Configure the form parameters



            method.addParameter("ontologies", ontologiesToAnnotate);

            method.addParameter("text", paragraph);

            method.addParameter("format", "xml"); //Options are 'text',
'xml', 'tabDelimited'

            method.addParameter("apikey", Config.getNCBOAPIKey());

            // Execute the POST method

            int statusCode = client.executeMethod(method);

            if( statusCode != -1 ) {

                try {

               InputStream temporal  = method.getResponseBodyAsStream();

               //testing, we want to see the response and if it is ok we
want to process it so we need it twice

               ByteArrayOutputStream baos = new ByteArrayOutputStream();

               byte[] buf = new byte[1024];

               int n = 0;

               while ((n = >= 0) {

                   baos.write(buf, 0, n);


               byte[] content = baos.toByteArray();

               InputStream annotatedParagraph = new

               if (annotatedParagraph != null) {

                //Reader reader = new StringReader(annotatedParagraph);

            JAXBContext jc =

            Unmarshaller unmarshaller = jc.createUnmarshaller();

            AnnotationCollection xml;

            Object obj = new Object();

            try {

            obj = unmarshaller.unmarshal(annotatedParagraph);

            if (obj instanceof Empty) {

            return true; //no annotations were found but everything was ok
with the response


            xml = (AnnotationCollection)obj; //otherwise,
AnnotationCollection should be the unmarshalled object

            } catch (Exception e) {

            InputStream temp = new ByteArrayInputStream(content);

            String line;

                   BufferedReader reader = new BufferedReader(new
InputStreamReader(temp, "UTF-8"));

                   while ((line = reader.readLine()) != null) {





            logger.fatal("- FATAL DTD ERROR ANNOTATOR - NCBO annotations
for " + this.documentId + "(" + urlContext + ") cannot be unmarshalled: "
+ e.getMessage() + " - class: " + obj.getClass());

            return false;



then I just start processing the response. If you need, I can send you the
actual java class, but I am afraid that it depends on some other
libraries, jaxb, etc. so unless I share you the whole project it would not
work. Please let me know should you need any further information.



On Fri, Feb 14, 2014 at 11:11 PM, Paul R Alexander
<palexander at> wrote:

How is the call being invoked? Can you share the code that is actually
doing the call?



On Feb 14, 2014, at 1:20 PM, Leyla Jael García Castro
<leylajael at> wrote:

Hi all,

I am using the Annotator service successfully on Windows but, what the
odds, the same code with the same text is not working on Linux.

This is the text after URL enconding:


And this is the response we are getting:

<?xml version="1.0" encoding="UTF-8"?>



  <error>You must provide a valid API Key. Your API Key can be obtained by
logging in at</error>


Any suggestions? This is really puzzle me.

Best regards,


bioontology-support mailing list
bioontology-support at

bioontology-support mailing list
bioontology-support at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the bioontology-support mailing list