- java.lang.Object
-
- com.uddernetworks.newocr.database.OCRDatabaseManager
-
- All Implemented Interfaces:
DatabaseManager
public class OCRDatabaseManager extends java.lang.Object implements DatabaseManager
-
-
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 theDatabaseCharacter
s in the databasejava.util.concurrent.Future<java.lang.Double>
getAveragedData(java.lang.String name)
Gets the average value of the given data name, added fromDatabaseManager.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 theDataSource
used by the DatabaseManagerjava.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.
-
-
-
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 databaseusername
- The username of the connecting accountpassword
- 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 interfaceDatabaseManager
- 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 interfaceDatabaseManager
- Returns:
- The name of the database
-
getDataSource
public javax.sql.DataSource getDataSource()
Description copied from interface:DatabaseManager
Gets theDataSource
used by the DatabaseManager- Specified by:
getDataSource
in interfaceDatabaseManager
- 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 interfaceDatabaseManager
- Parameters:
letter
- The character to insertaverageWidth
- The average width of the characteraverageHeight
- The average height of the characterminCenter
- The minimum relative center from the top found in the training ste for the font sizemaxCenter
- The maximum relative center from the top found in the training ste for the font sizeisLetter
- 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 interfaceDatabaseManager
- Parameters:
letter
- The character to insertmodifier
- The modifier of the data, for multi-part characters such as "averageWidth
- The average width of the characteraverageHeight
- The average height of the characterminCenter
- The minimum relative center from the top found in the training ste for the font sizemaxCenter
- The maximum relative center from the top found in the training ste for the font sizeisLetter
- 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 interfaceDatabaseManager
- 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 interfaceDatabaseManager
- Parameters:
letter
- The character to add segments tosegments
- 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 interfaceDatabaseManager
- Parameters:
letter
- The character to add segments tomodifier
- The modifier of the lettersegments
- An array with a length of 17 all <= 1 as percentage data points
-
getAllCharacterSegments
public java.util.concurrent.Future<java.util.List<DatabaseCharacter>> getAllCharacterSegments()
Description copied from interface:DatabaseManager
Gets all theDatabaseCharacter
s in the database- Specified by:
getAllCharacterSegments
in interfaceDatabaseManager
- Returns:
- A Future of all the
DatabaseCharacter
s
-
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 interfaceDatabaseManager
- Parameters:
name
- The name of the datavalues
- 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 interfaceDatabaseManager
- Parameters:
name
- The name of the datavalues
- 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 fromDatabaseManager.addAveragedData(String, double[])
. If no data is found, it will return -1.- Specified by:
getAveragedData
in interfaceDatabaseManager
- 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 interfaceDatabaseManager
- Parameters:
letter
- The letter before the space widthratio
- 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 interfaceDatabaseManager
- 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 interfaceDatabaseManager
- Parameters:
letter
- The character to setmod
- The modifier of the characterratio
- 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 interfaceDatabaseManager
- Parameters:
letter
- The letter to getmod
- 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 interfaceDatabaseManager
- Parameters:
name
- The name of the propertyvalue
- 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 interfaceDatabaseManager
- 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 interfaceDatabaseManager
- 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 interfaceDatabaseManager
- 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 fromDatabaseManager.isTrained()
because this is done fully synchronous and defaults to false if not found.- Specified by:
isTrainedSync
in interfaceDatabaseManager
- 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 interfaceDatabaseManager
-
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 interfaceDatabaseManager
-
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 interfaceDatabaseManager
- Parameters:
unit
- The Unit of timeduration
- 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 interfaceDatabaseManager
- Returns:
- If the database manager is using the internal HSQLDB database
-
-