Sign in to follow this  
Followers 0
lokster

similar_text() UDF

6 posts in this topic

#1 ·  Posted (edited)

This is just like the PHP similar_text() function.

;===============================================================================
;
; Description:      Calculate the similarity between two strings
; Parameter(s):     $sString1  - The first string.
;                   $sString2  - The second string.
;                   $fPercent - if TRUE similar_text() will calculate the 
;                   similarity in percent for you. If FALSE, the result is 
;                   the length of largest common subsequence
; Requirement(s):   None
; Return Value(s):  Similarity between the two strings (in percent or in 
;                   character count)
; Author(s):        lokster <lokiisyourmaster AT gmail DOT com>
; Note(s):
;
;===============================================================================
Func _StringSimilar($sString1,$sString2,$fPercent = True)
    Local $iLen = (StringLen($sString1) + StringLen($sString2)) / 2
    $sString1 = StringSplit($sString1,"")
    $sString2 = StringSplit($sString2,"")
    Local $iLen1 = UBound($sString1)-1
    Local $iLen2 = UBound($sString2)-1
    Local $aTable[$iLen1+1][$iLen2+1]
    For $iIndex1=1 to $iLen1-1
        $aTable[$iIndex1][0]=0
    Next
    For $iIndex2=1 to $iLen2-1
        $aTable[0][$iIndex2]=0
    Next
    For $iIndex1 = 1 to $iLen1
        For $iIndex2 = 1 to $iLen2
            If ($sString1[$iIndex1]==$sString2[$iIndex2]) Then
                $aTable[$iIndex1][$iIndex2] = $aTable[$iIndex1-1][$iIndex2-1] + 1
            ElseIf ($aTable[$iIndex1-1][$iIndex2] >= $aTable[$iIndex1][$iIndex2-1]) Then
                $aTable[$iIndex1][$iIndex2] = $aTable[$iIndex1-1][$iIndex2]
            else
                $aTable[$iIndex1][$iIndex2] = $aTable[$iIndex1][$iIndex2-1]
            EndIf
        Next
    Next
    if $fPercent Then
        return ($aTable[$iLen1][$iLen2]*100)/$iLen
    Else
        return $aTable[$iLen1][$iLen2]
    EndIf
EndFunc
Edited by lokster

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is similarity between the TEXT in the strings, not between the bits of the characters.

"AutoIt" means the same as "aUTOit" and the same as "AuToIt".

But if you're so smart, just comment the first lnes of the code...

Edited by lokster

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Lets not get it so personal, but what do you mean when you say "good" posts (in quotes) ?!?

(it looks like that you haven't read most of my posts...

At least I have posted here, and don't have some miserable 12 posts... yeah... you are a "good" and "intelligent" contributor to the community....)

F.O.

Edited by lokster

Share this post


Link to post
Share on other sites

Lets not get it so personal, but what do you mean when you say "good" posts (in quotes) ?!?

(it looks like that you haven't read most of my posts...

At least I have posted here, and don't have some miserable 12 posts... yeah... you are a "good" and "intelligent" contributor to the community....)

F.O.

Lokster, don't let this nimrod get you down. He too self-righteous to make helpful comments, and seems to have the need to make himself feel better by picking on people. Apparently, picking on Richard Robertson earlier wasn't enough for him (see here), now hes moved on to you. See, he sees pissing people off to be "contributing" so thats what hes been trying to do.

Next time he "contributes" like this, I will bring it to the attention of JdeB or Valik. No one likes a troll.

I wasn't questioning your intelligence in this instance, just the lack of it (based on the "good" posts I've seen of yours in the past).

And in regards to this, I will just say I personally have had about enough of your smart-ass offensive and rude posts. I don't give a rats ass how long you've used autoit, or "clever" your damn insults are. This a community centered around support. and I would sure like to see who exactly you have supported in all of your 18 posts. If didn't have such a crappy attitude, I wouldn't be posting this, but there are several ways to point out something that may or may not be a flaw in a code without insulting or being rude.

Please, do us all a favor, and step away from the computer, at least until your ego shrinks.

Share this post


Link to post
Share on other sites

Now that that has been taken care of, I would like to thank you for sharing this lokster. :) It works nicely.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks Paulie :P

To be honest, I was not in the mood yesterday :)

In the matter of fact despite MyNameIs rude comment, he turns out to be right about changing the strings before comapring them for similarity...

I updated the function. Now its case sensitive and does not remove the spaces in the strings.

:Edit

And also the code is reformatted according the rules for formatting UDFs

First post updated.

Peace! :)

Edited by lokster

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0