Commit 168e58a8 authored by Johannes Salentin's avatar Johannes Salentin
Browse files

fixed duplicated words

now checks for similar words instead of one name containing a word from the other
parent 53512737
Pipeline #160172 passed with stages
in 1 minute and 23 seconds
......@@ -2,6 +2,7 @@ package de.example.smells;
import de.example.model.ElementType;
import java.util.Arrays;
import java.util.List;
import static de.example.smells.Constants.DUPLICATED_WORDS_RATIO;
......@@ -18,18 +19,18 @@ public class Duplication extends Detector {
for (int j = i + 1; j < elements.size(); j++) {
// only if same element type
if (elements.get(i).getClass().getSimpleName().equals(elements.get(j).getClass().getSimpleName())) {
String[] ei = elements.get(i).getNameGroup().get(0).getValue().split(" ");
String[] ej = elements.get(j).getNameGroup().get(0).getValue().split(" ");
List<String> ei = Arrays.asList(elements.get(i).getNameGroup().get(0).getValue().split(" "));
List<String> ej = Arrays.asList(elements.get(j).getNameGroup().get(0).getValue().split(" "));
int duplicatedWords = 0;
for (String w : ej) {
if (elements.get(i).getNameGroup().get(0).getValue().contains(w)) {
if (ei.contains(w)) {
duplicatedWords++;
}
}
// if (duplicatedWords > DUPLICATED_WORDS) {
// addToSmells(new EASmell(getSmellName(), elements.get(i), " together with" + " \"" + elements.get(j).getNameGroup().get(0).getValue() + "\" (" + elements.get(j).getIdentifier() + ")"));
// }
if (((double) 2 * duplicatedWords) / (ei.length + ej.length) > DUPLICATED_WORDS_RATIO) {
if (((double) 2 * duplicatedWords) / (ei.size() + ej.size()) > DUPLICATED_WORDS_RATIO) {
addToSmells(new EASmell(getSmellName(), elements.get(i), " together with" + " \"" + elements.get(j).getNameGroup().get(0).getValue() + "\" (" + elements.get(j).getIdentifier() + ")"));
}
}
......
......@@ -22,6 +22,6 @@ class TestDuplication {
ModelAdapter model = new ModelAdapter("SmellExample.xml", null);
Detector.setModel(model);
detector = new Duplication();
assertEquals(detector.detect().size(), 2);
assertEquals(detector.detect().size(), 1);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment