Team Ai
Apppublic

Arulkumar03/Wheat_HEAD_Detection_Counting_ComputerVision_Model

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
levenshtein.js45 linesDownload Raw Back to workflows
1/*2Copyright (c) 2011 Andrei Mackenzie3 4Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:5 6The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.7 8THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.9*/10 11// Compute the edit distance between the two given strings12exports.getEditDistance = function(a, b){13  if(a.length == 0) return b.length; 14  if(b.length == 0) return a.length; 15 16  var matrix = [];17 18  // increment along the first column of each row19  var i;20  for(i = 0; i <= b.length; i++){21    matrix[i] = [i];22  }23 24  // increment each column in the first row25  var j;26  for(j = 0; j <= a.length; j++){27    matrix[0][j] = j;28  }29 30  // Fill in the rest of the matrix31  for(i = 1; i <= b.length; i++){32    for(j = 1; j <= a.length; j++){33      if(b.charAt(i-1) == a.charAt(j-1)){34        matrix[i][j] = matrix[i-1][j-1];35      } else {36        matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution37                                Math.min(matrix[i][j-1] + 1, // insertion38                                         matrix[i-1][j] + 1)); // deletion39      }40    }41  }42 43  return matrix[b.length][a.length];44};45