From 94195218e867e8139b05fd3a378a02afb6de36cd Mon Sep 17 00:00:00 2001 From: Donato Meoli Date: Thu, 29 Jul 2021 19:03:45 +0200 Subject: [PATCH] clean up code --- .../kdde/ws4j/demo/SimilarityCalculationDemo.java | 4 ++-- .../di/lacam/kdde/ws4j/similarity/JiangConrath.java | 12 ++++++------ .../lacam/kdde/ws4j/similarity/LeacockChodorow.java | 8 ++++---- .../edu/uniba/di/lacam/kdde/ws4j/similarity/Lin.java | 8 ++++---- .../uniba/di/lacam/kdde/ws4j/similarity/Path.java | 8 ++++---- .../uniba/di/lacam/kdde/ws4j/similarity/Resnik.java | 8 ++++---- .../di/lacam/kdde/ws4j/similarity/WuPalmer.java | 8 ++++---- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/demo/SimilarityCalculationDemo.java b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/demo/SimilarityCalculationDemo.java index 986709c..646927d 100644 --- a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/demo/SimilarityCalculationDemo.java +++ b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/demo/SimilarityCalculationDemo.java @@ -17,8 +17,8 @@ public class SimilarityCalculationDemo { WS4JConfiguration.getInstance().setMFS(true); ILexicalDatabase db = new MITWordNet(); rcs = new RelatednessCalculator[]{ - new HirstStOnge(db), new LeacockChodorow(db), new Lesk(db), new WuPalmer(db), - new Resnik(db), new JiangConrath(db), new Lin(db), new Path(db) + new WuPalmer(db), new JiangConrath(db), new LeacockChodorow(db), new Lin(db), + new Resnik(db), new Path(db), new Lesk(db), new HirstStOnge(db) }; } diff --git a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/JiangConrath.java b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/JiangConrath.java index 7639b65..db7db60 100644 --- a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/JiangConrath.java +++ b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/JiangConrath.java @@ -33,10 +33,10 @@ */ public class JiangConrath extends RelatednessCalculator { - private static double min = 0.0D; - private static double max = Double.MAX_VALUE; + private static final double min = 0.0D; + private static final double max = Double.MAX_VALUE; - private static List POSPairs = new ArrayList() {{ + private static final List POSPairs = new ArrayList() {{ add(new POS[]{POS.NOUN, POS.NOUN}); add(new POS[]{POS.VERB, POS.VERB}); }}; @@ -55,7 +55,7 @@ protected Relatedness calcRelatedness(Concept concept1, Concept concept2) { if (Objects.requireNonNull(lcsList).size() == 0) return new Relatedness(min, tracer.toString(), null); if (WS4JConfiguration.getInstance().useTrace()) { tracer.append("JCN(").append(concept1).append(", ").append(concept2).append(")\n"); - tracer.append(Objects.requireNonNull(subTracer).toString()); + tracer.append(Objects.requireNonNull(subTracer)); lcsList.forEach(lcs -> { tracer.append("Lowest Common Subsumer(s): "); tracer.append(lcs.getSubsumer().toString()).append(" (IC = ").append(lcs.getIC()).append(")\n"); @@ -70,8 +70,8 @@ protected Relatedness calcRelatedness(Concept concept1, Concept concept2) { double ic1 = ICFinder.getInstance().IC(pathFinder, concept1); double ic2 = ICFinder.getInstance().IC(pathFinder, concept2); if (WS4JConfiguration.getInstance().useTrace()) { - tracer.append("IC(").append(concept1.toString()).append(") = ").append(ic1).append("\n"); - tracer.append("IC(").append(concept2.toString()).append(") = ").append(ic2).append("\n"); + tracer.append("IC(").append(concept1).append(") = ").append(ic1).append("\n"); + tracer.append("IC(").append(concept2).append(") = ").append(ic2).append("\n"); } double distance; if (ic1 > 0 && ic2 > 0) distance = ic1 + ic2 - (2 * lcsIC); diff --git a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/LeacockChodorow.java b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/LeacockChodorow.java index 0548c02..6a7da16 100644 --- a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/LeacockChodorow.java +++ b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/LeacockChodorow.java @@ -36,10 +36,10 @@ */ public class LeacockChodorow extends RelatednessCalculator { - private static double min = 0.0D; - private static double max = Double.MAX_VALUE; + private static final double min = 0.0D; + private static final double max = Double.MAX_VALUE; - private static List POSPairs = new ArrayList() {{ + private static final List POSPairs = new ArrayList() {{ add(new POS[]{POS.NOUN, POS.NOUN}); add(new POS[]{POS.VERB, POS.VERB}); }}; @@ -63,7 +63,7 @@ protected Relatedness calcRelatedness(Concept concept1, Concept concept2) { double score = -Math.log((double) length / (double) (2 * maxDepth)); if (WS4JConfiguration.getInstance().useTrace()) { tracer.append("LCH(").append(concept1).append(", ").append(concept2).append(")\n"); - tracer.append(Objects.requireNonNull(subTracer).toString()); + tracer.append(Objects.requireNonNull(subTracer)); lcsList.forEach(lcs -> { tracer.append("Lowest Common Subsumer(s): "); tracer.append(lcs.getSubsumer().toString()).append(" (Length = ").append(lcs.getPathLength()).append(")\n"); diff --git a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Lin.java b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Lin.java index aafef0a..db37075 100644 --- a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Lin.java +++ b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Lin.java @@ -28,10 +28,10 @@ */ public class Lin extends RelatednessCalculator { - private static double min = 0.0D; - private static double max = 1.0D; + private static final double min = 0.0D; + private static final double max = 1.0D; - private static List POSPairs = new ArrayList() {{ + private static final List POSPairs = new ArrayList() {{ add(new POS[]{POS.NOUN, POS.NOUN}); add(new POS[]{POS.VERB, POS.VERB}); }}; @@ -53,7 +53,7 @@ protected Relatedness calcRelatedness(Concept concept1, Concept concept2) { double score = (ic1 > 0 && ic2 > 0) ? (2D * lcsList.get(0).getIC() / (ic1 + ic2)) : 0D; if (WS4JConfiguration.getInstance().useTrace()) { tracer.append("LIN(").append(concept1).append(", ").append(concept2).append(")\n"); - tracer.append(Objects.requireNonNull(subTracer).toString()); + tracer.append(Objects.requireNonNull(subTracer)); lcsList.forEach(lcs -> { tracer.append("Lowest Common Subsumer(s): "); tracer.append(lcs.getSubsumer()).append(" (IC = ").append(lcs.getIC()).append(")\n"); diff --git a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Path.java b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Path.java index a9ecb14..cea48e0 100644 --- a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Path.java +++ b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Path.java @@ -20,10 +20,10 @@ */ public class Path extends RelatednessCalculator { - private static double min = 0.0D; - private static double max = 1.0D; + private static final double min = 0.0D; + private static final double max = 1.0D; - private static List POSPairs = new ArrayList() {{ + private static final List POSPairs = new ArrayList() {{ add(new POS[]{POS.NOUN, POS.NOUN}); add(new POS[]{POS.VERB, POS.VERB}); }}; @@ -46,7 +46,7 @@ protected Relatedness calcRelatedness(Concept concept1, Concept concept2) { else score = -1.0D; if (WS4JConfiguration.getInstance().useTrace()) { tracer.append("PATH(").append(concept1).append(", ").append(concept2).append(")\n"); - tracer.append(Objects.requireNonNull(subTracer).toString()); + tracer.append(Objects.requireNonNull(subTracer)); tracer.append("Shortest path: ").append(path).append("\n"); tracer.append("Path length = ").append(dist).append("\n"); } diff --git a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Resnik.java b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Resnik.java index c5027da..c3b45fb 100644 --- a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Resnik.java +++ b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/Resnik.java @@ -34,10 +34,10 @@ */ public class Resnik extends RelatednessCalculator { - private static double min = 0.0D; - private static double max = Double.MAX_VALUE; + private static final double min = 0.0D; + private static final double max = Double.MAX_VALUE; - private static List POSPairs = new ArrayList() {{ + private static final List POSPairs = new ArrayList() {{ add(new POS[]{POS.NOUN, POS.NOUN}); add(new POS[]{POS.VERB, POS.VERB}); }}; @@ -56,7 +56,7 @@ protected Relatedness calcRelatedness(Concept concept1, Concept concept2) { if (Objects.requireNonNull(lcsList).size() == 0) return new Relatedness(min, tracer.toString(), null); if (WS4JConfiguration.getInstance().useTrace()) { tracer.append("RES(").append(concept1).append(", ").append(concept2).append(")\n"); - tracer.append(Objects.requireNonNull(subTracer).toString()); + tracer.append(Objects.requireNonNull(subTracer)); lcsList.forEach(lcs -> { tracer.append("Lowest Common Subsumer(s): "); tracer.append(lcs.getSubsumer()).append(" (IC = ").append(lcs.getIC()).append(")\n"); diff --git a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/WuPalmer.java b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/WuPalmer.java index ee1dd8b..f2b9d2d 100644 --- a/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/WuPalmer.java +++ b/src/main/java/edu/uniba/di/lacam/kdde/ws4j/similarity/WuPalmer.java @@ -20,10 +20,10 @@ */ public class WuPalmer extends RelatednessCalculator { - private static double min = 0.0D; - private static double max = 1.0D; + private static final double min = 0.0D; + private static final double max = 1.0D; - private static List POSPairs = new ArrayList() {{ + private static final List POSPairs = new ArrayList() {{ add(new POS[]{POS.NOUN, POS.NOUN}); add(new POS[]{POS.VERB, POS.VERB}); }}; @@ -47,7 +47,7 @@ protected Relatedness calcRelatedness(Concept concept1, Concept concept2) { if (depth1 > 0 && depth2 > 0) score = (double) (2 * depth) / (double) (depth1 + depth2); if (WS4JConfiguration.getInstance().useTrace()) { tracer.append("WUP(").append(concept1).append(", ").append(concept2).append(")\n"); - tracer.append(Objects.requireNonNull(subTracer).toString()); + tracer.append(Objects.requireNonNull(subTracer)); lcsList.forEach(lcs -> { tracer.append("Lowest Common Subsumer(s): "); tracer.append(lcs.getLeaf()).append(" (Depth = ").append(lcs.getDepth()).append(")\n");