Re: OpenNLP - Model version 1.6.0 not supported by this (1.5.3) version of OpenNLP

2017-01-15 Thread David Samuel Lim
Hello to everyone who has responded.

I would like to thank you for your invaluable assistance. Because of your
advice, I've gained a better insight into not just OpenNLP, but Java in
general as well.

I will continue to look deeper into this field.

Once again I would like to thank William, Richard, Jörn for their help.

Regards,
David

On Sat, Jan 14, 2017 at 4:08 AM, Richard Eckart de Castilho 
wrote:

> On 13.01.2017, at 11:41, David Samuel Lim  wrote:
> >
> > After all that has said, I have a question:
> >
> > *Why is it that when the references to the OpenNLP 1.6.0 libraries are
> > removed, the program "reverts" back to OpenNLP 1.5.3, and how do I undo
> > this? (i.e. when I re-add the 1.6.0 libraries, the program starts using
> > 1.6.0 instead of 1.5.3)*
> > Once again, thanks to all who have answered so far for their insight and
> > advice.
>
> That is because you OpenNLP classes are in multiple JARs on your classpath.
> Depending on the order in which the JARs are mentioned on the classpath,
> the one or the other version of these classes is preferred.
>
> How to fix this?
>
> a) make sure that you don't use fat JARs (cf. other mail I wrote).
> b) consider using a tool that manages your dependencies such as Maven,
>Gradle, or Ivy. I'd personally recommend Maven. It's a bit of another
>learning curve though.
>
> Cheers,
>
> -- Richard
>
>


Re: OpenNLP - Model version 1.6.0 not supported by this (1.5.3) version of OpenNLP

2017-01-13 Thread Richard Eckart de Castilho
On 13.01.2017, at 11:41, David Samuel Lim  wrote:
> 
> After all that has said, I have a question:
> 
> *Why is it that when the references to the OpenNLP 1.6.0 libraries are
> removed, the program "reverts" back to OpenNLP 1.5.3, and how do I undo
> this? (i.e. when I re-add the 1.6.0 libraries, the program starts using
> 1.6.0 instead of 1.5.3)*
> Once again, thanks to all who have answered so far for their insight and
> advice.

That is because you OpenNLP classes are in multiple JARs on your classpath.
Depending on the order in which the JARs are mentioned on the classpath,
the one or the other version of these classes is preferred.

How to fix this? 

a) make sure that you don't use fat JARs (cf. other mail I wrote).
b) consider using a tool that manages your dependencies such as Maven,
   Gradle, or Ivy. I'd personally recommend Maven. It's a bit of another
   learning curve though.

Cheers,

-- Richard



Re: OpenNLP - Model version 1.6.0 not supported by this (1.5.3) version of OpenNLP

2017-01-13 Thread Richard Eckart de Castilho
On 13.01.2017, at 08:29, David Samuel Lim  wrote:
> 
> *> Maybe OpenNLP classes are included in some non-OpenNLP JAR as well that
> you use in your project?*
> 
> Sorry, I'm personally not sure what you mean by this. Could you please
> clarify?

Sometimes people create so-called fat JARs. That is, the build a JAR
which not only contains their code, but also the code of each and every
library that they are using. 

I have hit that problem in the past when I was using a JAR from a tool
which included a full copy of the Stanford Parser. It meant, when I added
a more recent version of the Stanford Parser to my project, unpredictable
things would happen.

Cheers,

-- Richard


Re: OpenNLP - Model version 1.6.0 not supported by this (1.5.3) version of OpenNLP

2017-01-13 Thread David Samuel Lim
Thank you William and Richard for your help and advice.

I think I may have discovered something.

My project also references Apache Tika - the *tika-app-1.13.jar *library.
I'm not very well-versed in Tika, but it apparently has its own
implementation of the OpenNLP files.

How did I discover this?

*(Please bear with this long anecdotal post, I want to describe how I came
across this findings.)*

Firstly, I was conducting experiments to try and resolve this issue. One of
the measures I took was to create a new Eclipse project. This new project
was almost an exact replica of my old project - word-for-word, with the
same naming conventions and program structure. It also made use of the same
libraries - including the OpenNLP 1.6.0 and Apache Tika libraries.

The new program initially worked well. It could load the custom model
successfully.

I experimented on this new program and decided to remove the OpenNLP 1.6.0
library references, then re-add them. This time, the program no longer
worked, instead showing the exact same error as my old program did.

I got curious, so I decided to try something. I removed the libraries again
and observed the code. I was puzzled to see that the import statements for
the OpenNLP classes in use did not show any errors.

Then, I tried removing the reference to *tika-app-1.13.jar*. To my
surprise, the import statements for the various OpenNLP classes in use
showed errors (i.e. red underlines). At that point, I realized that it was
in part due to Tika.

True enough, upon examining the *tika-app-1.13.jar* file, I saw folders
containing OpenNLP packages and files. Given the evidence so far, I
strongly suspect that the OpenNLP version that Tika is implementing is
1.5.3. I'll investigate and experiment more throughout this week and the
next.

*(Please do excuse me; I am rather new to OpenNLP and Tika)*

After all that has said, I have a question:

*Why is it that when the references to the OpenNLP 1.6.0 libraries are
removed, the program "reverts" back to OpenNLP 1.5.3, and how do I undo
this? (i.e. when I re-add the 1.6.0 libraries, the program starts using
1.6.0 instead of 1.5.3)*
Once again, thanks to all who have answered so far for their insight and
advice.

Regards,
David

On Fri, Jan 13, 2017 at 3:32 PM, David Samuel Lim 
wrote:

> Oops, I meant *opennlp-tools-1.5.3.jar*. My bad.
>
> On Fri, Jan 13, 2017 at 3:29 PM, David Samuel Lim 
> wrote:
>
>> Hi Richard,
>>
>> Thanks for the reply. I've checked the classpath again and it only shows
>> the referenced 1.6.0 libraries.
>>
>> Though, when I initially faced the issue, one strategy I tried was to
>> reference the *opennlp-tools-1.5.0.jar* library. It didn't work, so I
>> removed it. None of the methods I've tried so far have given me a solid
>> answer, not even re-training the model using 1.6.0.
>>
>> *> Maybe OpenNLP classes are included in some non-OpenNLP JAR as well
>> that you use in your project?*
>>
>> Sorry, I'm personally not sure what you mean by this. Could you please
>> clarify?
>>
>> Regards,
>> David
>>
>> On Fri, Jan 13, 2017 at 3:14 PM, Richard Eckart de Castilho <
>> r...@apache.org> wrote:
>>
>>> On 13.01.2017, at 02:51, David Samuel Lim  wrote:
>>> >
>>> > *To sum up: Unable to load custom trained OpenNLP Name Finder model in
>>> code
>>> > due to apparent OpenNLP version incompatibility. Model was trained in
>>> > OpenNLP 1.6.0, which my project also uses. Other projects also using
>>> 1.6.0
>>> > were able to load the model successfully.*
>>>
>>> Maybe you have OpenNLP twice on the classpath for some reason, once in
>>> 1.5.3
>>> and once in 1.6.0. Maybe OpenNLP classes are included in some
>>> non-OpenNLP JAR
>>> as well that you use in your project?
>>>
>>> Cheers,
>>>
>>> -- Richard
>>>
>>
>>
>


Re: OpenNLP - Model version 1.6.0 not supported by this (1.5.3) version of OpenNLP

2017-01-13 Thread William Colen
Are you using Maven?


2017-01-13 5:32 GMT-02:00 David Samuel Lim :

> Oops, I meant *opennlp-tools-1.5.3.jar*. My bad.
>
> On Fri, Jan 13, 2017 at 3:29 PM, David Samuel Lim 
> wrote:
>
> > Hi Richard,
> >
> > Thanks for the reply. I've checked the classpath again and it only shows
> > the referenced 1.6.0 libraries.
> >
> > Though, when I initially faced the issue, one strategy I tried was to
> > reference the *opennlp-tools-1.5.0.jar* library. It didn't work, so I
> > removed it. None of the methods I've tried so far have given me a solid
> > answer, not even re-training the model using 1.6.0.
> >
> > *> Maybe OpenNLP classes are included in some non-OpenNLP JAR as well
> that
> > you use in your project?*
> >
> > Sorry, I'm personally not sure what you mean by this. Could you please
> > clarify?
> >
> > Regards,
> > David
> >
> > On Fri, Jan 13, 2017 at 3:14 PM, Richard Eckart de Castilho <
> > r...@apache.org> wrote:
> >
> >> On 13.01.2017, at 02:51, David Samuel Lim 
> wrote:
> >> >
> >> > *To sum up: Unable to load custom trained OpenNLP Name Finder model in
> >> code
> >> > due to apparent OpenNLP version incompatibility. Model was trained in
> >> > OpenNLP 1.6.0, which my project also uses. Other projects also using
> >> 1.6.0
> >> > were able to load the model successfully.*
> >>
> >> Maybe you have OpenNLP twice on the classpath for some reason, once in
> >> 1.5.3
> >> and once in 1.6.0. Maybe OpenNLP classes are included in some
> non-OpenNLP
> >> JAR
> >> as well that you use in your project?
> >>
> >> Cheers,
> >>
> >> -- Richard
> >>
> >
> >
>


OpenNLP - Model version 1.6.0 not supported by this (1.5.3) version of OpenNLP

2017-01-12 Thread David Samuel Lim
Hello,

I am currently facing an issue with regards to loading a custom trained NER
model.

My project uses OpenNLP 1.6.0 and is developed using Eclipse IDE. The model
was also trained using OpenNLP 1.6.0.

However, when I try to load the model *InputStream* into a
*TokenNameFinderModel* object, I get the following error:

java.lang.IllegalArgumentException :
opennlp.tools.util.InvalidFormatException: Model version 1.6.0 is not
supported by this (1.5.3) version of OpenNLP!


Based on info I've gathered from sites like StackOverflow (such as this

question), I get the sense that if I want to use a custom trained model in
OpenNLP 1.6.0, it has to be trained using OpenNLP 1.5.3. However, I
personally do not think that is the case, as I have other Java projects
using OpenNLP 1.6.0, and they were able to load the model successfully.

The *.classpath* of my project also shows that the project is referencing
the OpenNLP 1.6.0 libraries.

I know the question is rather vague, but if anyone has any insight into why
this could be happening, please let me know! Help is greatly appreciated.

*To sum up: Unable to load custom trained OpenNLP Name Finder model in code
due to apparent OpenNLP version incompatibility. Model was trained in
OpenNLP 1.6.0, which my project also uses. Other projects also using 1.6.0
were able to load the model successfully.*

Regards,

David Lim