- 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 voidaddAveragedData(java.lang.String name, double[] values)Adds a piece of data in the database (Never overrides existing data) to be averaged and fetched later.voidaddAveragedData(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.voidaddCustomSpace(char letter, double ratio)Adds a custom between-character space amount for after a character, as some fonts have different padding after certain character.voidaddLetterSegments(char letter, double[] segments)Adds segments (Percentage data points) to the database for a certain character, with a modifier of 0.voidaddLetterSegments(char letter, int modifier, double[] segments)Adds segments (Percentage data points) to the database for a certain character.voidclearData()Clears all data in the database, primarily used for before training.voidclearLetterSegments(char letter)Clears all data revolving around a character from both the `letters` and `sectionData` table.voidcreateLetterEntry(char letter, double averageWidth, double averageHeight, double minCenter, double maxCenter, boolean isLetter)Inserts into the `letters` table with a modifier of 0.voidcreateLetterEntry(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 theDatabaseCharacters 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.DataSourcegetDataSource()Gets theDataSourceused 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.StringgetName()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.booleanisTrainedSync()Gets if the database has been trained already.voidsetFontSize(char letter, int mod, double ratio)Sets the font size ratio for the given character and modifier.voidsetName(java.lang.String name)Sets the name of the database.voidsetProperty(java.lang.String name, boolean value)Sets the boolean property to the database.voidsetTrained(boolean trained)Sets the database value as trained or not.voidshutdown()Shuts down all executor threads when the program is ready to be terminated.voidshutdown(java.util.concurrent.TimeUnit unit, long duration)Shuts down all executor threads when the program is ready to be terminated after the specified time.booleanusesInternal()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.IOExceptionConnects 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.IOExceptionConnects 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:DatabaseManagerSets the name of the database. This has no effect on the actual function of the database.- Specified by:
setNamein interfaceDatabaseManager- Parameters:
name- The name of the database
-
getName
public java.lang.String getName()
Description copied from interface:DatabaseManagerGets the name of the database, which is by default it is either the file name or URL (Whichever one is given).- Specified by:
getNamein interfaceDatabaseManager- Returns:
- The name of the database
-
getDataSource
public javax.sql.DataSource getDataSource()
Description copied from interface:DatabaseManagerGets theDataSourceused by the DatabaseManager- Specified by:
getDataSourcein interfaceDatabaseManager- Returns:
- The
DataSourceused by the DatabaseManager
-
createLetterEntry
public void createLetterEntry(char letter, double averageWidth, double averageHeight, double minCenter, double maxCenter, boolean isLetter)Description copied from interface:DatabaseManagerInserts into the `letters` table with a modifier of 0.- Specified by:
createLetterEntryin 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:DatabaseManagerInserts into the `letters` table.- Specified by:
createLetterEntryin 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:DatabaseManagerClears all data revolving around a character from both the `letters` and `sectionData` table.- Specified by:
clearLetterSegmentsin interfaceDatabaseManager- Parameters:
letter- The character to clear
-
addLetterSegments
public void addLetterSegments(char letter, double[] segments)Description copied from interface:DatabaseManagerAdds segments (Percentage data points) to the database for a certain character, with a modifier of 0.- Specified by:
addLetterSegmentsin 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:DatabaseManagerAdds segments (Percentage data points) to the database for a certain character.- Specified by:
addLetterSegmentsin 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:DatabaseManagerGets all theDatabaseCharacters in the database- Specified by:
getAllCharacterSegmentsin interfaceDatabaseManager- Returns:
- A Future of all the
DatabaseCharacters
-
addAveragedData
public void addAveragedData(java.lang.String name, double[] values)Description copied from interface:DatabaseManagerAdds a piece of data in the database (Never overrides existing data) to be averaged and fetched later.- Specified by:
addAveragedDatain 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:DatabaseManagerAdds a piece of data in the database (Never overrides existing data) to be averaged and fetched later.- Specified by:
addAveragedDatain 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:DatabaseManagerGets the average value of the given data name, added fromDatabaseManager.addAveragedData(String, double[]). If no data is found, it will return -1.- Specified by:
getAveragedDatain 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:DatabaseManagerAdds 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:
addCustomSpacein 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:DatabaseManagerGets the custom between-character space associated with the character, to appear after the character.- Specified by:
getCustomSpacein 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:DatabaseManagerSets the font size ratio for the given character and modifier.- Specified by:
setFontSizein 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:DatabaseManagerGets the font size ratio from the given character and modifier.- Specified by:
getFontSizein 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:DatabaseManagerSets the boolean property to the database.- Specified by:
setPropertyin 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:DatabaseManagerGets the boolean property by the given name.- Specified by:
getPropertyin interfaceDatabaseManager- Parameters:
name- The name of the property to get- Returns:
- The property value
-
setTrained
public void setTrained(boolean trained)
Description copied from interface:DatabaseManagerSets the database value as trained or not. This only changes a boolean in the database.- Specified by:
setTrainedin 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:DatabaseManagerGets if the database has been trained already.- Specified by:
isTrainedin interfaceDatabaseManager- Returns:
- If the database has been trained
-
isTrainedSync
public boolean isTrainedSync()
Description copied from interface:DatabaseManagerGets 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:
isTrainedSyncin interfaceDatabaseManager- Returns:
- If the database has been trained
-
clearData
public void clearData()
Description copied from interface:DatabaseManagerClears all data in the database, primarily used for before training.- Specified by:
clearDatain interfaceDatabaseManager
-
shutdown
public void shutdown()
Description copied from interface:DatabaseManagerShuts down all executor threads when the program is ready to be terminated.- Specified by:
shutdownin interfaceDatabaseManager
-
shutdown
public void shutdown(java.util.concurrent.TimeUnit unit, long duration)Description copied from interface:DatabaseManagerShuts down all executor threads when the program is ready to be terminated after the specified time.- Specified by:
shutdownin interfaceDatabaseManager- Parameters:
unit- The Unit of timeduration- How long until it should shut down
-
usesInternal
public boolean usesInternal()
Description copied from interface:DatabaseManagerGets if the database manager is running off of the internal HSQLDB database or the external MySQL database.- Specified by:
usesInternalin interfaceDatabaseManager- Returns:
- If the database manager is using the internal HSQLDB database
-
-