You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@creadur.apache.org by Robert Burrell Donkin <ro...@blueyonder.co.uk> on 2009/05/17 09:03:57 UTC

Improved MIME support

i plan to take a look at improving MIME detection by offering the option
to use Tika

tika-0.2 has quite a few dependencies. most of these are not required
for MIME detection. tika has been modularised in trunk. after the next
released rat will be able to switch to tika-core which has only limited
dependencies.

IMHO it makes sense to factor out an interface, retain the existing
implementation and create a separate module. this will allow assembler
who don't want to use tika to create applications that don't use it.

i've raised https://issues.apache.org/jira/browse/RAT-54 and linked to a
couple of related issues.

opinions?

- robert


Re: Improved MIME support

Posted by Robert Burrell Donkin <ro...@blueyonder.co.uk>.
Robert Burrell Donkin wrote:
> Jukka Zitting wrote:
>> Hi,
>>
>> On Sun, May 17, 2009 at 9:03 AM, Robert Burrell Donkin
>> <ro...@blueyonder.co.uk> wrote:
>>> IMHO it makes sense to factor out an interface, retain the existing
>>> implementation and create a separate module. this will allow assembler
>>> who don't want to use tika to create applications that don't use it.
>> How about using the org.apache.tika.detect.Detector interface (see below)?
>>
>> Tika comes with default implementations of the interface, but it
>> should be straightforward to implement the interface also based on
>> alternative implementations.
> 
> i see this as a stepping stone. tika already supports most of the
> heuristics rat uses so IMHO it would make more sense to feed back rules
> upstream (either into the default typer, or a variant tuned for
> development).
> 
> a couple of issues that suggest that this might be better than jumping
> to tika right away:
> 
> 1. in terms of interface reuse ATM tika trunk doesn't offer a minimal api[1]
> 2. the latest release (tika 0.2) is not modular

correction 0.3

- robert


Re: Improved MIME support

Posted by Robert Burrell Donkin <ro...@blueyonder.co.uk>.
Jukka Zitting wrote:
> Hi,
> 
> On Sun, May 17, 2009 at 11:20 AM, Robert Burrell Donkin
> <ro...@blueyonder.co.uk> wrote:
>> a couple of issues that suggest that this might be better than jumping
>> to tika right away:
>>
>> 1. in terms of interface reuse ATM tika trunk doesn't offer a minimal api[1]
>>
>> [1] IMHO breaking out a tika api module with minimal dependencies would
>> encourage wider use of tika's basic abstractions
> 
> That's right. Tika is still in progress of cleaning up many of its
> internal abstractions (type registry, metadata handling, etc.), so it
> might be premature to use them as-is outside Tika at this point. By
> Tika 1.0 I believe the abstractions being in a pretty solid state.
> 
> Anyway, quite a bit of thought has already gone into the Detector
> interface, so it would be useful to at least borrow some of the key
> parts. One pretty essential piece is the way the InputStream argument
> is handled. With the explicitly specified mark/reset behaviour it's
> possible for a detector to easily delegate the detection to multiple
> different sub-detectors. Also, each detector gets to decide how much
> of the input stream they need to read to detect the file type.

my plan is to pattern the API on the ones in tika and see how it works

>> 2. the latest release (tika 0.3) is not modular
> 
> Correct, that'll be solved in Tika 0.4. I'm sure we can cut the 0.4
> release pretty soon if there's demand from RAT.

it's possible that RAT has some MIME typing heuristics that need to be
fed back upstream. so, probably best to wait a little while at least.

- robert


Re: Improved MIME support

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

On Sun, May 17, 2009 at 11:20 AM, Robert Burrell Donkin
<ro...@blueyonder.co.uk> wrote:
> a couple of issues that suggest that this might be better than jumping
> to tika right away:
>
> 1. in terms of interface reuse ATM tika trunk doesn't offer a minimal api[1]
>
> [1] IMHO breaking out a tika api module with minimal dependencies would
> encourage wider use of tika's basic abstractions

That's right. Tika is still in progress of cleaning up many of its
internal abstractions (type registry, metadata handling, etc.), so it
might be premature to use them as-is outside Tika at this point. By
Tika 1.0 I believe the abstractions being in a pretty solid state.

Anyway, quite a bit of thought has already gone into the Detector
interface, so it would be useful to at least borrow some of the key
parts. One pretty essential piece is the way the InputStream argument
is handled. With the explicitly specified mark/reset behaviour it's
possible for a detector to easily delegate the detection to multiple
different sub-detectors. Also, each detector gets to decide how much
of the input stream they need to read to detect the file type.

> 2. the latest release (tika 0.3) is not modular

Correct, that'll be solved in Tika 0.4. I'm sure we can cut the 0.4
release pretty soon if there's demand from RAT.

BR,

Jukka Zitting

Re: Improved MIME support

Posted by Robert Burrell Donkin <ro...@blueyonder.co.uk>.
Jukka Zitting wrote:
> Hi,
> 
> On Sun, May 17, 2009 at 9:03 AM, Robert Burrell Donkin
> <ro...@blueyonder.co.uk> wrote:
>> IMHO it makes sense to factor out an interface, retain the existing
>> implementation and create a separate module. this will allow assembler
>> who don't want to use tika to create applications that don't use it.
> 
> How about using the org.apache.tika.detect.Detector interface (see below)?
> 
> Tika comes with default implementations of the interface, but it
> should be straightforward to implement the interface also based on
> alternative implementations.

i see this as a stepping stone. tika already supports most of the
heuristics rat uses so IMHO it would make more sense to feed back rules
upstream (either into the default typer, or a variant tuned for
development).

a couple of issues that suggest that this might be better than jumping
to tika right away:

1. in terms of interface reuse ATM tika trunk doesn't offer a minimal api[1]
2. the latest release (tika 0.2) is not modular

- robert

[1] IMHO breaking out a tika api module with minimal dependencies would
encourage wider use of tika's basic abstractions


Re: Improved MIME support

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

On Sun, May 17, 2009 at 9:03 AM, Robert Burrell Donkin
<ro...@blueyonder.co.uk> wrote:
> IMHO it makes sense to factor out an interface, retain the existing
> implementation and create a separate module. this will allow assembler
> who don't want to use tika to create applications that don't use it.

How about using the org.apache.tika.detect.Detector interface (see below)?

Tika comes with default implementations of the interface, but it
should be straightforward to implement the interface also based on
alternative implementations.

BR,

Jukka Zitting


/**
 * Content type detector. Implementations of this interface use various
 * heuristics to detect the content type of a document based on given
 * input metadata or the first few bytes of the document stream.
 *
 * @since Apache Tika 0.3
 */
public interface Detector {

    /**
     * Detects the content type of the given input document. Returns
     * <code>application/octet-stream</code> if the type of the document
     * can not be detected.
     * <p>
     * If the document input stream is not available, then the first
     * argument may be <code>null</code>. Otherwise the detector may
     * read bytes from the start of the stream to help in type detection.
     * The given stream is guaranteed to support the
     * {@link InputStream#markSupported() mark feature} and the detector
     * is expected to {@link InputStream#mark(int) mark} the stream before
     * reading any bytes from it, and to {@link InputStream#reset() reset}
     * the stream before returning. The stream must not be closed by the
     * detector.
     * <p>
     * The given input metadata is only read, not modified, by the detector.
     *
     * @param input document input stream, or <code>null</code>
     * @param metadata input metadata for the document
     * @return detected media type, or <code>application/octet-stream</code>
     * @throws IOException if the document input stream could not be read
     */
    MediaType detect(InputStream input, Metadata metadata) throws IOException;

}