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 fromSimilarRule
s and checks if characters are similar.- Since:
- April 25, 2019
-
-
Constructor Summary
Constructors Constructor Description DefaultSimilarityManager()
-
Method Summary
Modifier and Type Method Description SimilarityManager
addSimilarity(SimilarRule rule)
Adds aSimilarRule
to the internal list.java.util.Optional<SimilarRule>
getRule(java.lang.String similarityRuleName)
Gets the instance ofSimilarRule
with the given name.void
getSafeRule(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 addedSimilarRule
s.boolean
isSimilar(ImageLetter first, ImageLetter second)
Finds any matchingSimilarRule
s for the firstImageLetter
, and then checks if the secondImageLetter
also matches any of them.SimilarityManager
loadDefaults()
Load the defaultSimilarRule
s, otherwise all rules will need to be added manually viaSimilarityManager.addSimilarity(SimilarRule)
.SimilarityManager
removeSimilarity(java.lang.Class<? extends SimilarRule> ruleClass)
Removes aSimilarRule
from the internal list if found.
-
-
-
Method Detail
-
loadDefaults
public SimilarityManager loadDefaults()
Load the defaultSimilarRule
s, 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:SimilarityManager
Adds aSimilarRule
to the internal list.- Specified by:
addSimilarity
in interfaceSimilarityManager
- Parameters:
rule
- TheSimilarRule
to add- Returns:
- The current
SimilarityManager
-
removeSimilarity
public SimilarityManager removeSimilarity(java.lang.Class<? extends SimilarRule> ruleClass)
Description copied from interface:SimilarityManager
Removes aSimilarRule
from the internal list if found.- Specified by:
removeSimilarity
in interfaceSimilarityManager
- Parameters:
ruleClass
- TheSimilarRule
to add if found- Returns:
- The current
SimilarityManager
-
isSimilar
public boolean isSimilar(ImageLetter first, ImageLetter second)
Description copied from interface:SimilarityManager
Finds any matchingSimilarRule
s for the firstImageLetter
, and then checks if the secondImageLetter
also matches any of them.- Specified by:
isSimilar
in interfaceSimilarityManager
- Parameters:
first
- The firstImageLetter
second
- The secondImageLetter
- Returns:
- If the two
ImageLetter
s are similar
-
getRule
public java.util.Optional<SimilarRule> getRule(java.lang.String similarityRuleName)
Description copied from interface:SimilarityManager
Gets the instance ofSimilarRule
with the given name.- Specified by:
getRule
in interfaceSimilarityManager
- Parameters:
similarityRuleName
- The name of theSimilarRule
to get, if present- Returns:
- A
SimilarRule
with the given name
-
getSafeRule
public void getSafeRule(java.lang.String similarityRuleName, java.util.function.Consumer<SimilarRule> ruleConsumer)
Description copied from interface:SimilarityManager
Gets a rule from the given name, and if found, sends it through the consumer. A message is sent saying theSimilarRule
is not found if one isn't found.- Specified by:
getSafeRule
in interfaceSimilarityManager
- Parameters:
similarityRuleName
- The name of theSimilarRule
to getruleConsumer
- The consumer to be given theSimilarRule
if 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:SimilarityManager
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 addedSimilarRule
s.- Specified by:
getSecondHighest
in interfaceSimilarityManager
- Parameters:
data
- The possible combination data- Returns:
- If found, the second character
-
-