Class LexiconIO


  • public final class LexiconIO
    extends Object
    Utility methods reading and writing Lexicon
    Author:
    David B. Bracewell
    • 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 name
        csvFile - the csv file
        updater - 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 file
        updater - 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 lexicon
        lexiconResource - 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 lexicon
        lexiconResource - the lexicon resource to write to
        defaultTag - the default tag to assign entries
        Throws:
        IOException - Something went wrong writing the lexicon