Skip to content

Commit d32d6c4

Browse files
committed
De-brand the wordnet lexicon contract: WordNetLexicon -> LexicalKnowledgeBase
Renames the public seam interface so consumers describe what they are injecting (a lexical knowledge base) rather than naming the WordNet brand in a public API type. Concrete implementations that genuinely are WordNet-format readers (InMemoryWordNetLexicon, WnLmfReader, WndbReader) keep the WordNet name, since they describe the data format they read, not the contract itself.
1 parent 2e03683 commit d32d6c4

10 files changed

Lines changed: 37 additions & 36 deletions

File tree

opennlp-api/src/main/java/opennlp/tools/wordnet/WordNetLexicon.java renamed to opennlp-api/src/main/java/opennlp/tools/wordnet/LexicalKnowledgeBase.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
import java.util.Optional;
2121

2222
/**
23-
* The wordnet lexicon seam: lemma and synset lookup over a loaded wordnet-style resource.
23+
* The lexical knowledge base seam: lemma and synset lookup over a loaded lexical-semantic
24+
* resource in the WordNet family.
2425
*
2526
* <p>This interface is the contract every wordnet-shaped dataset sits behind. A legacy Princeton
2627
* WNDB directory, a WN-LMF XML document (the Global WordNet Association interchange format used
2728
* by Open English WordNet and many other language wordnets), a future bundled
2829
* permissively-licensed lexicon, and a future user-downloaded CC-BY lexicon are all
29-
* implementations of this one seam, so a consumer written against {@code WordNetLexicon} never
30-
* changes when the data tier does. Nothing in the contract names a particular resource; synset
31-
* identity is opaque and source-qualified (see {@link Synset#id()}).</p>
30+
* implementations of this one seam, so a consumer written against {@code LexicalKnowledgeBase}
31+
* never changes when the data tier does. Nothing in the contract names a particular resource;
32+
* synset identity is opaque and source-qualified (see {@link Synset#id()}).</p>
3233
*
3334
* <p>The surface is intentionally minimal but sufficient for the layered features above it:
3435
* lemma lookup and membership for morphological analysis (Morphy-style lemmatization), and
@@ -44,7 +45,7 @@
4445
* <p>Implementations must be immutable and thread-safe after loading: one instance is meant to
4546
* be shared across an application's threads for concurrent lookups.</p>
4647
*/
47-
public interface WordNetLexicon {
48+
public interface LexicalKnowledgeBase {
4849

4950
/**
5051
* Finds the synsets containing a lemma with a part of speech, in the source's sense order

opennlp-api/src/main/java/opennlp/tools/wordnet/Synset.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* <p>The shape is deliberately format-agnostic. The {@link #id() id} is an opaque,
3131
* source-qualified string minted by whichever reader produced the synset (a WN-LMF document's
3232
* own synset id, or an id a WNDB reader derives from the file position); consumers must not
33-
* parse it, only pass it back to {@link WordNetLexicon#synset(String)} and compare it for
33+
* parse it, only pass it back to {@link LexicalKnowledgeBase#synset(String)} and compare it for
3434
* equality. Keeping identity opaque is what lets a bundled lexicon and a user-downloaded
3535
* lexicon sit behind the same seam, and lets later alignment layers join sources without a
3636
* contract change.</p>

opennlp-api/src/main/java/opennlp/tools/wordnet/WordNetRelation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* <p>The value set covers the pointer types documented for the legacy Princeton WNDB format,
2323
* which is also the common core the WN-LMF interchange format expresses; both readers map their
2424
* format's names onto these values, so consumers navigate one relation vocabulary regardless of
25-
* the data tier behind the {@link WordNetLexicon} seam. {@link #PARTICIPLE} is part of that
25+
* the data tier behind the {@link LexicalKnowledgeBase} seam. {@link #PARTICIPLE} is part of that
2626
* documented set (the adjective &quot;participle of verb&quot; pointer) even though it is easy
2727
* to overlook; without it, real Princeton data would be unreadable. Two values go beyond the
2828
* WNDB pointer set: {@link #ENTAILED_BY} and {@link #CAUSED_BY} cover the inverse relations

opennlp-api/src/test/java/opennlp/tools/wordnet/WordNetLexiconTest.java renamed to opennlp-api/src/test/java/opennlp/tools/wordnet/LexicalKnowledgeBaseTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import static org.junit.jupiter.api.Assertions.assertTrue;
2929

3030
/**
31-
* Exercises the {@link WordNetLexicon} default methods against a minimal in-memory
31+
* Exercises the {@link LexicalKnowledgeBase} default methods against a minimal in-memory
3232
* implementation, so the defaults are validated independently of any reader.
3333
*/
34-
public class WordNetLexiconTest {
34+
public class LexicalKnowledgeBaseTest {
3535

3636
private static final Synset DOG = new Synset("test-1-n", WordNetPos.NOUN, List.of("dog"),
3737
"a domesticated canid", Map.of(WordNetRelation.HYPERNYM, List.of("test-2-n")));
@@ -40,7 +40,7 @@ public class WordNetLexiconTest {
4040
"a carnivorous mammal", Map.of(WordNetRelation.HYPONYM, List.of("test-1-n")));
4141

4242
// A deliberately tiny implementation of only the two abstract methods.
43-
private static final WordNetLexicon LEXICON = new WordNetLexicon() {
43+
private static final LexicalKnowledgeBase LEXICON = new LexicalKnowledgeBase() {
4444

4545
@Override
4646
public List<Synset> lookup(String lemma, WordNetPos pos) {

opennlp-extensions/opennlp-wordnet/src/main/java/opennlp/wordnet/InMemoryWordNetLexicon.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
import java.util.Optional;
2727

2828
import opennlp.tools.commons.ThreadSafe;
29+
import opennlp.tools.wordnet.LexicalKnowledgeBase;
2930
import opennlp.tools.wordnet.Synset;
30-
import opennlp.tools.wordnet.WordNetLexicon;
3131
import opennlp.tools.wordnet.WordNetPos;
3232
import opennlp.tools.wordnet.WordNetRelation;
3333

3434
/**
35-
* The immutable in-memory {@link WordNetLexicon} both readers produce: a synset table plus a
35+
* The immutable in-memory {@link LexicalKnowledgeBase} both readers produce: a synset table plus a
3636
* folded (lemma, part of speech) index. Package-private because it is a reader product, not a
37-
* public entry point; consumers hold it as {@link WordNetLexicon}.
37+
* public entry point; consumers hold it as {@link LexicalKnowledgeBase}.
3838
*
3939
* <p>Lemma matching follows the recommended seam semantics: keys are folded by lowercasing with
4040
* the root locale and treating the underscore some formats store in multiword lemmas as a
@@ -45,7 +45,7 @@
4545
* After construction all state is immutable, making instances safe for concurrent lookups.</p>
4646
*/
4747
@ThreadSafe
48-
final class InMemoryWordNetLexicon implements WordNetLexicon {
48+
final class InMemoryWordNetLexicon implements LexicalKnowledgeBase {
4949

5050
private final Map<String, Synset> synsetsById;
5151
private final Map<LemmaKey, List<Synset>> senseIndex;

opennlp-extensions/opennlp-wordnet/src/main/java/opennlp/wordnet/MorphyLemmatizer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222

2323
import opennlp.tools.commons.ThreadSafe;
2424
import opennlp.tools.lemmatizer.Lemmatizer;
25-
import opennlp.tools.wordnet.WordNetLexicon;
25+
import opennlp.tools.wordnet.LexicalKnowledgeBase;
2626
import opennlp.tools.wordnet.WordNetPos;
2727

2828
/**
2929
* A clean-room implementation of the documented Morphy algorithm as a {@link Lemmatizer}:
3030
* exception-list lookup first, then the per-part-of-speech iterative detachment rules, with
31-
* every rule-derived candidate validated against a {@link WordNetLexicon} before it is
31+
* every rule-derived candidate validated against a {@link LexicalKnowledgeBase} before it is
3232
* returned.
3333
*
3434
* <p><b>Algorithm.</b> For each token the part-of-speech tag is mapped to a
@@ -90,7 +90,7 @@ public final class MorphyLemmatizer implements Lemmatizer {
9090

9191
private static final String[][] NO_RULES = {};
9292

93-
private final WordNetLexicon lexicon;
93+
private final LexicalKnowledgeBase lexicon;
9494
private final MorphyExceptions exceptions;
9595

9696
/**
@@ -102,7 +102,7 @@ public final class MorphyLemmatizer implements Lemmatizer {
102102
* @throws IllegalArgumentException Thrown if {@code lexicon} or {@code exceptions} is
103103
* {@code null}.
104104
*/
105-
public MorphyLemmatizer(WordNetLexicon lexicon, MorphyExceptions exceptions) {
105+
public MorphyLemmatizer(LexicalKnowledgeBase lexicon, MorphyExceptions exceptions) {
106106
if (lexicon == null) {
107107
throw new IllegalArgumentException("Lexicon must not be null");
108108
}

opennlp-extensions/opennlp-wordnet/src/main/java/opennlp/wordnet/WndbReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
import java.util.List;
2929
import java.util.Map;
3030

31+
import opennlp.tools.wordnet.LexicalKnowledgeBase;
3132
import opennlp.tools.wordnet.Synset;
32-
import opennlp.tools.wordnet.WordNetLexicon;
3333
import opennlp.tools.wordnet.WordNetPos;
3434
import opennlp.tools.wordnet.WordNetRelation;
3535

3636
/**
3737
* Reads a legacy Princeton WNDB database directory ({@code index.noun}, {@code data.noun}, and
38-
* the corresponding pairs for verbs, adjectives, and adverbs) into a {@link WordNetLexicon}.
38+
* the corresponding pairs for verbs, adjectives, and adverbs) into a {@link LexicalKnowledgeBase}.
3939
*
4040
* <p>The reader is clean-room, built from the published {@code wndb(5WN)} and
4141
* {@code wninput(5WN)} format documentation, with no third-party WordNet library involved. All
@@ -80,7 +80,7 @@ private WndbReader() {
8080
* file and line.
8181
* @throws UncheckedIOException Thrown if reading a file fails.
8282
*/
83-
public static WordNetLexicon read(Path directory) {
83+
public static LexicalKnowledgeBase read(Path directory) {
8484
if (directory == null) {
8585
throw new IllegalArgumentException("Directory must not be null");
8686
}

opennlp-extensions/opennlp-wordnet/src/test/java/opennlp/wordnet/LexiconConcurrencyTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import org.junit.jupiter.api.Test;
2626

27-
import opennlp.tools.wordnet.WordNetLexicon;
27+
import opennlp.tools.wordnet.LexicalKnowledgeBase;
2828
import opennlp.tools.wordnet.WordNetPos;
2929
import opennlp.tools.wordnet.WordNetRelation;
3030

@@ -42,7 +42,7 @@ public class LexiconConcurrencyTest {
4242

4343
@Test
4444
void testConcurrentLookupsSeeConsistentResults() throws InterruptedException {
45-
final WordNetLexicon lexicon = WndbReaderTest.fixture();
45+
final LexicalKnowledgeBase lexicon = WndbReaderTest.fixture();
4646
final CountDownLatch start = new CountDownLatch(1);
4747
final CountDownLatch done = new CountDownLatch(THREADS);
4848
final Queue<String> problems = new ConcurrentLinkedQueue<>();
@@ -70,7 +70,7 @@ void testConcurrentLookupsSeeConsistentResults() throws InterruptedException {
7070
assertEquals(List.of(), List.copyOf(problems));
7171
}
7272

73-
private static void verifyOnce(WordNetLexicon lexicon, Queue<String> problems) {
73+
private static void verifyOnce(LexicalKnowledgeBase lexicon, Queue<String> problems) {
7474
if (!"wndb-00001075-n".equals(lexicon.lookup("dog", WordNetPos.NOUN).get(0).id())) {
7575
problems.add("Wrong dog lookup");
7676
}

opennlp-extensions/opennlp-wordnet/src/test/java/opennlp/wordnet/ReaderEquivalenceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
import org.junit.jupiter.api.Test;
2626

27+
import opennlp.tools.wordnet.LexicalKnowledgeBase;
2728
import opennlp.tools.wordnet.Synset;
28-
import opennlp.tools.wordnet.WordNetLexicon;
2929
import opennlp.tools.wordnet.WordNetPos;
3030
import opennlp.tools.wordnet.WordNetRelation;
3131

@@ -61,7 +61,7 @@ void testBothReadersProduceEquivalentViews() {
6161

6262
@Test
6363
void testLookupAgreesForEveryLemmaAndPos() {
64-
final WordNetLexicon lmf = WnLmfReaderTest.fixture();
64+
final LexicalKnowledgeBase lmf = WnLmfReaderTest.fixture();
6565
final InMemoryWordNetLexicon wndb = (InMemoryWordNetLexicon) WndbReaderTest.fixture();
6666
final Set<String> checked = new HashSet<>();
6767
for (final Synset synset : wndb.synsets()) {
@@ -82,8 +82,8 @@ void testLookupAgreesForEveryLemmaAndPos() {
8282

8383
@Test
8484
void testSenseOrderAgreesForMultiSenseLemma() {
85-
final WordNetLexicon lmf = WnLmfReaderTest.fixture();
86-
final WordNetLexicon wndb = WndbReaderTest.fixture();
85+
final LexicalKnowledgeBase lmf = WnLmfReaderTest.fixture();
86+
final LexicalKnowledgeBase wndb = WndbReaderTest.fixture();
8787
final List<String> lmfOrder = glosses(lmf.lookup("run", WordNetPos.NOUN));
8888
final List<String> wndbOrder = glosses(wndb.lookup("run", WordNetPos.NOUN));
8989
assertEquals(2, lmfOrder.size());
@@ -102,7 +102,7 @@ private static Map<String, Synset> byGloss(InMemoryWordNetLexicon lexicon) {
102102

103103
// A synset's relations with targets replaced by their glosses, id-scheme independent.
104104
private static Map<WordNetRelation, Set<String>> relationsByGloss(Synset synset,
105-
WordNetLexicon lexicon) {
105+
LexicalKnowledgeBase lexicon) {
106106
final Map<WordNetRelation, Set<String>> result = new HashMap<>();
107107
for (final Map.Entry<WordNetRelation, List<String>> relation :
108108
synset.relations().entrySet()) {

opennlp-extensions/opennlp-wordnet/src/test/java/opennlp/wordnet/WndbReaderTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import org.junit.jupiter.api.Test;
2929
import org.junit.jupiter.api.io.TempDir;
3030

31+
import opennlp.tools.wordnet.LexicalKnowledgeBase;
3132
import opennlp.tools.wordnet.Synset;
32-
import opennlp.tools.wordnet.WordNetLexicon;
3333
import opennlp.tools.wordnet.WordNetPos;
3434
import opennlp.tools.wordnet.WordNetRelation;
3535

@@ -53,7 +53,7 @@ static Path fixtureDirectory() {
5353
}
5454
}
5555

56-
static WordNetLexicon fixture() {
56+
static LexicalKnowledgeBase fixture() {
5757
return WndbReader.read(fixtureDirectory());
5858
}
5959

@@ -71,7 +71,7 @@ void testLookupReturnsSynsetWithAllComponents() {
7171

7272
@Test
7373
void testLookupFoldsCaseAndUnderscore() {
74-
final WordNetLexicon lexicon = fixture();
74+
final LexicalKnowledgeBase lexicon = fixture();
7575
assertEquals(DOG_ID, lexicon.lookup("Domestic_Dog", WordNetPos.NOUN).get(0).id());
7676
assertEquals(DOG_ID, lexicon.lookup("DOG", WordNetPos.NOUN).get(0).id());
7777
}
@@ -84,7 +84,7 @@ void testLookupKeepsIndexSenseOrder() {
8484

8585
@Test
8686
void testRelationNavigation() {
87-
final WordNetLexicon lexicon = fixture();
87+
final LexicalKnowledgeBase lexicon = fixture();
8888
assertEquals(List.of(DOG_ID), lexicon.related(CANID_ID, WordNetRelation.HYPONYM));
8989
assertEquals(List.of("wndb-00001075-v", "wndb-00001171-v"),
9090
lexicon.related("wndb-00001324-v", WordNetRelation.HYPONYM));
@@ -94,7 +94,7 @@ void testRelationNavigation() {
9494

9595
@Test
9696
void testLexicalPointersSurfaceAtSynsetLevel() {
97-
final WordNetLexicon lexicon = fixture();
97+
final LexicalKnowledgeBase lexicon = fixture();
9898
assertEquals(List.of("wndb-00001141-a"),
9999
lexicon.related("wndb-00001075-a", WordNetRelation.ANTONYM));
100100
assertEquals(List.of("wndb-00001075-a"),
@@ -103,7 +103,7 @@ void testLexicalPointersSurfaceAtSynsetLevel() {
103103

104104
@Test
105105
void testSatelliteNormalizesToAdjectiveAndMarkerIsStripped() {
106-
final WordNetLexicon lexicon = fixture();
106+
final LexicalKnowledgeBase lexicon = fixture();
107107
final Synset large = lexicon.lookup("large", WordNetPos.ADJECTIVE).get(0);
108108
assertEquals(WordNetPos.ADJECTIVE, large.pos());
109109
assertEquals(List.of("wndb-00001211-a"), large.related(WordNetRelation.SIMILAR_TO));
@@ -114,7 +114,7 @@ void testSatelliteNormalizesToAdjectiveAndMarkerIsStripped() {
114114

115115
@Test
116116
void testUnknownLemmaOrSynsetIsEmpty() {
117-
final WordNetLexicon lexicon = fixture();
117+
final LexicalKnowledgeBase lexicon = fixture();
118118
assertTrue(lexicon.lookup("zebra", WordNetPos.NOUN).isEmpty());
119119
assertTrue(lexicon.synset("wndb-99999999-n").isEmpty());
120120
}

0 commit comments

Comments
 (0)