Guest User

Untitled

a guest
Jan 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. costCalc(ByRef tempText, ByRef regText)
  2. {
  3. distanceArray := []
  4.  
  5. R_len := StrLen(tempText)
  6. C_len := StrLen(regText)
  7.  
  8. r_index := 1
  9. while (r_index <= R_len)
  10. {
  11. c_index := 1
  12.  
  13. while (c_index <= C_len)
  14. {
  15. if (SubStr(tempText, r_index, 1) = SubStr(regText, c_index, 1))
  16. {
  17. distanceArray[r_index, c_index] := 0
  18. }
  19. else
  20. {
  21. distanceArray[r_index, c_index] := 1
  22. }
  23. c_index := c_index + 1
  24. }
  25. r_index := r_index + 1
  26. }
  27.  
  28. ;~ accumulated cost calc
  29. accumulatedCost := []
  30. accumulatedCost[1,1] := distanceArray[1,1]
  31.  
  32. r_index := 2
  33. while (r_index <= R_len)
  34. {
  35. accumulatedCost[r_index, 1] := distanceArray[r_index, 1] + accumulatedCost[r_index-1, 1]
  36. r_index := r_index + 1
  37. }
  38.  
  39. c_index := 2
  40. while (c_index <= C_len)
  41. {
  42. accumulatedCost[1, c_index] := distanceArray[1, c_index] + accumulatedCost[1, c_index-1]
  43. c_index := c_index + 1
  44. }
  45.  
  46. r_index := 2
  47.  
  48.  
  49. while (r_index <= R_len)
  50. {
  51. c_index := 2
  52.  
  53. while (c_index <= C_len)
  54. {
  55.  
  56. min1 := min(accumulatedCost[r_index-1, c_index-1], accumulatedCost[r_index-1, c_index])
  57.  
  58. accumulatedCost[r_index, c_index] := distanceArray[r_index, c_index] + min(min1, accumulatedCost[r_index, c_index-1])
  59.  
  60. c_index := c_index + 1
  61. }
  62. r_index := r_index + 1
  63. }
  64.  
  65. costV := accumulatedCost[R_len, C_len]
  66. costPercentV := costV / max(R_len, C_len) * 100.0
  67.  
  68.  
  69. result := {ref: regText, cost: costPercentV}
  70.  
  71. return result
  72. }
  73.  
  74.  
  75. dtw(ByRef testV)
  76. {
  77. refArray := ["Autohotkey", "Autoit", "Python", "Powershell", "Ruby"]
  78.  
  79. array := []
  80.  
  81. dtwResult := {}
  82.  
  83. for index, element in refArray
  84. {
  85. returnV := costCalc(testV, element)
  86. dtwResult[returnV.ref] := returnV.cost
  87.  
  88. }
  89.  
  90. minVlaue := 100
  91. minKeyWord := ""
  92.  
  93. For key, value in dtwResult
  94. {
  95. if (minVlaue >= value)
  96. {
  97. minVlaue := value
  98. minKeyWord := key
  99. }
  100. }
  101.  
  102. MsgBox,,,%testV% : %minKeyWord%`, %minVlaue%`%.,4
  103. }
  104.  
  105. ;~ run like this
  106. ;~ dtw("Autuhotkey")
  107. ;~ dtw("autohutky")
  108. ;~ dtw("Pithon")
Add Comment
Please, Sign In to add comment