You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Brian Goetz <br...@quiotix.com> on 2002/01/18 05:50:19 UTC

Format Stripping [ was: XLS parser ]

>Welcome!  And POI looks great.

Here here!

>I would like to see folks come to some agreement on an API to use for such
>extensions, perhaps via an interface or base class - although I'm partial to
>the interface so as to not interfere with other folks object hierarchy and
>such.

The ability to easily handle various document file formats is an area where 
a little up-front work will make life a _lot_ easier for future (and 
current) users.

At first glance, the missing abstraction appears to be something like 
FormatStripper, which is basically like a FilterInputStream; it would take 
in a document of a specific format (Word, XLS, PDF, XML, etc) and return a 
stream of text corresponding to the "body" of the document.  This is an 
80-90% solution, and is probably worth doing because it is so easy.  Then 
we could hook up the HTML parser to a format stripper and include an 
HtmlFormatStripper in the core, which would be nice.

The remaining 10-20% come from the ability to extract metadata from the 
document as well.  Word documents have Author, Title, and CreationDate 
metadata, which are pretty useful in a multi-field text indexing system 
like Lucene; HTML documents have META tags which contain keywords, which 
are also very useful.

Unfortunately, the Lucene Document class is defined in such a way that 
would make it hard to collect both the body and the other fields in one 
pass on the input file.  While that irks the performance-weenie in me, in 
reality keeping one document in memory when scanning it probably isn't so 
horrible.  (I think Doug convinced me of that.)

I would say that there are two stages to defining how an arbitrary document 
will map into Lucene.  Lets call them the "Document Digester" and the 
"Document Mapper".  The document digester processes a document (say, a Word 
document) and breaks it down into multiple fields, like Author, Title, 
CreationDate, and Body.  The document mapper maps the fields created by the 
DD into fields that will actually get put into a Lucene index.

public interface DocumentDigester {
   /** Retrieve the fields supported by this Digester */
   public Set getFields();

   /** Digest a document into memory */
   public void digestDocument(InputStream in);

   /** Digest a document into a Lucene Document.  Could optimize the
     * loading process by not storing fields that are not desired by
     * the mapper */
   public Document digestDocument(InputStream in,
                                  DocumentMapper mapper);

   /** Retrieve a digested field */
   public String getFieldAsString(String field);

   public InputStream getFieldAsStream(String field);
}

public interface DocumentMapper {
   /** Indicate that we want to map a given field from the document into
    *  the given Lucene field.  These routines together basically define
    *  Map-like functionality.  There could be a convenience constructor
    *  that sets up the field mappings using a Properties */
   public void mapField(String documentField, String luceneField);
   public String getFieldMapping(String documentField);
}

Now, someone can wrap any given document format processor with a 
DocumentDigester, and then in order to import documents into Lucene, the 
user only need create the Mapper showing which fields he cares 
about.  Again, we can create an HtmlDigester from the existing parser and 
include it in the kit, along with adapters for various document parsing 
packages.



--
Brian Goetz
Quiotix Corporation
brian@quiotix.com           Tel: 650-843-1300            Fax: 650-324-8032

http://www.quiotix.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Format Stripping [ was: XLS parser ]

Posted by Brian Goetz <br...@quiotix.com>.
> > Unfortunately, the Lucene Document class is defined in such a way that 
> > would make it hard to collect both the body and the other fields in one 
> > pass on the input file.  While that irks the performance-weenie in me, in 
> > reality keeping one document in memory when scanning it probably isn't so 
> > horrible.  (I think Doug convinced me of that.)
> > 
> 
> POI::HSSF (Excel) and POIFS (OLE2CDF) may have a solution to that.  I'll
> have to look this over a bit harder.  We've implemented an event based
> system for reading documents (so you register for what you care about
> and then kick it off and it throws events to listeners as it runs into
> them).  Not sure if there is a clean way to graft those ideas onto
> Lucene for a single pass read.  I'll take a more comprehensive look at
> it.

Lucene doesn't make this easy, except in the degenerate case where you
can extract all the short fields at once relatively easily (like if
all the metadata is at the top of the file.)  Otherwise, Lucene wants
you to load up a Document with Strings (for short fields) and
InputStreams (for long fields), and then you hand the whole thing over
to Lucene for indexing.  But since you don't know what order it will
read the InputStreams in, basically you're going to have to make at
least one pass on the file, and buffer anything besides the data for
that field.  Except in the case of really simple file formats, like
those with a body only, it doesn't seem like its worth doing a lot of
work to try avoiding buffering the whole thing.  On the other hand, I
think the interface I proposed would let a smart filter for an easy
file format do it without buffering, maybe.

> Great.  I'll start work on this for Excel.  I'll include the interfaces
> above as you suggest (unless someone else would rather), I'll leave the
> HTMLDigester to someone who understands javacc a bit better. I'll ask
> the poi-devel if anyone would kindly write an interpreter for Document
> Summary information (not to bore you but its a "separate" document
> within an OLE 2 Compound Document).

Bear in mind this is just a proposal, and I'd like to hear comments
from the rest of the list, but I think the basic concept is clear enough
that you can start on an Excel implementation.  

> Just a suggestion but you might at some point in the future consider
> inverting this a tad for a future release of Lucene.  

I like the idea of being able to add fields to a Document after the
Document is indexed.  Then, for documents with a long 'body' and short
metadata fields, you could process the body through an InputStream
adapter, which would, as a side effect, store the other fields
somewhere, and then add them.  Doug, how hard would this be to support
adding some new fields to an already indexed document?  

But even in the absence of such a feature, you could avoid the
memory-hogging problem like this: make two passes on the file, first
extracting the short fields as Strings and putting them into the
Document, and then make another pass with a
SuckTheTextOutOfAnExcelDocumentInputStream filter.  Again, this could
be hidden behind the DocumentDigester interface.  It requires two
passes, but for structured documents like Office documents, that's not
bad as you can go right to where the header fields are stored, and
then handle the text through an input stream without buffering.

So the trade-off is -- full buffering, or two passes.  For most file
formats, the two passes are probably not too bad.  



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Format Stripping [ was: XLS parser ]

Posted by "Andrew C. Oliver" <ac...@nc.rr.com>.
On Thu, 2002-01-17 at 23:50, Brian Goetz wrote:
> 
> >Welcome!  And POI looks great.
> 
> Here here!
> 

Thanks!

> >I would like to see folks come to some agreement on an API to use for such
> >extensions, perhaps via an interface or base class - although I'm partial to
> >the interface so as to not interfere with other folks object hierarchy and
> >such.
> 
> The ability to easily handle various document file formats is an area where 
> a little up-front work will make life a _lot_ easier for future (and 
> current) users.
> 
> At first glance, the missing abstraction appears to be something like 
> FormatStripper, which is basically like a FilterInputStream; it would take 
> in a document of a specific format (Word, XLS, PDF, XML, etc) and return a 
> stream of text corresponding to the "body" of the document.  This is an 
> 80-90% solution, and is probably worth doing because it is so easy.  Then 
> we could hook up the HTML parser to a format stripper and include an 
> HtmlFormatStripper in the core, which would be nice.
> 
> The remaining 10-20% come from the ability to extract metadata from the 
> document as well.  Word documents have Author, Title, and CreationDate 
> metadata, which are pretty useful in a multi-field text indexing system 
> like Lucene; HTML documents have META tags which contain keywords, which 
> are also very useful.
> 

I'll go ahead and write or ask someone on the poi list to write a
summary info interpreter.  It looks trivial, we've just not needed it so
far.

> Unfortunately, the Lucene Document class is defined in such a way that 
> would make it hard to collect both the body and the other fields in one 
> pass on the input file.  While that irks the performance-weenie in me, in 
> reality keeping one document in memory when scanning it probably isn't so 
> horrible.  (I think Doug convinced me of that.)
> 

POI::HSSF (Excel) and POIFS (OLE2CDF) may have a solution to that.  I'll
have to look this over a bit harder.  We've implemented an event based
system for reading documents (so you register for what you care about
and then kick it off and it throws events to listeners as it runs into
them).  Not sure if there is a clean way to graft those ideas onto
Lucene for a single pass read.  I'll take a more comprehensive look at
it.

> I would say that there are two stages to defining how an arbitrary document 
> will map into Lucene.  Lets call them the "Document Digester" and the 
> "Document Mapper".  The document digester processes a document (say, a Word 
> document) and breaks it down into multiple fields, like Author, Title, 
> CreationDate, and Body.  The document mapper maps the fields created by the 
> DD into fields that will actually get put into a Lucene index.
> 
> public interface DocumentDigester {
>    /** Retrieve the fields supported by this Digester */
>    public Set getFields();
> 
>    /** Digest a document into memory */
>    public void digestDocument(InputStream in);
> 
>    /** Digest a document into a Lucene Document.  Could optimize the
>      * loading process by not storing fields that are not desired by
>      * the mapper */
>    public Document digestDocument(InputStream in,
>                                   DocumentMapper mapper);
> 
>    /** Retrieve a digested field */
>    public String getFieldAsString(String field);
> 
>    public InputStream getFieldAsStream(String field);
> }
> 
> public interface DocumentMapper {
>    /** Indicate that we want to map a given field from the document into
>     *  the given Lucene field.  These routines together basically define
>     *  Map-like functionality.  There could be a convenience constructor
>     *  that sets up the field mappings using a Properties */
>    public void mapField(String documentField, String luceneField);
>    public String getFieldMapping(String documentField);
> }
> 
> Now, someone can wrap any given document format processor with a 
> DocumentDigester, and then in order to import documents into Lucene, the 
> user only need create the Mapper showing which fields he cares 
> about.  Again, we can create an HtmlDigester from the existing parser and 
> include it in the kit, along with adapters for various document parsing 
> packages.
> 

Great.  I'll start work on this for Excel.  I'll include the interfaces
above as you suggest (unless someone else would rather), I'll leave the
HTMLDigester to someone who understands javacc a bit better. I'll ask
the poi-devel if anyone would kindly write an interpreter for Document
Summary information (not to bore you but its a "separate" document
within an OLE 2 Compound Document).

Just a suggestion but you might at some point in the future consider
inverting this a tad for a future release of Lucene.  Meaning if your
streams followed a similar pattern and threw "events" instead of
building fields, the index writer could listen for these fields based on
passed in parameters and the (file-type filter) reader or stream could
throw them as it came across them.  When we did this for POI::HSSF the
memory usage for reading a really large spreadsheet went down tenfold
and performance was roughly equal or perhaps a bit better (lets put it
this way...I could probably run POI::HSSF on my palm pilot :-D, but the
sample file wouldn't fit).  Anyhow this is just a thought we shamelessly
stole from SAX. :-)

For an example of how we do this check out:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/poi/poi/production/src/net/sourceforge/poi/hssf/eventmodel/

and

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/poi/poi/production/src/net/sourceforge/poi/hssf/dev/EFHSSF.java


Thanks,

Andy
> 
> 
> --
> Brian Goetz
> Quiotix Corporation
> brian@quiotix.com           Tel: 650-843-1300            Fax: 650-324-8032
> 
> http://www.quiotix.com
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
-- 
www.superlinksoftware.com
www.sourceforge.net/projects/poi - port of Excel format to java
http://developer.java.sun.com/developer/bugParade/bugs/4487555.html 
			- fix java generics!


The avalanche has already started. It is too late for the pebbles to
vote.
-Ambassador Kosh


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Please Review: Contributions page and other web site updates

Posted by ca...@bookandhammer.com.
Hi All,
I am providing a tar and gzipped instance of the latest versions of the 
Lucene website.
I have moved, and added some new things that I want others to review 
before I post it to the website live.

Changes include

Moved Bugs to resources
Added Lucene bugs to resources
Added Link to JGuru FAQ in resources
Changed name of FAQ to "FAQ Official" in resources
Add Contributions link in Resources
Added Contributions page with currently 4 sections (Overview, Lucene 
Documents, Analyzers, Misc).
	Note: I will add description text to each of these soon.

I have changed, stylesheets/project.xml
I have added contributions.xml

I did have a To Do link, but I didn't know how to search for to do's 
(i.e. new features) in Bugzilla. Any help would be appreciated.

Once I hear back from a few people that they think the changes are good, 
I'll post it.
Now that I have my setup, updates will not take as long.

Thanks

--Peter