Package net.sf.okapi.tm.pensieve.writer
Class PensieveWriter
- java.lang.Object
-
- net.sf.okapi.tm.pensieve.writer.PensieveWriter
-
-
Constructor Summary
Constructors Constructor Description PensieveWriter(org.apache.lucene.store.Directory indexDirectory, boolean createNewTmIndex)
Creates a PensieveWriter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Commits and closes (for now) the transaction.void
commit()
Forces a commit against the index.void
delete(String id)
Deletes a TranslationUnit based on the id.org.apache.lucene.index.IndexWriter
getIndexWriter()
Gets a handle on the IndexWriter so that commits and rollbacks can happen outside.void
indexTranslationUnit(TranslationUnit tu)
Adds a TranslationUnit to the indexvoid
indexTranslationUnit(TranslationUnit tu, boolean overwrite)
Indexes a given translation unit, possibly overwriting an existing one with the same source.void
update(TranslationUnit tu)
Updates a TranslationUnit.
-
-
-
Constructor Detail
-
PensieveWriter
public PensieveWriter(org.apache.lucene.store.Directory indexDirectory, boolean createNewTmIndex) throws IOException
Creates a PensieveWriter- Parameters:
indexDirectory
- - the Lucene Directory implementation of choice.createNewTmIndex
- Set to false to append to the existing TM index file. Set to true to overwrite.- Throws:
IOException
- if the indexDirectory can not load
-
-
Method Detail
-
close
public void close()
Commits and closes (for now) the transaction.- Specified by:
close
in interfaceITmWriter
- Throws:
OkapiIOException
- if the commit cannot happen.
-
commit
public void commit()
Forces a commit against the index.
-
getIndexWriter
public org.apache.lucene.index.IndexWriter getIndexWriter()
Gets a handle on the IndexWriter so that commits and rollbacks can happen outside. For now, this is a convenience method. In other words, don't depend on it working for you.- Returns:
- a handle on the IndexWriter used to Create, Update or Delete the index.
-
indexTranslationUnit
public void indexTranslationUnit(TranslationUnit tu)
Adds a TranslationUnit to the index- Specified by:
indexTranslationUnit
in interfaceITmWriter
- Parameters:
tu
- The TranslationUnit to index- Throws:
IOException
- if the TU can not be indexed.IllegalArgumentException
- if tu is null
-
indexTranslationUnit
public void indexTranslationUnit(TranslationUnit tu, boolean overwrite)
Description copied from interface:ITmWriter
Indexes a given translation unit, possibly overwriting an existing one with the same source.- Specified by:
indexTranslationUnit
in interfaceITmWriter
- Parameters:
tu
- the translation unit to index.overwrite
- true to overwrite any existing unit that has the same source content (codes excluded)
-
delete
public void delete(String id)
Deletes a TranslationUnit based on the id.- Specified by:
delete
in interfaceITmWriter
- Parameters:
id
- The Unique ID of the TU to delete- Throws:
OkapiIOException
- if the delete can not happenIllegalArgumentException
- if the id is invalid
-
update
public void update(TranslationUnit tu)
Updates a TranslationUnit.- Specified by:
update
in interfaceITmWriter
- Parameters:
tu
- The TranslationUnit to update- Throws:
IOException
- if the update can not happenIllegalArgumentException
- if the tu or MetadataType.ID is null
-
-