Ah, I see, it is for the stuff you do in sandbox. Looks very reasonable to
me. But I would test for resource loading - we use jar artifacts to move
our models along with the library, but now they're manually handled. With
this new method it'll be easier.

Aliaksandr

On Fri, Apr 27, 2012 at 12:05 PM, Jörn Kottmann <[email protected]> wrote:

> With the URL constructor the model bean can be created like this:
> <bean id="en-ner-person-model"
>       class="opennlp.t.namefind.**TokenNameFinderModel">
>
> <argument value="file:///home/xyz/**models/en-ner-person.bin"/>
> </bean>
>
> Jörn
>
>
> On 04/27/2012 12:02 PM, Jörn Kottmann wrote:
>
>> On 04/27/2012 11:47 AM, Aliaksandr Autayeu wrote:
>>
>>> Seems to be a good idea. Can you shed some light on this: "URL
>>> constructor can be easily used by a dependency injection framework
>>> to create an instance."?
>>>
>>
>> Sure.
>>
>> In the Tagging Server I did this:
>> public static TokenNamerFinderModel createModel(URL modelURL) {...}
>>
>> This factory method loads a model from a URL. I needed to create it
>> because
>> our models do not have such a constructor, with a URL constructor the
>> factory
>> is not necessary.
>>
>> Now with this factory you can create a bean like this:
>> <bean id="en-ner-person-model"
>>         class="org.apache.opennlp.**tagging_server.namefind.**
>> TokenNameFinderModelFactory"
>>         factory-method="createModel">
>> <argument value="file:///home/xyz/**models/en-ner-person.bin"/>
>> </bean>
>>
>> The url could also be http, or as far as I know in spring even a resource
>> on the
>> classpath, e.g. something like classpath:person.bin (I didn't test that,
>> just heard its possible).
>>
>> To finally use the model it still needs to be registered as a service (at
>> least in the Tagging Server):
>> <service id="en-ner-person-model-**service" ref="en-ner-person-model"
>>        interface="opennlp.tools.**namefind.TokenNameFinderModel"**>
>> <service-properties>
>> <entry key="MODEL_LANG" value="en"/>
>> <entry key="MODEL_NAME" value="person"/>
>> </service-properties>
>> </service>
>>
>> Jörn
>>
>>
>>
>

Reply via email to