Module NewOCR

Interface DatabaseManager

  • All Known Implementing Classes:
    OCRDatabaseManager

    public interface DatabaseManager
    The manager that provides methods to connect and interact with the database.
    • Method Summary

      Modifier and Type Method Description
      void addAveragedData​(java.lang.String name, double[] values)
      Adds a piece of data in the database (Never overrides existing data) to be averaged and fetched later.
      void addAveragedData​(java.lang.String name, it.unimi.dsi.fastutil.doubles.DoubleList values)
      Adds a piece of data in the database (Never overrides existing data) to be averaged and fetched later.
      void addCustomSpace​(char letter, double ratio)
      Adds a custom between-character space amount for after a character, as some fonts have different padding after certain character.
      void addLetterSegments​(char letter, double[] segments)
      Adds segments (Percentage data points) to the database for a certain character, with a modifier of 0.
      void addLetterSegments​(char letter, int modifier, double[] segments)
      Adds segments (Percentage data points) to the database for a certain character.
      void clearData()
      Clears all data in the database, primarily used for before training.
      void clearLetterSegments​(char letter)
      Clears all data revolving around a character from both the `letters` and `sectionData` table.
      void createLetterEntry​(char letter, double averageWidth, double averageHeight, double minCenter, double maxCenter, boolean isLetter)
      Inserts into the `letters` table with a modifier of 0.
      void createLetterEntry​(char letter, int modifier, double averageWidth, double averageHeight, double minCenter, double maxCenter, boolean isLetter)
      Inserts into the `letters` table.
      java.util.concurrent.Future<java.util.List<DatabaseCharacter>> getAllCharacterSegments()
      Gets all the DatabaseCharacters in the database
      java.util.concurrent.Future<java.lang.Double> getAveragedData​(java.lang.String name)
      Gets the average value of the given data name, added from addAveragedData(String, double[]).
      java.util.concurrent.Future<java.lang.Double> getCustomSpace​(char letter)
      Gets the custom between-character space associated with the character, to appear after the character.
      javax.sql.DataSource getDataSource()
      Gets the DataSource used by the DatabaseManager
      java.util.concurrent.Future<java.lang.Double> getFontSize​(char letter, int mod)
      Gets the font size ratio from the given character and modifier.
      java.lang.String getName()
      Gets the name of the database, which is by default it is either the file name or URL (Whichever one is given).
      java.util.concurrent.Future<java.util.Optional<java.lang.Boolean>> getProperty​(java.lang.String name)
      Gets the boolean property by the given name.
      java.util.concurrent.Future<java.util.Optional<java.lang.Boolean>> isTrained()
      Gets if the database has been trained already.
      boolean isTrainedSync()
      Gets if the database has been trained already.
      void setFontSize​(char letter, int mod, double ratio)
      Sets the font size ratio for the given character and modifier.
      void setName​(java.lang.String name)
      Sets the name of the database.
      void setProperty​(java.lang.String name, boolean value)
      Sets the boolean property to the database.
      void setTrained​(boolean trained)
      Sets the database value as trained or not.
      void shutdown()
      Shuts down all executor threads when the program is ready to be terminated.
      void shutdown​(java.util.concurrent.TimeUnit unit, long duration)
      Shuts down all executor threads when the program is ready to be terminated after the specified time.
      boolean usesInternal()
      Gets if the database manager is running off of the internal HSQLDB database or the external MySQL database.
    • Method Detail

      • setName

        void setName​(java.lang.String name)
        Sets the name of the database. This has no effect on the actual function of the database.
        Parameters:
        name - The name of the database
      • getName

        java.lang.String getName()
        Gets the name of the database, which is by default it is either the file name or URL (Whichever one is given).
        Returns:
        The name of the database
      • getDataSource

        javax.sql.DataSource getDataSource()
        Gets the DataSource used by the DatabaseManager
        Returns:
        The DataSource used by the DatabaseManager
      • createLetterEntry

        void createLetterEntry​(char letter,
                               double averageWidth,
                               double averageHeight,
                               double minCenter,
                               double maxCenter,
                               boolean isLetter)
        Inserts into the `letters` table with a modifier of 0.
        Parameters:
        letter - The character to insert
        averageWidth - The average width of the character
        averageHeight - The average height of the character
        minCenter - The minimum relative center from the top found in the training ste for the font size
        maxCenter - The maximum relative center from the top found in the training ste for the font size
        isLetter - If the character is a letter (true) or if it is a space (false)
      • createLetterEntry

        void createLetterEntry​(char letter,
                               int modifier,
                               double averageWidth,
                               double averageHeight,
                               double minCenter,
                               double maxCenter,
                               boolean isLetter)
        Inserts into the `letters` table.
        Parameters:
        letter - The character to insert
        modifier - The modifier of the data, for multi-part characters such as "
        averageWidth - The average width of the character
        averageHeight - The average height of the character
        minCenter - The minimum relative center from the top found in the training ste for the font size
        maxCenter - The maximum relative center from the top found in the training ste for the font size
        isLetter - If the character is a letter (true) or if it is a space (false)
      • clearLetterSegments

        void clearLetterSegments​(char letter)
        Clears all data revolving around a character from both the `letters` and `sectionData` table.
        Parameters:
        letter - The character to clear
      • addLetterSegments

        void addLetterSegments​(char letter,
                               double[] segments)
        Adds segments (Percentage data points) to the database for a certain character, with a modifier of 0.
        Parameters:
        letter - The character to add segments to
        segments - An array with a length of 17 all <= 1 as percentage data points
      • addLetterSegments

        void addLetterSegments​(char letter,
                               int modifier,
                               double[] segments)
        Adds segments (Percentage data points) to the database for a certain character.
        Parameters:
        letter - The character to add segments to
        modifier - The modifier of the letter
        segments - An array with a length of 17 all <= 1 as percentage data points
      • addAveragedData

        void addAveragedData​(java.lang.String name,
                             double[] values)
        Adds a piece of data in the database (Never overrides existing data) to be averaged and fetched later.
        Parameters:
        name - The name of the data
        values - The value to be added
      • addAveragedData

        void addAveragedData​(java.lang.String name,
                             it.unimi.dsi.fastutil.doubles.DoubleList values)
        Adds a piece of data in the database (Never overrides existing data) to be averaged and fetched later.
        Parameters:
        name - The name of the data
        values - The value to be added
      • getAveragedData

        java.util.concurrent.Future<java.lang.Double> getAveragedData​(java.lang.String name)
        Gets the average value of the given data name, added from addAveragedData(String, double[]). If no data is found, it will return -1.
        Parameters:
        name - The name of the data to fetch and average
        Returns:
        The averaged data, being -1 if no data is found
      • addCustomSpace

        void addCustomSpace​(char letter,
                            double ratio)
        Adds a custom between-character space amount for after a character, as some fonts have different padding after certain character. This calculated with of padding after a character is subtracted from the amount needed for a space.
        Parameters:
        letter - The letter before the space width
        ratio - The width/height ratio of the space
      • getCustomSpace

        java.util.concurrent.Future<java.lang.Double> getCustomSpace​(char letter)
        Gets the custom between-character space associated with the character, to appear after the character.
        Parameters:
        letter - The letter this space associates with
        Returns:
        The custom between-character space width/height ratio, or 0 if no custom space is found
      • setFontSize

        void setFontSize​(char letter,
                         int mod,
                         double ratio)
        Sets the font size ratio for the given character and modifier.
        Parameters:
        letter - The character to set
        mod - The modifier of the character
        ratio - The ratio
      • getFontSize

        java.util.concurrent.Future<java.lang.Double> getFontSize​(char letter,
                                                                  int mod)
        Gets the font size ratio from the given character and modifier.
        Parameters:
        letter - The letter to get
        mod - The modifier of the letter
        Returns:
        The font size ratio
      • setProperty

        void setProperty​(java.lang.String name,
                         boolean value)
        Sets the boolean property to the database.
        Parameters:
        name - The name of the property
        value - The property value
      • getProperty

        java.util.concurrent.Future<java.util.Optional<java.lang.Boolean>> getProperty​(java.lang.String name)
        Gets the boolean property by the given name.
        Parameters:
        name - The name of the property to get
        Returns:
        The property value
      • setTrained

        void setTrained​(boolean trained)
        Sets the database value as trained or not. This only changes a boolean in the database.
        Parameters:
        trained - If the database is trained or not
      • isTrained

        java.util.concurrent.Future<java.util.Optional<java.lang.Boolean>> isTrained()
        Gets if the database has been trained already.
        Returns:
        If the database has been trained
      • isTrainedSync

        boolean isTrainedSync()
        Gets if the database has been trained already. This differs from isTrained() because this is done fully synchronous and defaults to false if not found.
        Returns:
        If the database has been trained
      • clearData

        void clearData()
        Clears all data in the database, primarily used for before training.
      • shutdown

        void shutdown()
        Shuts down all executor threads when the program is ready to be terminated.
      • shutdown

        void shutdown​(java.util.concurrent.TimeUnit unit,
                      long duration)
        Shuts down all executor threads when the program is ready to be terminated after the specified time.
        Parameters:
        unit - The Unit of time
        duration - How long until it should shut down
      • usesInternal

        boolean usesInternal()
        Gets if the database manager is running off of the internal HSQLDB database or the external MySQL database.
        Returns:
        If the database manager is using the internal HSQLDB database