近似社会保险号匹配搜索算法

Algorithm for Approximate Social Security Number Match Search

我根据客户的社会安全号码写了一个申请到link文件,但有时客户写错了1或2位数字。我可以将哪些算法部署到 return 近似匹配?

对了我实现了通配符功能,如果手写不好让我通过数据库搜索。但是有时候手写的还好(他们只是写错了)

; Function to get the new SSN
; Keep in mind the searchCount is reset at the end of this function only.
; =============================================================================
GetSSN() {
    Global searchCount
    UserInput = Blank
    Length := StrLen(UserInput)

    while (Length < 9) 
    {
        InputBox, UserInput, Please Enter the SSN,,, 350, 100
        Length := StrLen(UserInput)
    }

    ; Use the SubStr method to extract the first character of the ssn
    firstCharacterOfInput := SubStr(UserInput, 1, 1)

    if (firstCharacterOfInput = 0) {
        StringTrimLeft, UserInput, UserInput, 1
    }

    ; Replace the wild card key "*" with the implementation required "."
    StringReplace, UserInput, UserInput, *,.

    ; Depend if the key contains a wild card, use normal / wild card search
    IfInString, UserInput, . 
    {
        ; MsgBox, WildCardSearch
        mFileName := WildCardSearch(UserInput)
    } else {
        ; MsgBox, NormalSearch
        mFileName := GetFileName(UserInput)
    }

    DrawFileName(mFileName)
    ; Reset searchCount for next time use
    searchCount = 0
}

; Function for wild card implementation
; Reference: http://www.adarshr.com/papers/wildcard
; The implementation used the RegEXMatch Expression
; =============================================================================
WildCardSearch(key) {
    Global dataCount, searchCount, DataBaseArray

    Loop, %dataCount% {
        currentLine := DataBaseArray%searchCount%_1
        FoundPos := RegExMatch(currentLine, key)

        if (FoundPos != 0) {
            result := DataBaseArray%searchCount%_2
            return result
        }
        searchCount += 1
    }

    notFoundMapName = Unable to find the member %A_Now%.jpg
    return notFoundMapName
}

一种方法是通过精确查找构建近似匹配。将 SSN 分为三个字段。如果只有两个错误,则这些字段中至少有一个必须没有错误。因此,构建三个表,每个表都允许您检索与其中一个字段完全匹配的所有 SSN。

给定一个近似的 SSN,从三个表中的每一个中检索所有完全匹配项,按您将其分解成的三个字段进行索引,并检查检索到的 SSN 以查看其中是否有不超过两个字符错误。

检查两个字符串是否几乎相同的一种简单方法是使用编辑距离。 http://en.wikipedia.org/wiki/Levenshtein_distance这个returns一个数字,数字越大两者相差越大

唯一的问题是 levenshtein 需要两个输入来计算距离,因此您无法快速计算数据库中的所有条目。该算法在批量执行时非常昂贵。

当然可以结合Mcdowellas的想法,那么你至少已经把音量降低到1/1000了