So Im creating an optical text reader using google camera api for OCR. When reaeding from the camera i want to filter the read strings by matching them to a list of strings and if the read string partially matches, the item from the list gets added and displayed.
Everything but the filtering works.
Say i have a list containing the string:
"BigSizeScrew 45**"
I want to match the read string:
"BigSizeScrew"
...to the one with the number and then add the string containing the number too.
The number and stars are for another reason but must be kept, the reason is irrelevant to the question.
tl;dr:
How do i match partially match a string to an existing string from a list?
I have the following but it exclusively searches for a 100% matching string, not if the checked string contains a substring of the read string.
for(int i =0;i<items.size();++i){
if (list.contains(items.valueAt(i))) {
TextBlock item = items.valueAt(i);
stringBuilder.append(item.getValue());
stringBuilder.append("\n");
}
}
EDIT:
The list contains approx 200 different strings that should be matchable partially. But all in the same way; Partially matching the main string but not the numbers/stars.
You can do something like this by adding a if
condition:
for(int i =0;i<items.size();++i){
if (list.contains(items.valueAt(i))) {
TextBlock item = items.valueAt(i);
if(item.getValue().indexOf("Your String") > -1){
stringBuilder.append(item.getValue());
stringBuilder.append("\n");
}
}
}
In place of your string
use the string value you want to search for.
Use indexOf()method. Index of method give index of matching string. So it its value is greater than -1, that means seach string exist in list and you can use that string.
You can use the startsWith
method of String
. If ocrString
has value BigSizeScrew 45**
then execute a for
loop to the list with the strings to match, and if(ocrString.startsWith(list.get(i)) then ...
.
I think you may actually want a fuzzy sentence matcher. If letters are not captured by the optics you'll need to interpolate what they might be. It gets into NLP but might be the proper way to implement.
Here is a link to Smith-Waterman wikipedia: https://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm
Leveshtein Distance: https://en.wikipedia.org/wiki/Levenshtein_distance
There are various implementations and libraries to do a single function call on each statement read. "Local sentence alignment" is the problem you are trying to solve. Forget exact match when screen readers are involved expect human and computer error.
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
We have a Web applicationFor the same, we have three separate code bases for three different regions
Hi I am a beginning java learner, and need to run my code in EclipseHowever I encountered below error:
I am working on android in purchase projectI used this sample code as reference
I have a frontend and a backend repository for my appThe backend is written in Go and serves the API over gRPC