|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.biojava.bio.program.tagvalue.Indexer
public class Indexer
Listens to tag-value events and passes on indexing events to an IndexStore.
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.
Note: It is very important to configure the BioStoreFactory instance with all the right keys before hand.
File fileToIndex; // get this from somewhere BioStore store = bsf.createBioStore(); Indexer indexer = new Indexer(fileToIndex, store); indexer.setPrimaryKeyName("foo"); indexer.addSecondaryKey("bar"); indexer.addSecondaryKey("baz"); TagValueParser tvParser; // make this appropriate for your format TagValueListener listener; // make this appropriate for your format // and forward all events to changer Parser parser = new Parser(); while( parser.read(indexer.getReader(), tvParser, listener) ) { System.out.print("."); }
Constructor Summary | |
---|---|
Indexer(java.io.File file,
IndexStore indexStore)
Build a new Indexer. |
Method Summary | |
---|---|
void |
addSecondaryKey(java.lang.String secKeyName)
Add a secondary key. |
void |
endRecord()
The current record has ended. |
void |
endTag()
End the current tag. |
java.lang.String |
getPrimaryKeyName()
Retrieve the tag currently used as primary key. |
CountedBufferedReader |
getReader()
Retrieve the reader that can be safely used to index this file. |
void |
removeSecondaryKey(java.lang.String secKeyName)
Remove a secondary key. |
void |
setPrimaryKeyName(java.lang.String primaryKeyName)
Set the tag to use as a primary key in the index. |
void |
startRecord()
A new record is about to start. |
void |
startTag(java.lang.Object tag)
Start a new tag. |
void |
value(TagValueContext ctxt,
java.lang.Object value)
A value has been seen. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Indexer(java.io.File file, IndexStore indexStore) throws java.io.FileNotFoundException
file
- the file to be processedindexStore
- the IndexStore to write to
java.io.FileNotFoundException
Method Detail |
---|
public CountedBufferedReader getReader()
public void setPrimaryKeyName(java.lang.String primaryKeyName)
Set the tag to use as a primary key in the index.
Whenever a value for the primary key tag is seen, this is passed to the indexer as the primary key for indexing.
Primary keys must be unique between entries, and each entry must provide exactly one primary key value.
primaryKeyName
- the tag to use as primary keypublic java.lang.String getPrimaryKeyName()
public void addSecondaryKey(java.lang.String secKeyName)
Add a secondary key.
Secondary keys are potentially non-unique properties of the entries being indexed. Multiple records can use the same secondary key values, and a single record can have multiple values for a secondary key.
secKeyName
- the name of the secondary key to addpublic void removeSecondaryKey(java.lang.String secKeyName)
secKeyName
- the name of the secondary key to removepublic void startRecord()
TagValueListener
startRecord
in interface TagValueListener
public void startTag(java.lang.Object tag)
TagValueListener
startTag
in interface TagValueListener
tag
- the Object representing the new tagpublic void value(TagValueContext ctxt, java.lang.Object value)
TagValueListener
value
in interface TagValueListener
ctxt
- a TagValueContext that could be used to push a sub-documentvalue
- the value Object observedpublic void endTag()
TagValueListener
endTag
in interface TagValueListener
public void endRecord() throws ParserException
TagValueListener
endRecord
in interface TagValueListener
ParserException
- if the record can not be ended
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |