I am working on an app that uses OCR to grab text from an image and searches the text in a MYSQL database of ~10,000 records. Most of the time the text scanned from image is not accurate (missing or mispelled words) so I am using Fuse to do the fuzzy matching... it works well against a small lists but it is very slow running - it takes 5 mins to scan thru 10K records, and is not that accurate (about 50% match rate).
Can anyone recommend a library or method of taking mispelled or mis-ordered text from an OCR scan and matching it to the correct database record?
Here is the code I'm using:
// Setting variables
private var allBooks = [Book]()
let fuse = Fuse()
var bookNames = [String]()
var OCRArray : [String] = []
// Get all books from database
sqlConfig.configureMySQL()
BooksProvider().loadBooks { books in
self.allBooks = books
}
// Put list of books in string array in order for fuse search to work
for object in allBooks {
let strName = object.name ?? ""
bookNames.append(strName)
}
// Function that iterates thru each line of OCR scan that is stored in OCRArray
// This takes several 5+ to complete
func fuseMatch() {
for x in 0..<OCRArray.count {
var results = fuse.search(OCRArray[x], in: bookNames)
var fuseWine:String
if results.first != nil {
fuseMatch = bookNames[results[0].index]
} else {
fuseMatch = "Not found."
}
print(x, " | ", OCRArray[x], " | ", fuseMatch)
}
}