Commit 38812746 authored by Johannes Salentin's avatar Johannes Salentin
Browse files

duplicated words ratio

Duplication now checked by ratio of same words in name
parent c1749793
Pipeline #159928 passed with stages
in 1 minute and 22 seconds
This diff is collapsed.
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
<documentation xml:lang="de">One who drives car or taxi</documentation> <documentation xml:lang="de">One who drives car or taxi</documentation>
</element> </element>
<element identifier="id-7eda7ef0-c57c-4403-93c0-cb0bccaf585e" xsi:type="BusinessRole"> <element identifier="id-7eda7ef0-c57c-4403-93c0-cb0bccaf585e" xsi:type="BusinessRole">
<name xml:lang="de">Trvelling to airport</name> <name xml:lang="de">Travelling to airport</name>
<documentation xml:lang="de">Passengers, visitors travels to airport</documentation> <documentation xml:lang="de">Passengers, visitors travels to airport</documentation>
</element> </element>
<element identifier="id-51b88d5b-5515-4e3b-9ce0-a33dcdd0b490" xsi:type="BusinessService"> <element identifier="id-51b88d5b-5515-4e3b-9ce0-a33dcdd0b490" xsi:type="BusinessService">
......
...@@ -7,6 +7,7 @@ class Constants { ...@@ -7,6 +7,7 @@ class Constants {
static final int MAX_DOCUMENTATION_LENGTH = 256; static final int MAX_DOCUMENTATION_LENGTH = 256;
static final int DUPLICATED_WORDS = 2; static final int DUPLICATED_WORDS = 2;
static final double DUPLICATED_WORDS_RATIO = 0.75;
static final int LARGE_FAN_IN = 10; static final int LARGE_FAN_IN = 10;
static final int LARGE_FAN_OUT = 10; static final int LARGE_FAN_OUT = 10;
......
...@@ -4,7 +4,7 @@ import de.example.model.ElementType; ...@@ -4,7 +4,7 @@ import de.example.model.ElementType;
import java.util.List; import java.util.List;
import static de.example.smells.Constants.DUPLICATED_WORDS; import static de.example.smells.Constants.DUPLICATED_WORDS_RATIO;
public class Duplication extends Detector { public class Duplication extends Detector {
...@@ -16,9 +16,9 @@ public class Duplication extends Detector { ...@@ -16,9 +16,9 @@ public class Duplication extends Detector {
List<ElementType> elements = model.getElements(); List<ElementType> elements = model.getElements();
for (int i = 0; i < elements.size() - 1; i++) { for (int i = 0; i < elements.size() - 1; i++) {
for (int j = i + 1; j < elements.size(); j++) { for (int j = i + 1; j < elements.size(); j++) {
// only if in same layer // only if same element type
if (elements.get(i).getClass().getSimpleName().equals(elements.get(j).getClass().getSimpleName())) { if (elements.get(i).getClass().getSimpleName().equals(elements.get(j).getClass().getSimpleName())) {
//String[] ei = elements.get(i).getNameGroup().get(0).getValue().split(" "); String[] ei = elements.get(i).getNameGroup().get(0).getValue().split(" ");
String[] ej = elements.get(j).getNameGroup().get(0).getValue().split(" "); String[] ej = elements.get(j).getNameGroup().get(0).getValue().split(" ");
int duplicatedWords = 0; int duplicatedWords = 0;
for (String w : ej) { for (String w : ej) {
...@@ -26,8 +26,11 @@ public class Duplication extends Detector { ...@@ -26,8 +26,11 @@ public class Duplication extends Detector {
duplicatedWords++; duplicatedWords++;
} }
} }
if (duplicatedWords > DUPLICATED_WORDS) { // if (duplicatedWords > DUPLICATED_WORDS) {
addToSmells(new EASmell(getSmellName(), elements.get(i), " with the " + elements.get(j).getClass().getSimpleName() + " \"" + elements.get(j).getNameGroup().get(0).getValue() + "\" (" + elements.get(j).getIdentifier() + ")")); // 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) {
addToSmells(new EASmell(getSmellName(), elements.get(i), " together with" + " \"" + elements.get(j).getNameGroup().get(0).getValue() + "\" (" + elements.get(j).getIdentifier() + ")"));
} }
} }
} }
......
...@@ -19,6 +19,6 @@ class TestDuplication { ...@@ -19,6 +19,6 @@ class TestDuplication {
@Test @Test
void test() { void test() {
assertEquals(detector.detect().size(), 2); assertEquals(detector.detect().size(), 0);
} }
} }
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