Skip to content

Commit

Permalink
Adds a test for test get similar pages
Browse files Browse the repository at this point in the history
  • Loading branch information
rzo1 committed Dec 1, 2023
1 parent 28391cd commit 9ca5d74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
11 changes: 1 addition & 10 deletions dkpro-jwpl-api/src/main/java/org/dkpro/jwpl/api/Wikipedia.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,8 @@
package org.dkpro.jwpl.api;

import java.lang.invoke.MethodHandles;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;

import org.dkpro.jwpl.api.exception.WikiApiException;
import org.dkpro.jwpl.api.exception.WikiInitializationException;
Expand Down Expand Up @@ -483,7 +475,6 @@ public Map<Page, Double> getSimilarPages(String pPattern, int pSize) throws Wiki

// this returns a similarity - if we want to use it, we have to change the semantics the
// ordering of the results
// double distance = new Levenshtein().getSimilarity(pageName, pPattern);
double distance = lsd.distance(o.name(), pattern);

distanceMap.put(o.id(), distance);
Expand Down
18 changes: 13 additions & 5 deletions dkpro-jwpl-api/src/test/java/org/dkpro/jwpl/api/WikipediaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -439,12 +441,18 @@ public void testGetLanguage()
assertNotNull(wiki.getLanguage());
}

@Disabled(value = "This returns incorrect page elements with miscomputed distances")
@Test
public void testGetSimilarPages() throws WikiApiException {
final Map<Page, Double> similarPages = wiki.getSimilarPages("TK", 3);
@ParameterizedTest
@ValueSource(strings = {
"Wikipedia_AP",
"Wikipedia_API"
})
public void testGetSimilarPages(String val) throws WikiApiException {
final Map<Page, Double> similarPages = wiki.getSimilarPages(val, 1);
assertNotNull(similarPages);
assertFalse(similarPages.isEmpty());
assertEquals(1, similarPages.size());
Map.Entry<Page, Double> entry = similarPages.entrySet().iterator().next();
assertTrue(entry.getKey().getTitle().getRawTitleText().startsWith(val));
assertTrue(entry.getValue() <= 1);
}

/* INTERNAL TEST HELPER METHODS */
Expand Down

0 comments on commit 9ca5d74

Please sign in to comment.