Search in sources :

Example 1 with CorpusLexiconBuilder

use of com.joliciel.jochre.lexicon.CorpusLexiconBuilder in project jochre by urieli.

the class Jochre method doCommandBuildLexicon.

/**
 * Rebuild the training corpus lexicon.
 */
public void doCommandBuildLexicon(File outputDir, CorpusSelectionCriteria criteria) {
    try {
        CorpusLexiconBuilder builder = new CorpusLexiconBuilder(criteria, jochreSession);
        TextFileLexicon lexicon = builder.buildLexicon();
        File textFile = new File(outputDir, "jochreCorpusLexicon.txt");
        textFile.delete();
        Writer textFileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(textFile, true), "UTF8"));
        try {
            lexicon.writeFile(textFileWriter);
        } finally {
            textFileWriter.flush();
            textFileWriter.close();
        }
        File lexiconFile = new File(outputDir, "jochreCorpusLexicon.zip");
        lexicon.serialize(lexiconFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : CorpusLexiconBuilder(com.joliciel.jochre.lexicon.CorpusLexiconBuilder) FileOutputStream(java.io.FileOutputStream) TextFileLexicon(com.joliciel.jochre.lexicon.TextFileLexicon) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) UnknownWordListWriter(com.joliciel.jochre.lexicon.UnknownWordListWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) LexiconErrorWriter(com.joliciel.jochre.lexicon.LexiconErrorWriter) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Aggregations

CorpusLexiconBuilder (com.joliciel.jochre.lexicon.CorpusLexiconBuilder)1 LexiconErrorWriter (com.joliciel.jochre.lexicon.LexiconErrorWriter)1 TextFileLexicon (com.joliciel.jochre.lexicon.TextFileLexicon)1 UnknownWordListWriter (com.joliciel.jochre.lexicon.UnknownWordListWriter)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1