Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- costCalc(ByRef tempText, ByRef regText)
- {
- distanceArray := []
- R_len := StrLen(tempText)
- C_len := StrLen(regText)
- r_index := 1
- while (r_index <= R_len)
- {
- c_index := 1
- while (c_index <= C_len)
- {
- if (SubStr(tempText, r_index, 1) = SubStr(regText, c_index, 1))
- {
- distanceArray[r_index, c_index] := 0
- }
- else
- {
- distanceArray[r_index, c_index] := 1
- }
- c_index := c_index + 1
- }
- r_index := r_index + 1
- }
- ;~ accumulated cost calc
- accumulatedCost := []
- accumulatedCost[1,1] := distanceArray[1,1]
- r_index := 2
- while (r_index <= R_len)
- {
- accumulatedCost[r_index, 1] := distanceArray[r_index, 1] + accumulatedCost[r_index-1, 1]
- r_index := r_index + 1
- }
- c_index := 2
- while (c_index <= C_len)
- {
- accumulatedCost[1, c_index] := distanceArray[1, c_index] + accumulatedCost[1, c_index-1]
- c_index := c_index + 1
- }
- r_index := 2
- while (r_index <= R_len)
- {
- c_index := 2
- while (c_index <= C_len)
- {
- min1 := min(accumulatedCost[r_index-1, c_index-1], accumulatedCost[r_index-1, c_index])
- accumulatedCost[r_index, c_index] := distanceArray[r_index, c_index] + min(min1, accumulatedCost[r_index, c_index-1])
- c_index := c_index + 1
- }
- r_index := r_index + 1
- }
- costV := accumulatedCost[R_len, C_len]
- costPercentV := costV / max(R_len, C_len) * 100.0
- result := {ref: regText, cost: costPercentV}
- return result
- }
- dtw(ByRef testV)
- {
- refArray := ["Autohotkey", "Autoit", "Python", "Powershell", "Ruby"]
- array := []
- dtwResult := {}
- for index, element in refArray
- {
- returnV := costCalc(testV, element)
- dtwResult[returnV.ref] := returnV.cost
- }
- minVlaue := 100
- minKeyWord := ""
- For key, value in dtwResult
- {
- if (minVlaue >= value)
- {
- minVlaue := value
- minKeyWord := key
- }
- }
- MsgBox,,,%testV% : %minKeyWord%`, %minVlaue%`%.,4
- }
- ;~ run like this
- ;~ dtw("Autuhotkey")
- ;~ dtw("autohutky")
- ;~ dtw("Pithon")
Add Comment
Please, Sign In to add comment