Skip to content

Commit

Permalink
#71 - Upgrade to DKPro Core 1.11.0
Browse files Browse the repository at this point in the history
- Ignore tests which used bender
  • Loading branch information
reckart committed Jul 13, 2019
1 parent 906ee11 commit 21311d7
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Entity> entitiesAqua = wikiResource.getEntity("AQUA");
Set<Entity> entitiesSir = wikiResource.getEntity("SIR");
Set<Entity> entitiesUKP = wikiResource.getEntity("UKP");
Set<Entity> entitiesAqua = wikiResource.getEntity("AQUA");
Set<Entity> entitiesSir = wikiResource.getEntity("SIR");
Set<Entity> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Entity> entitiesAuto = germanet.getEntity("Auto", PoS.n);
Set<Entity> entitiesBagger = germanet.getEntity("Bagger", PoS.n);
Set<Entity> 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<Entity> entitiesTree = wordnet.getEntity("tree", PoS.n);
Set<Entity> entitiesPlant = wordnet.getEntity("plant", PoS.n);
Set<Entity> 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<Entity> entitiesAuto = germanet.getEntity("Auto", PoS.n);
Set<Entity> entitiesBagger = germanet.getEntity("Bagger", PoS.n);
Set<Entity> 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<Entity> entitiesTree = wordnet.getEntity("tree", PoS.n);
Set<Entity> entitiesPlant = wordnet.getEntity("plant", PoS.n);
Set<Entity> 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<Entity> entitiesTK3 = wikipedia.getEntity("TK3");
Set<Entity> entitiesIryna = wikipedia.getEntity("Iryna Gurevych");
Set<Entity> entitiesUKP = wikipedia.getEntity("UKP");
Set<Entity> entitiesNCS = wikipedia.getEntity("NCS");
Set<Entity> entitiesNCSl = wikipedia.getEntity("Net Centric Systems");
Set<Entity> 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<Entity> entitiesFahrzeug = wiktionary.getEntity("Fahrzeug");
Set<Entity> entitiesAuto = wiktionary.getEntity("Auto");
Set<Entity> entitiesGarten = wiktionary.getEntity("Garten");
Set<Entity> entitiesEmpty = new HashSet<Entity>();
Set<Entity> entitiesUnknown = new HashSet<Entity>();
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<Entity> entitiesTK3 = wikipedia.getEntity("TK3");
Set<Entity> entitiesIryna = wikipedia.getEntity("Iryna Gurevych");
Set<Entity> entitiesUKP = wikipedia.getEntity("UKP");
Set<Entity> entitiesNCS = wikipedia.getEntity("NCS");
Set<Entity> entitiesNCSl = wikipedia.getEntity("Net Centric Systems");
Set<Entity> 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<Entity> entitiesFahrzeug = wiktionary.getEntity("Fahrzeug");
Set<Entity> entitiesAuto = wiktionary.getEntity("Auto");
Set<Entity> entitiesGarten = wiktionary.getEntity("Garten");
Set<Entity> entitiesEmpty = new HashSet<Entity>();
Set<Entity> entitiesUnknown = new HashSet<Entity>();
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);
}
}
Loading

0 comments on commit 21311d7

Please sign in to comment.