Package org.biojava.bio.program.tagvalue
Class Indexer2
- java.lang.Object
-
- org.biojava.bio.program.tagvalue.Indexer2
-
- All Implemented Interfaces:
TagValueListener
public class Indexer2 extends Object implements TagValueListener
Listens to tag-value events and passes on indexing events to an IndexStore. This is an update to Indexer that understands that indexed properties may not be at the top level.
This class is provided to allow the indexing of arbitrary record-based text files. Indexer objects are built for a single file and the indexes are written to a single index store. To keep all of the reader offsets in sync with one another, you will almost certainly wish to use the getReader() method to retrieve a CountedBufferedReader instance if you want to read the byte-offset between calls to Parser.read(). Below is an example of how to index a file.
File fileToIndex; // get this from somewhere // don't forget to register all the apropreate keys to the factory first. BioIndexStore indexStore = bioIndxStrFact.createBioStore(); Indexer indexer = new Indexer(fileToIndex, indexStore); indexer.setPrimaryKeyName("foo", new String[] { "foo" }); indexer.addSecondaryKey("bar", new String[] { "x", "y", "bar"}); indexer.addSecondaryKey("baz", new String[] { "z" }); TagValueParser tvParser; // make this appropriate for your format TagValueListener listener; // make this appropriate for your format // and forward all events to indexer Parser parser = new Parser(); while( parser.read(indexer.getReader(), tvParser, listener) ) { System.out.print("."); }- Since:
- 1.2
- Author:
- Matthew Pocock
-
-
Constructor Summary
Constructors Constructor Description Indexer2(File file, IndexStore indexStore, Index2Model model)Build a new Indexer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidendRecord()The current record has ended.voidendTag()End the current tag.CountedBufferedReadergetReader()Retrieve the reader that can be safely used to index this file.voidstartRecord()A new record is about to start.voidstartTag(Object tag)Start a new tag.voidvalue(TagValueContext ctxt, Object value)A value has been seen.
-
-
-
Constructor Detail
-
Indexer2
public Indexer2(File file, IndexStore indexStore, Index2Model model) throws FileNotFoundException
Build a new Indexer.- Parameters:
file- the file to be processedindexStore- the IndexStore to write to- Throws:
FileNotFoundException
-
-
Method Detail
-
getReader
public CountedBufferedReader getReader()
Retrieve the reader that can be safely used to index this file.- Returns:
- the CountedBufferedReader that should be processed
-
startRecord
public void startRecord()
Description copied from interface:TagValueListenerA new record is about to start.- Specified by:
startRecordin interfaceTagValueListener
-
startTag
public void startTag(Object tag)
Description copied from interface:TagValueListenerStart a new tag.- Specified by:
startTagin interfaceTagValueListener- Parameters:
tag- the Object representing the new tag
-
value
public void value(TagValueContext ctxt, Object value)
Description copied from interface:TagValueListenerA value has been seen.- Specified by:
valuein interfaceTagValueListener- Parameters:
ctxt- a TagValueContext that could be used to push a sub-documentvalue- the value Object observed
-
endTag
public void endTag()
Description copied from interface:TagValueListenerEnd the current tag.- Specified by:
endTagin interfaceTagValueListener
-
endRecord
public void endRecord() throws ParserException
Description copied from interface:TagValueListenerThe current record has ended.- Specified by:
endRecordin interfaceTagValueListener- Throws:
ParserException- if the record can not be ended
-
-