From 21311d754780995da28d1259e80722c4ca732248 Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Sat, 13 Jul 2019 21:21:09 +0200 Subject: [PATCH] #71 - Upgrade to DKPro Core 1.11.0 - Ignore tests which used bender --- .../path/LeacockChodorowComparatorTest.java | 48 ++-- .../lsr/path/PathLengthComparatorTest.java | 227 +++++++++--------- .../lsr/gloss/GlossOverlapComparatorTest.java | 71 +++--- 3 files changed, 172 insertions(+), 174 deletions(-) diff --git a/dkpro-similarity-algorithms-lsr-asl/src/test/java/org/dkpro/similarity/algorithms/lsr/path/LeacockChodorowComparatorTest.java b/dkpro-similarity-algorithms-lsr-asl/src/test/java/org/dkpro/similarity/algorithms/lsr/path/LeacockChodorowComparatorTest.java index 82d212e0..65cda39f 100644 --- a/dkpro-similarity-algorithms-lsr-asl/src/test/java/org/dkpro/similarity/algorithms/lsr/path/LeacockChodorowComparatorTest.java +++ b/dkpro-similarity-algorithms-lsr-asl/src/test/java/org/dkpro/similarity/algorithms/lsr/path/LeacockChodorowComparatorTest.java @@ -23,8 +23,8 @@ import java.util.Set; import org.dkpro.similarity.algorithms.lsr.LexSemResourceComparator; -import org.dkpro.similarity.algorithms.lsr.path.LeacockChodorowComparator; import org.junit.Assume; +import org.junit.Ignore; import org.junit.Test; import de.tudarmstadt.ukp.dkpro.lexsemresource.Entity; @@ -33,35 +33,33 @@ public class LeacockChodorowComparatorTest { - private static final double epsilon = 0.0001; + private static final double epsilon = 0.0001; - - @Test - public void testLC98WikipediaCategory() - throws Exception - { + @Ignore("MySQL server with Wikipedia data not available") + @Test + public void testLC98WikipediaCategory() throws Exception + { + Assume.assumeTrue(Runtime.getRuntime().maxMemory() > 1000000000); - Assume.assumeTrue(Runtime.getRuntime().maxMemory() > 1000000000); - - LexicalSemanticResource wikiResource = ResourceFactory.getInstance().get( - "wikipedia_category", "test"); + LexicalSemanticResource wikiResource = ResourceFactory.getInstance() + .get("wikipedia_category", "test"); - LexSemResourceComparator comparator = new LeacockChodorowComparator(wikiResource); + LexSemResourceComparator comparator = new LeacockChodorowComparator(wikiResource); - Set entitiesAqua = wikiResource.getEntity("AQUA"); - Set entitiesSir = wikiResource.getEntity("SIR"); - Set entitiesUKP = wikiResource.getEntity("UKP"); + Set entitiesAqua = wikiResource.getEntity("AQUA"); + Set entitiesSir = wikiResource.getEntity("SIR"); + Set entitiesUKP = wikiResource.getEntity("UKP"); - assertTrue("AQUA", entitiesAqua.size() > 0); - assertTrue("SIR", entitiesSir.size() > 0); - assertTrue("UKP", entitiesUKP.size() > 0); + assertTrue("AQUA", entitiesAqua.size() > 0); + assertTrue("SIR", entitiesSir.size() > 0); + assertTrue("UKP", entitiesUKP.size() > 0); - // same page - assertEquals(2.0794, comparator.getSimilarity(entitiesAqua, entitiesAqua), epsilon); + // same page + assertEquals(2.0794, comparator.getSimilarity(entitiesAqua, entitiesAqua), epsilon); - // different pages - // pathlength in Edges = 2 - assertEquals(-Math.log(0.375), comparator.getSimilarity(entitiesAqua, entitiesSir), - epsilon); - } + // different pages + // pathlength in Edges = 2 + assertEquals(-Math.log(0.375), comparator.getSimilarity(entitiesAqua, entitiesSir), + epsilon); + } } \ No newline at end of file diff --git a/dkpro-similarity-algorithms-lsr-asl/src/test/java/org/dkpro/similarity/algorithms/lsr/path/PathLengthComparatorTest.java b/dkpro-similarity-algorithms-lsr-asl/src/test/java/org/dkpro/similarity/algorithms/lsr/path/PathLengthComparatorTest.java index be2a189f..bf7cb984 100644 --- a/dkpro-similarity-algorithms-lsr-asl/src/test/java/org/dkpro/similarity/algorithms/lsr/path/PathLengthComparatorTest.java +++ b/dkpro-similarity-algorithms-lsr-asl/src/test/java/org/dkpro/similarity/algorithms/lsr/path/PathLengthComparatorTest.java @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package org.dkpro.similarity.algorithms.lsr.path; - +package org.dkpro.similarity.algorithms.lsr.path; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -35,121 +35,122 @@ import de.tudarmstadt.ukp.dkpro.lexsemresource.LexicalSemanticResource; import de.tudarmstadt.ukp.dkpro.lexsemresource.core.ResourceFactory; import de.tudarmstadt.ukp.dkpro.lexsemresource.exception.ResourceLoaderException; - -public class PathLengthComparatorTest { - - private static final double epsilon = 0.0001; - - private static LexicalSemanticResource wordnet; - private static LexicalSemanticResource germanet; - private static LexicalSemanticResource wikipedia; - private static LexicalSemanticResource wiktionary; - - @BeforeClass - public static void initialize() throws ResourceLoaderException { - wordnet = ResourceFactory.getInstance().get("wordnet3", "en"); -// germanet = ResourceFactory.getInstance().get("germanet7", "de"); - wikipedia = ResourceFactory.getInstance().get("wikipedia", "test"); -// wiktionary = ResourceFactory.getInstance().get("wiktionary", "en"); - } - - @Ignore("The original GermaNet API is not Apache licensed.") - @Test - public void testGermaNetUsingResourceLoader() - throws Exception - { - LexSemResourceComparator comparator = new PathLengthComparator(germanet); - - Set entitiesAuto = germanet.getEntity("Auto", PoS.n); - Set entitiesBagger = germanet.getEntity("Bagger", PoS.n); - Set entitiesSchnell = germanet.getEntity("schnell", PoS.adj); - - assertEquals(0.0, comparator.getSimilarity(entitiesAuto, entitiesAuto), epsilon); - assertEquals(1.0, comparator.getSimilarity(entitiesAuto, entitiesBagger), epsilon); - assertEquals(6.0, comparator.getSimilarity(entitiesAuto, entitiesSchnell), epsilon); - } - -// @Ignore("The path from 'tree' to 'tree' should be 0 but is 13! - See bug 163") - @Test - public void testWordNet() - throws Exception - { - Assume.assumeTrue(Runtime.getRuntime().maxMemory() > 1000000000); - - LexSemResourceComparator comparator = new PathLengthComparator(wordnet); - - Set entitiesTree = wordnet.getEntity("tree", PoS.n); - Set entitiesPlant = wordnet.getEntity("plant", PoS.n); - Set entitiesFast = wordnet.getEntity("fast", PoS.adj); - - assertEquals(0.0, comparator.getSimilarity(entitiesTree, entitiesTree), epsilon); - assertEquals(2.0, comparator.getSimilarity(entitiesTree, entitiesPlant), epsilon); + +public class PathLengthComparatorTest +{ + + private static final double epsilon = 0.0001; + + private static LexicalSemanticResource wordnet; + private static LexicalSemanticResource germanet; + private static LexicalSemanticResource wikipedia; + private static LexicalSemanticResource wiktionary; + + @BeforeClass + public static void initialize() throws ResourceLoaderException + { + wordnet = ResourceFactory.getInstance().get("wordnet3", "en"); + // germanet = ResourceFactory.getInstance().get("germanet7", "de"); + wikipedia = ResourceFactory.getInstance().get("wikipedia", "test"); + // wiktionary = ResourceFactory.getInstance().get("wiktionary", "en"); + } + + @Ignore("The original GermaNet API is not Apache licensed.") + @Test + public void testGermaNetUsingResourceLoader() throws Exception + { + LexSemResourceComparator comparator = new PathLengthComparator(germanet); + + Set entitiesAuto = germanet.getEntity("Auto", PoS.n); + Set entitiesBagger = germanet.getEntity("Bagger", PoS.n); + Set entitiesSchnell = germanet.getEntity("schnell", PoS.adj); + + assertEquals(0.0, comparator.getSimilarity(entitiesAuto, entitiesAuto), epsilon); + assertEquals(1.0, comparator.getSimilarity(entitiesAuto, entitiesBagger), epsilon); + assertEquals(6.0, comparator.getSimilarity(entitiesAuto, entitiesSchnell), epsilon); + } + + // @Ignore("The path from 'tree' to 'tree' should be 0 but is 13! - See bug 163") + @Test + public void testWordNet() throws Exception + { + Assume.assumeTrue(Runtime.getRuntime().maxMemory() > 1000000000); + + LexSemResourceComparator comparator = new PathLengthComparator(wordnet); + + Set entitiesTree = wordnet.getEntity("tree", PoS.n); + Set entitiesPlant = wordnet.getEntity("plant", PoS.n); + Set entitiesFast = wordnet.getEntity("fast", PoS.adj); + + assertEquals(0.0, comparator.getSimilarity(entitiesTree, entitiesTree), epsilon); + assertEquals(2.0, comparator.getSimilarity(entitiesTree, entitiesPlant), epsilon); assertEquals(PathLengthComparator.NOT_FOUND, comparator.getSimilarity(entitiesTree, entitiesFast), epsilon); - } - - @Test - public void testWikipediaArticle() - throws Exception - { - Assume.assumeTrue(Runtime.getRuntime().maxMemory() > 1000000000); - - LexSemResourceComparator comparator = new PathLengthComparator(wikipedia); - - // this are pages - // we have to find a way to cast the path length between pages to the path length between - // the corresponding categories - Set entitiesTK3 = wikipedia.getEntity("TK3"); - Set entitiesIryna = wikipedia.getEntity("Iryna Gurevych"); - Set entitiesUKP = wikipedia.getEntity("UKP"); - Set entitiesNCS = wikipedia.getEntity("NCS"); - Set entitiesNCSl = wikipedia.getEntity("Net Centric Systems"); - Set entitiesNLP = wikipedia.getEntity("Natural Language Processing for Ambient Intelligence"); - - assertTrue("TK3", entitiesTK3.size() > 0); - assertTrue("Iryna Gurevych", entitiesIryna.size() > 0); - assertTrue("UKP", entitiesUKP.size() > 0); - assertTrue("NCS", entitiesNCS.size() > 0); - assertTrue("Net Centric Systems", entitiesNCSl.size() > 0); - assertTrue("Natural Language Processing for Ambient Intelligence", entitiesNLP.size() > 0); - - // same page - assertEquals(0.0, comparator.getSimilarity(entitiesTK3, entitiesTK3), epsilon); - - // different pages - // pathlength in Edges = 2 - assertEquals(2.0, comparator.getSimilarity(entitiesIryna, entitiesUKP), epsilon); - - // page and redirect - assertEquals(0.0, comparator.getSimilarity(entitiesNCS, entitiesNCSl), epsilon); - - // one edge / zero nodes distance - assertEquals(1.0, comparator.getSimilarity(entitiesUKP, entitiesNLP), epsilon); - } - - @Test - @Ignore("WiktionaryResource.getParents() is not implemented.") - public void testWiktionary() - throws Exception - { - LexSemResourceComparator comparator = new PathLengthComparator(wiktionary); - - Set entitiesFahrzeug = wiktionary.getEntity("Fahrzeug"); - Set entitiesAuto = wiktionary.getEntity("Auto"); - Set entitiesGarten = wiktionary.getEntity("Garten"); - Set entitiesEmpty = new HashSet(); - Set entitiesUnknown = new HashSet(); - entitiesUnknown.add(new Entity("humbelgrmpfh")); - - assertEquals(0.0, comparator.getSimilarity(entitiesAuto, entitiesAuto), epsilon); - assertEquals(1.0, comparator.getSimilarity(entitiesAuto, entitiesFahrzeug), epsilon); - assertEquals(3.0, comparator.getSimilarity(entitiesAuto, entitiesGarten), epsilon); + } + + @Ignore("MySQL server with Wikipedia data not available") + @Test + public void testWikipediaArticle() throws Exception + { + Assume.assumeTrue(Runtime.getRuntime().maxMemory() > 1000000000); + + LexSemResourceComparator comparator = new PathLengthComparator(wikipedia); + + // this are pages + // we have to find a way to cast the path length between pages to the path length between + // the corresponding categories + Set entitiesTK3 = wikipedia.getEntity("TK3"); + Set entitiesIryna = wikipedia.getEntity("Iryna Gurevych"); + Set entitiesUKP = wikipedia.getEntity("UKP"); + Set entitiesNCS = wikipedia.getEntity("NCS"); + Set entitiesNCSl = wikipedia.getEntity("Net Centric Systems"); + Set entitiesNLP = wikipedia + .getEntity("Natural Language Processing for Ambient Intelligence"); + + assertTrue("TK3", entitiesTK3.size() > 0); + assertTrue("Iryna Gurevych", entitiesIryna.size() > 0); + assertTrue("UKP", entitiesUKP.size() > 0); + assertTrue("NCS", entitiesNCS.size() > 0); + assertTrue("Net Centric Systems", entitiesNCSl.size() > 0); + assertTrue("Natural Language Processing for Ambient Intelligence", entitiesNLP.size() > 0); + + // same page + assertEquals(0.0, comparator.getSimilarity(entitiesTK3, entitiesTK3), epsilon); + + // different pages + // pathlength in Edges = 2 + assertEquals(2.0, comparator.getSimilarity(entitiesIryna, entitiesUKP), epsilon); + + // page and redirect + assertEquals(0.0, comparator.getSimilarity(entitiesNCS, entitiesNCSl), epsilon); + + // one edge / zero nodes distance + assertEquals(1.0, comparator.getSimilarity(entitiesUKP, entitiesNLP), epsilon); + } + + @Test + @Ignore("WiktionaryResource.getParents() is not implemented.") + public void testWiktionary() throws Exception + { + LexSemResourceComparator comparator = new PathLengthComparator(wiktionary); + + Set entitiesFahrzeug = wiktionary.getEntity("Fahrzeug"); + Set entitiesAuto = wiktionary.getEntity("Auto"); + Set entitiesGarten = wiktionary.getEntity("Garten"); + Set entitiesEmpty = new HashSet(); + Set entitiesUnknown = new HashSet(); + entitiesUnknown.add(new Entity("humbelgrmpfh")); + + assertEquals(0.0, comparator.getSimilarity(entitiesAuto, entitiesAuto), epsilon); + assertEquals(1.0, comparator.getSimilarity(entitiesAuto, entitiesFahrzeug), epsilon); + assertEquals(3.0, comparator.getSimilarity(entitiesAuto, entitiesGarten), epsilon); assertEquals(PathLengthComparator.NOT_FOUND, comparator.getSimilarity(entitiesAuto, entitiesEmpty), epsilon); assertEquals(PathLengthComparator.NOT_FOUND, comparator.getSimilarity(entitiesAuto, entitiesUnknown), epsilon); - - // test symmetry - assertEquals(comparator.getSimilarity(entitiesFahrzeug, entitiesAuto), comparator.getSimilarity(entitiesAuto, entitiesFahrzeug), epsilon); - } + + // test symmetry + assertEquals(comparator.getSimilarity(entitiesFahrzeug, entitiesAuto), + comparator.getSimilarity(entitiesAuto, entitiesFahrzeug), epsilon); + } } \ No newline at end of file diff --git a/dkpro-similarity-algorithms-lsr-gpl/src/test/java/org/dkpro/similarity/algorithms/lsr/gloss/GlossOverlapComparatorTest.java b/dkpro-similarity-algorithms-lsr-gpl/src/test/java/org/dkpro/similarity/algorithms/lsr/gloss/GlossOverlapComparatorTest.java index f556bb2e..d3dc928c 100644 --- a/dkpro-similarity-algorithms-lsr-gpl/src/test/java/org/dkpro/similarity/algorithms/lsr/gloss/GlossOverlapComparatorTest.java +++ b/dkpro-similarity-algorithms-lsr-gpl/src/test/java/org/dkpro/similarity/algorithms/lsr/gloss/GlossOverlapComparatorTest.java @@ -39,7 +39,6 @@ import de.tudarmstadt.ukp.wikipedia.api.Wikipedia; import de.tudarmstadt.ukp.wikipedia.api.exception.WikiException; - public class GlossOverlapComparatorTest { private static final double epsilon = 0.0001; @@ -48,32 +47,30 @@ public class GlossOverlapComparatorTest private LexicalSemanticResource wikiResource; private LexicalSemanticResource wktResource; - @Before - public void setupWikipedia() - throws Exception - { + @Before + public void setupWikipedia() throws Exception + { wikiResource = ResourceFactory.getInstance().get("wikipedia", "en"); wikiResource.setIsCaseSensitive(false); } - -// @Before -// public void setupWiktionary() -// throws Exception -// { -// wktResource = ResourceFactory.getInstance().get("wiktionary", "de"); -// } - - @Test - public void testGlossOverlapWikipedia() - throws Exception - { + // @Before + // public void setupWiktionary() + // throws Exception + // { + // wktResource = ResourceFactory.getInstance().get("wiktionary", "de"); + // } + + @Ignore("MySQL server with Wikipedia data not available") + @Test + public void testGlossOverlapWikipedia() throws Exception + { LexSemResourceComparator comparator = new GlossOverlapComparator(wikiResource, false); - Set entitiesAuto = wikiResource.getEntity("Automobile"); + Set entitiesAuto = wikiResource.getEntity("Automobile"); Set entitiesTruck = wikiResource.getEntity("Truck"); - assertTrue("Auto", entitiesAuto.size() > 0); + assertTrue("Auto", entitiesAuto.size() > 0); assertTrue("Truck", entitiesTruck.size() > 0); // same page @@ -84,16 +81,16 @@ public void testGlossOverlapWikipedia() } @Ignore("Currently deactivated as Wiktionary resource data is not for API version is not available.") - @Test - public void testGlossOverlapWiktionary() - throws LexicalSemanticResourceException, SimilarityException - { - LexSemResourceComparator comparator = new GlossOverlapComparator(wktResource, false); + @Test + public void testGlossOverlapWiktionary() + throws LexicalSemanticResourceException, SimilarityException + { + LexSemResourceComparator comparator = new GlossOverlapComparator(wktResource, false); - Set entities1 = wktResource.getEntity("Bayern"); + Set entities1 = wktResource.getEntity("Bayern"); Set entities2 = wktResource.getEntity("Deutschland"); - assertTrue("Bayern", entities1.size() > 0); + assertTrue("Bayern", entities1.size() > 0); assertTrue("Deutschland", entities2.size() > 0); // same page @@ -104,25 +101,27 @@ public void testGlossOverlapWiktionary() } // LSR-based comparator and JWPL-based comparator should yield equal results - // See Bug 144 - @Test - @Ignore("TODO for some reason the leskComparator gloss is from the disambiguation page - need to discover why") - public void comparisonWithJwplImplementationTest() - throws LexicalSemanticResourceException, WikiException, SimilarityException - { - wikiResource.setIsCaseSensitive(true); - LexSemResourceComparator glossOverlapComparator = new GlossOverlapComparator(wikiResource, false); + // See Bug 144 + @Test + @Ignore("TODO for some reason the leskComparator gloss is from the disambiguation page - need to discover why") + public void comparisonWithJwplImplementationTest() + throws LexicalSemanticResourceException, WikiException, SimilarityException + { + wikiResource.setIsCaseSensitive(true); + LexSemResourceComparator glossOverlapComparator = new GlossOverlapComparator(wikiResource, + false); String term1 = "Automobile"; String term2 = "Truck"; - Set entitiesAuto = wikiResource.getEntity(term1); + Set entitiesAuto = wikiResource.getEntity(term1); Set entitiesTruck = wikiResource.getEntity(term2); LeskComparator leskComparator = new LeskFirstComparator(wiki); leskComparator.setUseCache(false); - assertEquals(glossOverlapComparator.getSimilarity(entitiesAuto, entitiesTruck), leskComparator.getSimilarity(term1, term2), epsilon); + assertEquals(glossOverlapComparator.getSimilarity(entitiesAuto, entitiesTruck), + leskComparator.getSimilarity(term1, term2), epsilon); wikiResource.setIsCaseSensitive(false); }