Sha256: 8ac9c7453904d8a9d7e946f341da2948d0fd0b6c6ff64e87a8f1f0d2bb41daab

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

class Utils

  @random_string: ->
    chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"
    ret = ""
    for i in [0..16]
      rnum = Math.floor(Math.random() * chars.length)
      ret += chars.substring(rnum,rnum+1)
    return ret

  @tokenize: (input) =>
    input = input.toLowerCase()
    input = input.replace(/\,/g, " , ")
    input = input.replace(/\./g, " . ")
    input = input.replace(/\n/g, "")
    input = input.replace(/\ \ /g, " ")
    return input

  @split_source: (text) ->
    delimiters = [".","!","?"]
    line = ""
    spliting = false
    firstSplit = false
    input = new Array()
    white = 0
    last = ' '
    for c in text
      #c = text[i]
      if (spliting == true)
          if (c != ' ' && c != '\n' && c != '\t')
            if (white > 0 || last == '\n')
              input[input.length] = line
              line = ""
            spliting = false
          else
            ++white
      line += c
      if (c == '.' || c == '!' || c == '?' || c == '\n')
        spliting = true
        white = 0
      last = c
    input[input.length] = line
    return input

  @trim: (text) =>
    return text.replace(/^\s+|\s+$/g, "")

  @edit_distance: (source, target) ->
    a = []
    for i in [0..source.length]
      a[i] = new Array(target.length + 1)
      a[i][0] = i
    a[0] = [0..target.length]

    for i in [1..source.length]
      for j in [1..target.length]
        substitute_cost = a[i - 1][j - 1]
        substitute_cost += 1 if (source.charAt(i - 1) != target.charAt(j - 1))
        a[i][j] = Math.min(substitute_cost, a[i-1][j] + 1, a[i][j-1] + 1)
    return a[source.length][target.length]


Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ajax-cat-2.1.0 lib/ajax-cat/public/Utils.coffee
ajax-cat-2.0.5 lib/ajax-cat/public/Utils.coffee
ajax-cat-2.0.4 lib/ajax-cat/public/Utils.coffee
ajax-cat-2.0.3 lib/ajax-cat/public/Utils.coffee
ajax-cat-2.0.2 lib/ajax-cat/public/Utils.coffee
ajax-cat-2.0.1 lib/ajax-cat/public/Utils.coffee