You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nutch.apache.org by Julien Nioche <li...@gmail.com> on 2009/11/16 20:13:32 UTC

Update on Integration with Tika

Hi,

I came across the classloader issue that you mentioned but got everything to
work OK by duplicating the class TikaConfiguration into the package used by
my plugin. The lib tika-core goes into the main /lib dir of nutch while
tika-parsers jar goes into the lib dir of the plugin. I now have a first
version of the Tika plugin which does some very basic text and metadata
extraction.

What shall we do about the HTMLParseFilters? Get the generic TikaParser to
create a DOM representation and pass it to the HTMLParseFilters as it is
done now? Modify the HTMLParseFilters so that they use SAX events so that we
can forward them from Tika? Any other suggestions?

J.


2009/11/12 Kirby Bohling <ki...@gmail.com>

> You'll need to be careful of the classloader issues if you do that...
>
> The core Nutch code needs just the mime type stuff, but if you access
> Tika from the lib directory rather then from the plugins/lib
> directory, it won't be able to find any extensions.  I've used Tika to
> implement a docx plugin, and came across all these problems.
>
> Kirby
>
>
> On Thu, Nov 12, 2009 at 8:41 AM, Julien Nioche
> <li...@gmail.com> wrote:
> > Speaking of which, I'm planning to do some work on the Tika integration
> > within the next week or so. Basically, I'll create a new plugin which
> will
> > be used for the mime types that Tika can already handle while keeping
> some
> > of the existing plugins for the more complex cases. This should allow us
> to
> > already have a first version of the Tika integration without losing any
> the
> > functionalities. Will update the list as soon as I have something working
> +
> > will create a JIRA
> >
> > J.
> > --
> > DigitalPebble Ltd
> > http://www.digitalpebble.com
> >
> > 2009/11/10 Andrzej Bialecki <ab...@getopt.org>
> >>
> >> BrunoWL wrote:
> >>>
> >>> Hi. i'm a benning in nutch. Can anybody tell how to make nutch use
> >>> parsers
> >>> from tika.
> >>> I did all kind of search and didn't find a answer.
> >>
> >> Tika parsers are not integrated yet with Nutch - we use our own parsers,
> >> and in most cases they are of similar quality as those in Tika (since
> most
> >> Tika parsers originated in Nutch). Tight Tika integration is on the
> roadmap.
> >>
> >> --
> >> Best regards,
> >> Andrzej Bialecki     <><
> >>  ___. ___ ___ ___ _ _   __________________________________
> >> [__ || __|__/|__||\/|  Information Retrieval, Semantic Web
> >> ___|||__||  \|  ||  |  Embedded Unix, System Integration
> >> http://www.sigram.com  Contact: info at sigram dot com
> >
>



-- 
DigitalPebble Ltd
http://www.digitalpebble.com

Re: Update on Integration with Tika

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Tue, Nov 17, 2009 at 10:24 AM, Julien Nioche
<li...@gmail.com> wrote:
> First let me explain the classloader issue. The main class in the Tika
> plugin instantiates a TikaConfig object (using Tika's XML
> configuration file), which tries to load the parser classes for each
> mime-type Tika knows about. Remember that we need tika-core in the
> main lib directory? This is where the TikaConfig class is stored. For
> some reason it is not able to find the classes in the jars located at
> the plugin level even though the class instantiating TikaConfig is
> itself at the plugin level.

The problem is that TikaConfig currently uses the class loader that
loaded tika-core when trying to resolve the configured parser classes.

There's discussion in Tika about using the Java service provider
mechanism and the thread context class loader to access all available
parser implementations. This would make Tika more "plugin friendly",
but is not yet implemented.

BR,

Jukka Zitting

Re: Update on Integration with Tika

Posted by Andrzej Bialecki <ab...@getopt.org>.
Julien Nioche wrote:

[...]
> Sure, but it also mean that we would hopefully get a working version of 
> the Tika parser quicker by not making it depend on the extension point 
> refactoring. It could also be argued that the Tika parsing and the 
> refactoring of the extension points are two separated issues which could 
> be possibly covered by different people. Moreover the workaround is just 
> a reference to a class in one file, replacing this during the 
> refactoring would hardly add any work.

Ok, good points - let's try it this way.

-- 
Best regards,
Andrzej Bialecki     <><
  ___. ___ ___ ___ _ _   __________________________________
[__ || __|__/|__||\/|  Information Retrieval, Semantic Web
___|||__||  \|  ||  |  Embedded Unix, System Integration
http://www.sigram.com  Contact: info at sigram dot com


Re: Update on Integration with Tika

Posted by Julien Nioche <li...@gmail.com>.
>
>> I haven't looked yet at the way extension points work, so I don't really
>> have an idea on how difficult this would be. Some of Tika's classes (mostly
>> MimeType) are used explicitly in several places of the core, would we need
>> to hide them behind non Tika objects in order not to have direct
>> dependencies?
>>
>
> Yes, that was my idea.


My concern with this approach is that we end up having something
artificially complex and add all sorts of intermediate objects on the
mimetype side just to avoid a limitation of Tika which might be sorted later
anyway.


>  I suppose we could try to make progress on the Tika plugin as it is now
>> (i.e. with the work around I described earlier) and refactor things in a
>> later stage using the extension points. Makes sense?
>>
>
> We could, but if we can figure out a cleaner solution now, then we should
> follow it instead of committing that workaround and then having to refactor
> it ...


Sure, but it also mean that we would hopefully get a working version of the
Tika parser quicker by not making it depend on the extension point
refactoring. It could also be argued that the Tika parsing and the
refactoring of the extension points are two separated issues which could be
possibly covered by different people. Moreover the workaround is just a
reference to a class in one file, replacing this during the refactoring
would hardly add any work.

J.
-- 
DigitalPebble Ltd
http://www.digitalpebble.com

Re: Update on Integration with Tika

Posted by Andrzej Bialecki <ab...@getopt.org>.
Julien Nioche wrote:
> 
>     Well ... let's consider this: in the past we used to put things
>     under /lib/ when they were being used by more than a few plugins.
>     Then we started using library-only plugins (e.g. lib-xml,
>     lib-nekohtml, etc). There is a mechanism that allows us to export
>     any classes from a plugin so that they are visible to the rest of
>     the framework.
> 
>     It looks to me like we could be better off by putting all parts of
>     Tika in a single plugin, and then in Nutch core use a new extension
>     point just for the purpose of mimetype detection. This facade
>     (MimeDetectors) would use the Tika plugin if available, or some
>     other (null?) mechanism otherwise. At the same time Tika would be
>     happy to configure itself having all tika-core and parsers available
>     under the same classloader, and it would define two extension points
>     - one for mimetype detection, and another for parsing. What do you
>     think?
> 
> 
> I haven't looked yet at the way extension points work, so I don't really 
> have an idea on how difficult this would be. Some of Tika's classes 
> (mostly MimeType) are used explicitly in several places of the core, 
> would we need to hide them behind non Tika objects in order not to have 
> direct dependencies?

Yes, that was my idea.

> I suppose we could try to make progress on the Tika plugin as it is now 
> (i.e. with the work around I described earlier) and refactor things in a 
> later stage using the extension points. Makes sense?

We could, but if we can figure out a cleaner solution now, then we 
should follow it instead of committing that workaround and then having 
to refactor it ...

-- 
Best regards,
Andrzej Bialecki     <><
  ___. ___ ___ ___ _ _   __________________________________
[__ || __|__/|__||\/|  Information Retrieval, Semantic Web
___|||__||  \|  ||  |  Embedded Unix, System Integration
http://www.sigram.com  Contact: info at sigram dot com


Re: Update on Integration with Tika

Posted by Julien Nioche <li...@gmail.com>.
>
>
> Well ... let's consider this: in the past we used to put things under /lib/
> when they were being used by more than a few plugins. Then we started using
> library-only plugins (e.g. lib-xml, lib-nekohtml, etc). There is a mechanism
> that allows us to export any classes from a plugin so that they are visible
> to the rest of the framework.
>
> It looks to me like we could be better off by putting all parts of Tika in
> a single plugin, and then in Nutch core use a new extension point just for
> the purpose of mimetype detection. This facade (MimeDetectors) would use the
> Tika plugin if available, or some other (null?) mechanism otherwise. At the
> same time Tika would be happy to configure itself having all tika-core and
> parsers available under the same classloader, and it would define two
> extension points - one for mimetype detection, and another for parsing. What
> do you think?


I haven't looked yet at the way extension points work, so I don't really
have an idea on how difficult this would be. Some of Tika's classes (mostly
MimeType) are used explicitly in several places of the core, would we need
to hide them behind non Tika objects in order not to have direct
dependencies?

I suppose we could try to make progress on the Tika plugin as it is now
(i.e. with the work around I described earlier) and refactor things in a
later stage using the extension points. Makes sense?

J.
-- 
DigitalPebble Ltd
http://www.digitalpebble.com

Re: Update on Integration with Tika

Posted by Andrzej Bialecki <ab...@getopt.org>.
Julien Nioche wrote:
> Hi guys,
> 
>>> This is confusing. Could you please explain why various Tika parts
>>> need to be put in different places?
> 
> NUTCH_HOME/lib : tika-core.jar
> NUTCH_HOME/tika-plugin/lib : tika-parsers.jar
> 
> Tika being used by the core only for its Mimetype functionalities we
> only need to put tika-core at the main lib level whereas the tika
> plugin obviously needs the tika-parsers.jar + all the jars used
> internally by Tika. Note that we could simply put everything in the
> main lib dir but that would not be very elegant.  Is that more clear?

Clear, thanks.

> 
>>> Also, the word "duplication"  raises a red flag ...
> 
> First let me explain the classloader issue. The main class in the Tika
> plugin instantiates a TikaConfig object (using Tika's XML
> configuration file), which tries to load the parser classes for each
> mime-type Tika knows about. Remember that we need tika-core in the
> main lib directory? This is where the TikaConfig class is stored. For
> some reason it is not able to find the classes in the jars located at
> the plugin level even though the class instantiating TikaConfig is
> itself at the plugin level. I had a look at the PluginClassLoader but
> could not find anything wrong with it.
> 
> We can of course try to fix this classloader issue (which will be a
> more elegant solution), but in order not to get bogged down with this
> I found that having a temporary solution with a local TikaConfig
> allowed us to make progress with the Tika implementation.
> 
> Is the classloader problem clear? Shall we treat it as a separate issue?

Thanks for the explanation.

Well ... let's consider this: in the past we used to put things under 
/lib/ when they were being used by more than a few plugins. Then we 
started using library-only plugins (e.g. lib-xml, lib-nekohtml, etc). 
There is a mechanism that allows us to export any classes from a plugin 
so that they are visible to the rest of the framework.

It looks to me like we could be better off by putting all parts of Tika 
in a single plugin, and then in Nutch core use a new extension point 
just for the purpose of mimetype detection. This facade (MimeDetectors) 
would use the Tika plugin if available, or some other (null?) mechanism 
otherwise. At the same time Tika would be happy to configure itself 
having all tika-core and parsers available under the same classloader, 
and it would define two extension points - one for mimetype detection, 
and another for parsing. What do you think?

>>> The benefit of using DOM tree in HTMLParseFilters is that it's
>>> easier to extract / remove parts of the tree without keeping track
>>> of the context, which is the most complicated part of working with
>>> SAX - this context tracking would have to be reimplemented in many
>>> plugins ... The downside is of course the memory footprint - but we
>>> do limit the max size of the documents elsewhere (in the protocol
>>> plugins). So I'd vote to keep using DOM for now.
>> With web mining, you absolutely need to be able to access the context
>> of the complete DOM.
> 
> I agree with you both. Maybe we could delegate the building of the DOM
> object to the class HTMLParseFilters so that it is done only if there
> are HTMLParseFilter implementation to be used.

Hmmmm .. let's rephrase the question: who would use the non-DOM 
interface? If nobody, then maybe we only need the DOM.

> A related question is : shall we build the DOM representation from the
> original HTML or from the XHTML returned by Tika? I would be inclined
> to the latter as this could potentially allow us to do the same with
> non HTML documents as well as Tika converts their original markup into
> XHTML.

I think we should use the XHTML from Tika.

-- 
Best regards,
Andrzej Bialecki     <><
  ___. ___ ___ ___ _ _   __________________________________
[__ || __|__/|__||\/|  Information Retrieval, Semantic Web
___|||__||  \|  ||  |  Embedded Unix, System Integration
http://www.sigram.com  Contact: info at sigram dot com


Re: Update on Integration with Tika

Posted by Julien Nioche <li...@gmail.com>.
Hi guys,

>> This is confusing. Could you please explain why various Tika parts
>> need to be put in different places?

NUTCH_HOME/lib : tika-core.jar
NUTCH_HOME/tika-plugin/lib : tika-parsers.jar

Tika being used by the core only for its Mimetype functionalities we
only need to put tika-core at the main lib level whereas the tika
plugin obviously needs the tika-parsers.jar + all the jars used
internally by Tika. Note that we could simply put everything in the
main lib dir but that would not be very elegant.  Is that more clear?

>> Also, the word "duplication"  raises a red flag ...

First let me explain the classloader issue. The main class in the Tika
plugin instantiates a TikaConfig object (using Tika's XML
configuration file), which tries to load the parser classes for each
mime-type Tika knows about. Remember that we need tika-core in the
main lib directory? This is where the TikaConfig class is stored. For
some reason it is not able to find the classes in the jars located at
the plugin level even though the class instantiating TikaConfig is
itself at the plugin level. I had a look at the PluginClassLoader but
could not find anything wrong with it.

We can of course try to fix this classloader issue (which will be a
more elegant solution), but in order not to get bogged down with this
I found that having a temporary solution with a local TikaConfig
allowed us to make progress with the Tika implementation.

Is the classloader problem clear? Shall we treat it as a separate issue?


>> The benefit of using DOM tree in HTMLParseFilters is that it's
>> easier to extract / remove parts of the tree without keeping track
>> of the context, which is the most complicated part of working with
>> SAX - this context tracking would have to be reimplemented in many
>> plugins ... The downside is of course the memory footprint - but we
>> do limit the max size of the documents elsewhere (in the protocol
>> plugins). So I'd vote to keep using DOM for now.
>
> With web mining, you absolutely need to be able to access the context
> of the complete DOM.

I agree with you both. Maybe we could delegate the building of the DOM
object to the class HTMLParseFilters so that it is done only if there
are HTMLParseFilter implementation to be used.

A related question is : shall we build the DOM representation from the
original HTML or from the XHTML returned by Tika? I would be inclined
to the latter as this could potentially allow us to do the same with
non HTML documents as well as Tika converts their original markup into
XHTML.

Have a nice day

Julien
-- 
DigitalPebble Ltd
http://www.digitalpebble.com

Re: Update on Integration with Tika

Posted by Ken Krugler <kk...@transpac.com>.
On Nov 16, 2009, at 12:00pm, Andrzej Bialecki wrote:

> Julien Nioche wrote:
>> Hi,
>> I came across the classloader issue that you mentioned but got  
>> everything to work OK by duplicating the class TikaConfiguration  
>> into the package used by my plugin. The lib tika-core goes into the  
>> main /lib dir of nutch while tika-parsers jar goes into the lib dir  
>> of the plugin. I now have a first version of the Tika plugin which  
>> does some very basic text and metadata extraction.
>
> This is confusing. Could you please explain why various Tika parts  
> need to be put in different places? Also, the word "duplication"  
> raises a red flag ...
>
>> What shall we do about the HTMLParseFilters? Get the generic  
>> TikaParser to create a DOM representation and pass it to the  
>> HTMLParseFilters as it is done now? Modify the HTMLParseFilters so  
>> that they use SAX events so that we can forward them from Tika? Any  
>> other suggestions?
>
> The benefit of using DOM tree in HTMLParseFilters is that it's  
> easier to extract / remove parts of the tree without keeping track  
> of the context, which is the most complicated part of working with  
> SAX - this context tracking would have to be reimplemented in many  
> plugins ... The downside is of course the memory footprint - but we  
> do limit the max size of the documents elsewhere (in the protocol  
> plugins). So I'd vote to keep using DOM for now.

With web mining, you absolutely need to be able to access the context  
of the complete DOM.

Though I could see this being configurable, based on whether the  
output is just used for building an index, versus more specific  
scraping.

-- Ken



Re: Update on Integration with Tika

Posted by Andrzej Bialecki <ab...@getopt.org>.
Julien Nioche wrote:
> Hi,
> 
> I came across the classloader issue that you mentioned but got 
> everything to work OK by duplicating the class TikaConfiguration into 
> the package used by my plugin. The lib tika-core goes into the main /lib 
> dir of nutch while tika-parsers jar goes into the lib dir of the plugin. 
> I now have a first version of the Tika plugin which does some very basic 
> text and metadata extraction.

This is confusing. Could you please explain why various Tika parts need 
to be put in different places? Also, the word "duplication" raises a red 
flag ...

> 
> What shall we do about the HTMLParseFilters? Get the generic TikaParser 
> to create a DOM representation and pass it to the HTMLParseFilters as it 
> is done now? Modify the HTMLParseFilters so that they use SAX events so 
> that we can forward them from Tika? Any other suggestions?

The benefit of using DOM tree in HTMLParseFilters is that it's easier to 
extract / remove parts of the tree without keeping track of the context, 
which is the most complicated part of working with SAX - this context 
tracking would have to be reimplemented in many plugins ... The downside 
is of course the memory footprint - but we do limit the max size of the 
documents elsewhere (in the protocol plugins). So I'd vote to keep using 
DOM for now.

-- 
Best regards,
Andrzej Bialecki     <><
  ___. ___ ___ ___ _ _   __________________________________
[__ || __|__/|__||\/|  Information Retrieval, Semantic Web
___|||__||  \|  ||  |  Embedded Unix, System Integration
http://www.sigram.com  Contact: info at sigram dot com