Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing strings for accuracy (including offsets)

I am making a typing program where users type lines of words that appear on the screen and I need to check for accuracy. This would seem easy, however, I need to account for an offset. If the given line is "This is a test" and the user types "Thiss is a test", they should only have one error. However, the simplified way to check for accuracy with mark everything after the "ss" offset incorrect, when it should be right. Is there an easy way to do this?

like image 505
user3142972 Avatar asked Jul 19 '26 23:07

user3142972


1 Answers

Several string similarity algorithm are described here: http://www.morfoedro.it/doc.php?n=223&lang=en

I have been using the "Ratcliff/Obershelp" algorithm. It works as follows:

/*
 * divide s1 and s2 each into three parts
 * in the middle is the longest common substring between them
 * leaving (the possibly) empty left and right parts
 *
 *     pennsylvania  =  pennsy|lvan|ia
 *     pencilvaneya  =   penci|lvan|eya
 *
 *     pennsy  = |pen|nsy       ia   =  i|a|
 *     penci   = |pen|ci        eya  = ey|a|
 */
like image 143
John Hascall Avatar answered Jul 21 '26 12:07

John Hascall