Skip to content

Instantly share code, notes, and snippets.

@Treehopper
Created November 5, 2018 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Treehopper/a2500ea8d594890b9eba3c870a8113e2 to your computer and use it in GitHub Desktop.
Save Treehopper/a2500ea8d594890b9eba3c870a8113e2 to your computer and use it in GitHub Desktop.
Test string for similarity with each line in a file
#!/usr/bin/env groovy
@Grab(group='info.debatty', module='java-string-similarity', version='1.1.0')
import info.debatty.java.stringsimilarity.*
def input = args[0]
def inputFile = new File('file.txt')
def csvFile = new File('file-smlr.csv')
def l = new Levenshtein()
csvFile.withPrintWriter { out ->
out.println("line from file;distance compared to " + input)
inputFile.eachLine { line ->
out.print(line)
out.print(";")
out.println(l.distance(input, line))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment