Module NewOCR

Class OCRDatabaseManager

    • Constructor Summary

      Constructors 
      Constructor Description
      OCRDatabaseManager​(boolean useInternal, java.io.File filePath, java.lang.String databaseURL, java.lang.String username, java.lang.String password)  
      OCRDatabaseManager​(java.io.File filePath)
      Connects to the internal database provided by HSQLDB in the given location, and executes the queries found in letters.sql and sectionData.sql.
      OCRDatabaseManager​(java.lang.String databaseURL, java.lang.String username, java.lang.String password)
      Connects to the database with the given credentials, and executes the queries found in letters.sql and sectionData.sql
    • 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 DatabaseManager.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OCRDatabaseManager

        public OCRDatabaseManager​(java.lang.String databaseURL,
                                  java.lang.String username,
                                  java.lang.String password)
                           throws java.io.IOException
        Connects to the database with the given credentials, and executes the queries found in letters.sql and sectionData.sql
        Parameters:
        databaseURL - The URL to the database
        username - The username of the connecting account
        password - The password of the connecting account
        Throws:
        java.io.IOException - If there are issues when creating/accessing the pool
      • OCRDatabaseManager

        public OCRDatabaseManager​(java.io.File filePath)
                           throws java.io.IOException
        Connects to the internal database provided by HSQLDB in the given location, and executes the queries found in letters.sql and sectionData.sql. This option can be over 12x faster than the MySQL variant.
        Parameters:
        filePath - The file without an extension of the database. If this doesn't exist, it will be created
        Throws:
        java.io.IOException - If there are issues when creating/accessing the pool
      • OCRDatabaseManager

        public OCRDatabaseManager​(boolean useInternal,
                                  java.io.File filePath,
                                  java.lang.String databaseURL,
                                  java.lang.String username,
                                  java.lang.String password)
                           throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • setName

        public void setName​(java.lang.String name)
        Description copied from interface: DatabaseManager
        Sets the name of the database. This has no effect on the actual function of the database.
        Specified by:
        setName in interface DatabaseManager
        Parameters:
        name - The name of the database
      • getName

        public java.lang.String getName()
        Description copied from interface: DatabaseManager
        Gets the name of the database, which is by default it is either the file name or URL (Whichever one is given).
        Specified by:
        getName in interface DatabaseManager
        Returns:
        The name of the database
      • getDataSource

        public javax.sql.DataSource getDataSource()
        Description copied from interface: DatabaseManager
        Gets the DataSource used by the DatabaseManager
        Specified by:
        getDataSource in interface DatabaseManager
        Returns:
        The DataSource used by the DatabaseManager
      • createLetterEntry

        public void createLetterEntry​(char letter,
                                      double averageWidth,
                                      double averageHeight,
                                      double minCenter,
                                      double maxCenter,
                                      boolean isLetter)
        Description copied from interface: DatabaseManager
        Inserts into the `letters` table with a modifier of 0.
        Specified by:
        createLetterEntry in interface DatabaseManager
        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

        public void createLetterEntry​(char letter,
                                      int modifier,
                                      double averageWidth,
                                      double averageHeight,
                                      double minCenter,
                                      double maxCenter,
                                      boolean isLetter)
        Description copied from interface: DatabaseManager
        Inserts into the `letters` table.
        Specified by:
        createLetterEntry in interface DatabaseManager
        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

        public void clearLetterSegments​(char letter)
        Description copied from interface: DatabaseManager
        Clears all data revolving around a character from both the `letters` and `sectionData` table.
        Specified by:
        clearLetterSegments in interface DatabaseManager
        Parameters:
        letter - The character to clear
      • addLetterSegments

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

        public void addLetterSegments​(char letter,
                                      int modifier,
                                      double[] segments)
        Description copied from interface: DatabaseManager
        Adds segments (Percentage data points) to the database for a certain character.
        Specified by:
        addLetterSegments in interface DatabaseManager
        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

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

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

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

        public void addCustomSpace​(char letter,
                                   double ratio)
        Description copied from interface: DatabaseManager
        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.
        Specified by:
        addCustomSpace in interface DatabaseManager
        Parameters:
        letter - The letter before the space width
        ratio - The width/height ratio of the space
      • getCustomSpace

        public java.util.concurrent.Future<java.lang.Double> getCustomSpace​(char letter)
        Description copied from interface: DatabaseManager
        Gets the custom between-character space associated with the character, to appear after the character.
        Specified by:
        getCustomSpace in interface DatabaseManager
        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

        public void setFontSize​(char letter,
                                int mod,
                                double ratio)
        Description copied from interface: DatabaseManager
        Sets the font size ratio for the given character and modifier.
        Specified by:
        setFontSize in interface DatabaseManager
        Parameters:
        letter - The character to set
        mod - The modifier of the character
        ratio - The ratio
      • getFontSize

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

        public void setProperty​(java.lang.String name,
                                boolean value)
        Description copied from interface: DatabaseManager
        Sets the boolean property to the database.
        Specified by:
        setProperty in interface DatabaseManager
        Parameters:
        name - The name of the property
        value - The property value
      • getProperty

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

        public void setTrained​(boolean trained)
        Description copied from interface: DatabaseManager
        Sets the database value as trained or not. This only changes a boolean in the database.
        Specified by:
        setTrained in interface DatabaseManager
        Parameters:
        trained - If the database is trained or not
      • isTrained

        public java.util.concurrent.Future<java.util.Optional<java.lang.Boolean>> isTrained()
        Description copied from interface: DatabaseManager
        Gets if the database has been trained already.
        Specified by:
        isTrained in interface DatabaseManager
        Returns:
        If the database has been trained
      • isTrainedSync

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

        public void clearData()
        Description copied from interface: DatabaseManager
        Clears all data in the database, primarily used for before training.
        Specified by:
        clearData in interface DatabaseManager
      • shutdown

        public void shutdown()
        Description copied from interface: DatabaseManager
        Shuts down all executor threads when the program is ready to be terminated.
        Specified by:
        shutdown in interface DatabaseManager
      • shutdown

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

        public boolean usesInternal()
        Description copied from interface: DatabaseManager
        Gets if the database manager is running off of the internal HSQLDB database or the external MySQL database.
        Specified by:
        usesInternal in interface DatabaseManager
        Returns:
        If the database manager is using the internal HSQLDB database