Package com.gengoai.hermes.lexicon
Class LexiconIO
- java.lang.Object
-
- com.gengoai.hermes.lexicon.LexiconIO
-
public final class LexiconIO extends Object
Utility methods reading and writing Lexicon- Author:
- David B. Bracewell
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LexiconIO.CSVParameters
The type Csv parameters.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Lexicon
importCSV(@NonNull Resource csvFile, @NonNull Consumer<LexiconIO.CSVParameters> updater)
Imports a CSV file into an in-memory lexicon.static Lexicon
importCSV(@NonNull String name, @NonNull Resource csvFile, @NonNull Consumer<LexiconIO.CSVParameters> updater)
Imports a CSV file into an in-memory lexicon.static Lexicon
read(@NonNull Resource lexiconResource)
Reads a lexicon in Json format from the given lexicon resourcestatic Lexicon
read(@NonNull String name, @NonNull Resource lexiconResource)
Reads a lexicon in Json format from the given lexicon resourcestatic void
write(Lexicon lexicon, Resource lexiconResource, String defaultTag)
Writes the given lexicon to the given lexicon resource in Json format.
-
-
-
Method Detail
-
importCSV
public static Lexicon importCSV(@NonNull @NonNull String name, @NonNull @NonNull Resource csvFile, @NonNull @NonNull Consumer<LexiconIO.CSVParameters> updater) throws IOException
Imports a CSV file into an in-memory lexicon.- Parameters:
name
- the lexicon namecsvFile
- the csv fileupdater
- consumer to set the CSVParameters- Returns:
- the lexicon
- Throws:
IOException
- Something went wrong reading the CSV file
-
importCSV
public static Lexicon importCSV(@NonNull @NonNull Resource csvFile, @NonNull @NonNull Consumer<LexiconIO.CSVParameters> updater) throws IOException
Imports a CSV file into an in-memory lexicon.- Parameters:
csvFile
- the csv fileupdater
- consumer to set the CSVParameters- Returns:
- the lexicon
- Throws:
IOException
- Something went wrong reading the CSV file
-
read
public static Lexicon read(@NonNull @NonNull String name, @NonNull @NonNull Resource lexiconResource) throws IOException
Reads a lexicon in Json format from the given lexicon resource- Parameters:
name
- the name of the lexiconlexiconResource
- the lexicon resource- Returns:
- the lexicon
- Throws:
IOException
- Something went wrong reading the resource
-
read
public static Lexicon read(@NonNull @NonNull Resource lexiconResource) throws IOException
Reads a lexicon in Json format from the given lexicon resource- Parameters:
lexiconResource
- the lexicon resource- Returns:
- the lexicon
- Throws:
IOException
- Something went wrong reading the resource
-
write
public static void write(Lexicon lexicon, Resource lexiconResource, String defaultTag) throws IOException
Writes the given lexicon to the given lexicon resource in Json format.- Parameters:
lexicon
- the lexiconlexiconResource
- the lexicon resource to write todefaultTag
- the default tag to assign entries- Throws:
IOException
- Something went wrong writing the lexicon
-
-