Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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