Skip to content

Instantly share code, notes, and snippets.

@ricardogobbo
Created March 6, 2020 17:59
Show Gist options
  • Save ricardogobbo/acb78fa278d2ac0dbf191108ddba7206 to your computer and use it in GitHub Desktop.
Save ricardogobbo/acb78fa278d2ac0dbf191108ddba7206 to your computer and use it in GitHub Desktop.
def componentes = ComponenteProjeto.findAllByCorpoIsNotNull(params)
def results = componentes.collect {
[texts: Jsoup.parse(it.corpo).text().split("\\.")]
}
results.each{ a ->
a.similarity = results.collect{
TextSimilarityCalculator.similarity(it.texts[0], a.texts[0])
}
a.diff = results.collect{
def value = new DiffMatchPatch().diff_main(it.texts[0], a.texts[0])
def total = 0
def similarity = 0
value.each{ diff ->
switch (diff.operation){
case DiffMatchPatch.Operation.INSERT:
total -= diff.text.length(); break
case DiffMatchPatch.Operation.DELETE:
total -= diff.text.length(); break
case DiffMatchPatch.Operation.EQUAL:
total += diff.text.length();
similarity += diff.text.length();
break
}
}
//return similarity/a.texts[0].length()
return [total: total, similarity: similarity/a.texts[0].length()]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment