Created
March 6, 2020 17:59
-
-
Save ricardogobbo/acb78fa278d2ac0dbf191108ddba7206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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