Module NewOCR
Class DefaultSimilarityManager
- java.lang.Object
-
- com.uddernetworks.newocr.recognition.similarity.DefaultSimilarityManager
-
- All Implemented Interfaces:
SimilarityManager
public class DefaultSimilarityManager extends java.lang.Object implements SimilarityManager
Uses methods fromSimilarRules and checks if characters are similar.- Since:
- April 25, 2019
-
-
Constructor Summary
Constructors Constructor Description DefaultSimilarityManager()
-
Method Summary
Modifier and Type Method Description SimilarityManageraddSimilarity(SimilarRule rule)Adds aSimilarRuleto the internal list.java.util.Optional<SimilarRule>getRule(java.lang.String similarityRuleName)Gets the instance ofSimilarRulewith the given name.voidgetSafeRule(java.lang.String similarityRuleName, java.util.function.Consumer<SimilarRule> ruleConsumer)Gets a rule from the given name, and if found, sends it through the consumer.java.util.Optional<it.unimi.dsi.fastutil.objects.Object2DoubleMap.Entry<ImageLetter>>getSecondHighest(java.util.List<it.unimi.dsi.fastutil.objects.Object2DoubleMap.Entry<ImageLetter>> data)When given a list of the potential results of a character (Irrelevant what character it is), this will find the character lowest in the list that does not match the first character's letter and modifier to any of the addedSimilarRules.booleanisSimilar(ImageLetter first, ImageLetter second)Finds any matchingSimilarRules for the firstImageLetter, and then checks if the secondImageLetteralso matches any of them.SimilarityManagerloadDefaults()Load the defaultSimilarRules, otherwise all rules will need to be added manually viaSimilarityManager.addSimilarity(SimilarRule).SimilarityManagerremoveSimilarity(java.lang.Class<? extends SimilarRule> ruleClass)Removes aSimilarRulefrom the internal list if found.
-
-
-
Method Detail
-
loadDefaults
public SimilarityManager loadDefaults()
Load the defaultSimilarRules, otherwise all rules will need to be added manually viaSimilarityManager.addSimilarity(SimilarRule).- Returns:
- The current
SimilarityManager
-
addSimilarity
public SimilarityManager addSimilarity(SimilarRule rule)
Description copied from interface:SimilarityManagerAdds aSimilarRuleto the internal list.- Specified by:
addSimilarityin interfaceSimilarityManager- Parameters:
rule- TheSimilarRuleto add- Returns:
- The current
SimilarityManager
-
removeSimilarity
public SimilarityManager removeSimilarity(java.lang.Class<? extends SimilarRule> ruleClass)
Description copied from interface:SimilarityManagerRemoves aSimilarRulefrom the internal list if found.- Specified by:
removeSimilarityin interfaceSimilarityManager- Parameters:
ruleClass- TheSimilarRuleto add if found- Returns:
- The current
SimilarityManager
-
isSimilar
public boolean isSimilar(ImageLetter first, ImageLetter second)
Description copied from interface:SimilarityManagerFinds any matchingSimilarRules for the firstImageLetter, and then checks if the secondImageLetteralso matches any of them.- Specified by:
isSimilarin interfaceSimilarityManager- Parameters:
first- The firstImageLettersecond- The secondImageLetter- Returns:
- If the two
ImageLetters are similar
-
getRule
public java.util.Optional<SimilarRule> getRule(java.lang.String similarityRuleName)
Description copied from interface:SimilarityManagerGets the instance ofSimilarRulewith the given name.- Specified by:
getRulein interfaceSimilarityManager- Parameters:
similarityRuleName- The name of theSimilarRuleto get, if present- Returns:
- A
SimilarRulewith the given name
-
getSafeRule
public void getSafeRule(java.lang.String similarityRuleName, java.util.function.Consumer<SimilarRule> ruleConsumer)Description copied from interface:SimilarityManagerGets a rule from the given name, and if found, sends it through the consumer. A message is sent saying theSimilarRuleis not found if one isn't found.- Specified by:
getSafeRulein interfaceSimilarityManager- Parameters:
similarityRuleName- The name of theSimilarRuleto getruleConsumer- The consumer to be given theSimilarRuleif found
-
getSecondHighest
public java.util.Optional<it.unimi.dsi.fastutil.objects.Object2DoubleMap.Entry<ImageLetter>> getSecondHighest(java.util.List<it.unimi.dsi.fastutil.objects.Object2DoubleMap.Entry<ImageLetter>> data)
Description copied from interface:SimilarityManagerWhen given a list of the potential results of a character (Irrelevant what character it is), this will find the character lowest in the list that does not match the first character's letter and modifier to any of the addedSimilarRules.- Specified by:
getSecondHighestin interfaceSimilarityManager- Parameters:
data- The possible combination data- Returns:
- If found, the second character
-
-