ovos-wordnet-plugin 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,211 @@
1
+ Metadata-Version: 2.4
2
+ Name: ovos-wordnet-plugin
3
+ Version: 0.1.0
4
+ Summary: OVOS WordNet plugin — dictionary definitions and lexical relations
5
+ License: Apache-2.0
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: ovos-utils<1.0.0,>=0.7.0
9
+ Requires-Dist: ovos-plugin-manager<3.0.0,>=2.3.0a1
10
+ Requires-Dist: wn>=0.9
11
+ Requires-Dist: pydantic
12
+
13
+ # ovos-wordnet-plugin
14
+
15
+ OVOS plugin that exposes [WordNet](https://wordnet.princeton.edu/) as a
16
+ `RetrievalEngine` and a `ToolBox` with two agent tools.
17
+
18
+ Supports 30+ languages via the [`wn`](https://pypi.org/project/wn/) package
19
+ with [Open English WordNet 2024](https://github.com/globalwordnet/english-wordnet),
20
+ [ODENet](https://github.com/hdaSprachtechnologie/odenet) for German, and
21
+ [OMW 1.4](https://omwn.org/) packs for other languages. Lexicons are
22
+ downloaded automatically on first use and cached locally.
23
+
24
+ For languages whose OMW pack has no native definitions (most non-EN/DE
25
+ languages), the engine fetches the English OEWN definition and translates it
26
+ into the target language using the OVOS translation plugin configured on the
27
+ system (default: `ovos-translate-plugin-server`).
28
+
29
+ ---
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install ovos-wordnet-plugin
35
+ ```
36
+
37
+ The first query downloads the required WordNet lexicon (~30–60 MB for English).
38
+ Subsequent calls are served from the local cache with no network access.
39
+
40
+ ---
41
+
42
+ ## Components
43
+
44
+ ### `WordnetRetrievalEngine`
45
+
46
+ An OVOS [`RetrievalEngine`](https://github.com/OpenVoiceOS/ovos-plugin-manager)
47
+ that returns natural-language passages for a word lookup. Each passage covers
48
+ one WordNet sense and is formatted as:
49
+
50
+ ```
51
+ dog (noun): a member of the genus Canis. Also known as: domestic dog, Canis familiaris. Example: the dog barked all night
52
+ ```
53
+
54
+ When the query matches a locale intent pattern (e.g. *"what are the antonyms
55
+ of happy?"*) the engine resolves that specific relation and returns a single
56
+ rendered dialog response instead.
57
+
58
+ Passages are drawn from all four parts of speech (noun → verb → adjective →
59
+ adverb) up to the requested `k` limit.
60
+
61
+ ```python
62
+ from ovos_wordnet_plugin import WordnetRetrievalEngine
63
+
64
+ engine = WordnetRetrievalEngine()
65
+ for passage, score in engine.query("bank", lang="en", k=3):
66
+ print(f"[{score:.2f}] {passage}")
67
+ ```
68
+
69
+ ```
70
+ [0.70] bank (noun): sloping land (especially the slope beside a body of water). Example: he sat on the bank of the river
71
+ [0.70] bank (noun): a financial institution that accepts deposits. Also known as: depository financial institution.
72
+ [0.70] bank (verb): tip laterally. Example: the pilot had to bank the aircraft
73
+ ```
74
+
75
+ Intent-style queries return a single spoken-language response:
76
+
77
+ ```python
78
+ for passage, score in engine.query("what are the hyponyms of dog", lang="en"):
79
+ print(f"[{score:.2f}] {passage}")
80
+ # [0.90] The hyponyms of dog are: poodle, corgi, dalmatian, ...
81
+ ```
82
+
83
+ ### `WordnetToolbox`
84
+
85
+ An OVOS `ToolBox` that registers two agent tools.
86
+
87
+ #### `define_word`
88
+
89
+ Returns definitions grouped by part of speech, plus usage examples.
90
+
91
+ | Argument | Type | Default | Description |
92
+ |---|---|---|---|
93
+ | `word` | str | — | Word to define |
94
+ | `lang` | str | `"en"` | BCP-47 language code |
95
+ | `pos` | str | `"any"` | `"noun"`, `"verb"`, `"adjective"`, `"adverb"`, or `"any"` |
96
+
97
+ ```python
98
+ from ovos_wordnet_plugin import WordnetToolbox, DefineWordArgs
99
+
100
+ tb = WordnetToolbox()
101
+ out = tb.define_word(DefineWordArgs(word="run", lang="en", pos="verb"))
102
+ for pos_label, definition in out.definitions:
103
+ print(f"{pos_label}: {definition}")
104
+ # verb: move fast by using one's feet, with one foot off the ground at any given time
105
+ print(out.examples[:2])
106
+ # ['she ran her first marathon', ...]
107
+ ```
108
+
109
+ #### `word_relations`
110
+
111
+ Returns synonyms, antonyms, hypernyms, hyponyms, and holonyms.
112
+
113
+ | Argument | Type | Default | Description |
114
+ |---|---|---|---|
115
+ | `word` | str | — | Word to look up |
116
+ | `lang` | str | `"en"` | BCP-47 language code |
117
+ | `pos` | str | `"noun"` | `"noun"`, `"verb"`, `"adjective"`, or `"adverb"` |
118
+
119
+ ```python
120
+ from ovos_wordnet_plugin import WordnetToolbox, WordRelationsArgs
121
+
122
+ tb = WordnetToolbox()
123
+ out = tb.word_relations(WordRelationsArgs(word="dog", lang="en", pos="noun"))
124
+ print("synonyms:", out.synonyms) # ['dog', 'domestic dog', 'Canis familiaris']
125
+ print("hypernyms:", out.hypernyms) # ['canine', 'canid', ...]
126
+ print("hyponyms:", out.hyponyms[:3]) # ['corgi', 'dalmatian', 'poodle']
127
+ print("holonyms:", out.holonyms) # ['pack', ...]
128
+ ```
129
+
130
+ ### Low-level `Wordnet` helper
131
+
132
+ The `Wordnet` class provides direct access to all WordNet relations:
133
+
134
+ ```python
135
+ from ovos_wordnet_plugin import Wordnet, NOUN, ADJ
136
+
137
+ # First sense only
138
+ data = Wordnet.get("bank", pos=NOUN, lang="en")
139
+
140
+ # All senses (generator)
141
+ for sense in Wordnet.search("bank", pos=NOUN, lang="en"):
142
+ print(sense["definition"])
143
+
144
+ # Individual lookups
145
+ Wordnet.get_definition("bank", lang="en")
146
+ Wordnet.get_lemmas("bank", lang="en")
147
+ Wordnet.get_hypernyms("dog", lang="en")
148
+ Wordnet.get_hyponyms("dog", lang="en")
149
+ Wordnet.get_holonyms("dog", lang="en")
150
+ Wordnet.get_antonyms("good", pos=ADJ, lang="en")
151
+ Wordnet.get_root_hypernyms("dog", lang="en")
152
+ Wordnet.common_hypernyms("dog", "cat", lang="en")
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Supported Languages
158
+
159
+ English uses OEWN 2024 (native definitions throughout). German uses ODENet
160
+ (native definitions for ~85% of synsets). All other languages use their OMW
161
+ 1.4 pack, which provides lemmas but typically no glosses — definitions are
162
+ translated from English via the configured OVOS translation plugin.
163
+
164
+ | BCP-47 | Language | Source |
165
+ |--------|----------|--------|
166
+ | `en` | English | Open English WordNet 2024 |
167
+ | `de` | German | ODENet 1.4 (native definitions) |
168
+ | `ar` | Arabic | OMW 1.4 |
169
+ | `bg` | Bulgarian | OMW 1.4 |
170
+ | `ca` | Catalan | OMW 1.4 |
171
+ | `cmn` | Mandarin Chinese | OMW 1.4 |
172
+ | `da` | Danish | OMW 1.4 |
173
+ | `el` | Greek | OMW 1.4 |
174
+ | `es` | Spanish | OMW 1.4 |
175
+ | `eu` | Basque | OMW 1.4 |
176
+ | `fi` | Finnish | OMW 1.4 |
177
+ | `fr` | French | OMW 1.4 |
178
+ | `gl` | Galician | OMW 1.4 |
179
+ | `he` | Hebrew | OMW 1.4 |
180
+ | `hr` | Croatian | OMW 1.4 |
181
+ | `id` | Indonesian | OMW 1.4 |
182
+ | `is` | Icelandic | OMW 1.4 |
183
+ | `it` | Italian | OMW 1.4 |
184
+ | `ja` | Japanese | OMW 1.4 |
185
+ | `lt` | Lithuanian | OMW 1.4 |
186
+ | `nb` | Norwegian Bokmål | OMW 1.4 |
187
+ | `nl` | Dutch | OMW 1.4 |
188
+ | `nn` | Norwegian Nynorsk | OMW 1.4 |
189
+ | `pl` | Polish | OMW 1.4 |
190
+ | `pt` | Portuguese | OMW 1.4 |
191
+ | `ro` | Romanian | OMW 1.4 |
192
+ | `sk` | Slovak | OMW 1.4 |
193
+ | `sl` | Slovenian | OMW 1.4 |
194
+ | `sv` | Swedish | OMW 1.4 |
195
+ | `th` | Thai | OMW 1.4 |
196
+ | `zsm` | Standard Malay | OMW 1.4 |
197
+
198
+ ---
199
+
200
+ ## Running tests
201
+
202
+ ```bash
203
+ pip install pytest
204
+ pytest tests/
205
+ ```
206
+
207
+ ---
208
+
209
+ ## License
210
+
211
+ Apache 2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,199 @@
1
+ # ovos-wordnet-plugin
2
+
3
+ OVOS plugin that exposes [WordNet](https://wordnet.princeton.edu/) as a
4
+ `RetrievalEngine` and a `ToolBox` with two agent tools.
5
+
6
+ Supports 30+ languages via the [`wn`](https://pypi.org/project/wn/) package
7
+ with [Open English WordNet 2024](https://github.com/globalwordnet/english-wordnet),
8
+ [ODENet](https://github.com/hdaSprachtechnologie/odenet) for German, and
9
+ [OMW 1.4](https://omwn.org/) packs for other languages. Lexicons are
10
+ downloaded automatically on first use and cached locally.
11
+
12
+ For languages whose OMW pack has no native definitions (most non-EN/DE
13
+ languages), the engine fetches the English OEWN definition and translates it
14
+ into the target language using the OVOS translation plugin configured on the
15
+ system (default: `ovos-translate-plugin-server`).
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install ovos-wordnet-plugin
23
+ ```
24
+
25
+ The first query downloads the required WordNet lexicon (~30–60 MB for English).
26
+ Subsequent calls are served from the local cache with no network access.
27
+
28
+ ---
29
+
30
+ ## Components
31
+
32
+ ### `WordnetRetrievalEngine`
33
+
34
+ An OVOS [`RetrievalEngine`](https://github.com/OpenVoiceOS/ovos-plugin-manager)
35
+ that returns natural-language passages for a word lookup. Each passage covers
36
+ one WordNet sense and is formatted as:
37
+
38
+ ```
39
+ dog (noun): a member of the genus Canis. Also known as: domestic dog, Canis familiaris. Example: the dog barked all night
40
+ ```
41
+
42
+ When the query matches a locale intent pattern (e.g. *"what are the antonyms
43
+ of happy?"*) the engine resolves that specific relation and returns a single
44
+ rendered dialog response instead.
45
+
46
+ Passages are drawn from all four parts of speech (noun → verb → adjective →
47
+ adverb) up to the requested `k` limit.
48
+
49
+ ```python
50
+ from ovos_wordnet_plugin import WordnetRetrievalEngine
51
+
52
+ engine = WordnetRetrievalEngine()
53
+ for passage, score in engine.query("bank", lang="en", k=3):
54
+ print(f"[{score:.2f}] {passage}")
55
+ ```
56
+
57
+ ```
58
+ [0.70] bank (noun): sloping land (especially the slope beside a body of water). Example: he sat on the bank of the river
59
+ [0.70] bank (noun): a financial institution that accepts deposits. Also known as: depository financial institution.
60
+ [0.70] bank (verb): tip laterally. Example: the pilot had to bank the aircraft
61
+ ```
62
+
63
+ Intent-style queries return a single spoken-language response:
64
+
65
+ ```python
66
+ for passage, score in engine.query("what are the hyponyms of dog", lang="en"):
67
+ print(f"[{score:.2f}] {passage}")
68
+ # [0.90] The hyponyms of dog are: poodle, corgi, dalmatian, ...
69
+ ```
70
+
71
+ ### `WordnetToolbox`
72
+
73
+ An OVOS `ToolBox` that registers two agent tools.
74
+
75
+ #### `define_word`
76
+
77
+ Returns definitions grouped by part of speech, plus usage examples.
78
+
79
+ | Argument | Type | Default | Description |
80
+ |---|---|---|---|
81
+ | `word` | str | — | Word to define |
82
+ | `lang` | str | `"en"` | BCP-47 language code |
83
+ | `pos` | str | `"any"` | `"noun"`, `"verb"`, `"adjective"`, `"adverb"`, or `"any"` |
84
+
85
+ ```python
86
+ from ovos_wordnet_plugin import WordnetToolbox, DefineWordArgs
87
+
88
+ tb = WordnetToolbox()
89
+ out = tb.define_word(DefineWordArgs(word="run", lang="en", pos="verb"))
90
+ for pos_label, definition in out.definitions:
91
+ print(f"{pos_label}: {definition}")
92
+ # verb: move fast by using one's feet, with one foot off the ground at any given time
93
+ print(out.examples[:2])
94
+ # ['she ran her first marathon', ...]
95
+ ```
96
+
97
+ #### `word_relations`
98
+
99
+ Returns synonyms, antonyms, hypernyms, hyponyms, and holonyms.
100
+
101
+ | Argument | Type | Default | Description |
102
+ |---|---|---|---|
103
+ | `word` | str | — | Word to look up |
104
+ | `lang` | str | `"en"` | BCP-47 language code |
105
+ | `pos` | str | `"noun"` | `"noun"`, `"verb"`, `"adjective"`, or `"adverb"` |
106
+
107
+ ```python
108
+ from ovos_wordnet_plugin import WordnetToolbox, WordRelationsArgs
109
+
110
+ tb = WordnetToolbox()
111
+ out = tb.word_relations(WordRelationsArgs(word="dog", lang="en", pos="noun"))
112
+ print("synonyms:", out.synonyms) # ['dog', 'domestic dog', 'Canis familiaris']
113
+ print("hypernyms:", out.hypernyms) # ['canine', 'canid', ...]
114
+ print("hyponyms:", out.hyponyms[:3]) # ['corgi', 'dalmatian', 'poodle']
115
+ print("holonyms:", out.holonyms) # ['pack', ...]
116
+ ```
117
+
118
+ ### Low-level `Wordnet` helper
119
+
120
+ The `Wordnet` class provides direct access to all WordNet relations:
121
+
122
+ ```python
123
+ from ovos_wordnet_plugin import Wordnet, NOUN, ADJ
124
+
125
+ # First sense only
126
+ data = Wordnet.get("bank", pos=NOUN, lang="en")
127
+
128
+ # All senses (generator)
129
+ for sense in Wordnet.search("bank", pos=NOUN, lang="en"):
130
+ print(sense["definition"])
131
+
132
+ # Individual lookups
133
+ Wordnet.get_definition("bank", lang="en")
134
+ Wordnet.get_lemmas("bank", lang="en")
135
+ Wordnet.get_hypernyms("dog", lang="en")
136
+ Wordnet.get_hyponyms("dog", lang="en")
137
+ Wordnet.get_holonyms("dog", lang="en")
138
+ Wordnet.get_antonyms("good", pos=ADJ, lang="en")
139
+ Wordnet.get_root_hypernyms("dog", lang="en")
140
+ Wordnet.common_hypernyms("dog", "cat", lang="en")
141
+ ```
142
+
143
+ ---
144
+
145
+ ## Supported Languages
146
+
147
+ English uses OEWN 2024 (native definitions throughout). German uses ODENet
148
+ (native definitions for ~85% of synsets). All other languages use their OMW
149
+ 1.4 pack, which provides lemmas but typically no glosses — definitions are
150
+ translated from English via the configured OVOS translation plugin.
151
+
152
+ | BCP-47 | Language | Source |
153
+ |--------|----------|--------|
154
+ | `en` | English | Open English WordNet 2024 |
155
+ | `de` | German | ODENet 1.4 (native definitions) |
156
+ | `ar` | Arabic | OMW 1.4 |
157
+ | `bg` | Bulgarian | OMW 1.4 |
158
+ | `ca` | Catalan | OMW 1.4 |
159
+ | `cmn` | Mandarin Chinese | OMW 1.4 |
160
+ | `da` | Danish | OMW 1.4 |
161
+ | `el` | Greek | OMW 1.4 |
162
+ | `es` | Spanish | OMW 1.4 |
163
+ | `eu` | Basque | OMW 1.4 |
164
+ | `fi` | Finnish | OMW 1.4 |
165
+ | `fr` | French | OMW 1.4 |
166
+ | `gl` | Galician | OMW 1.4 |
167
+ | `he` | Hebrew | OMW 1.4 |
168
+ | `hr` | Croatian | OMW 1.4 |
169
+ | `id` | Indonesian | OMW 1.4 |
170
+ | `is` | Icelandic | OMW 1.4 |
171
+ | `it` | Italian | OMW 1.4 |
172
+ | `ja` | Japanese | OMW 1.4 |
173
+ | `lt` | Lithuanian | OMW 1.4 |
174
+ | `nb` | Norwegian Bokmål | OMW 1.4 |
175
+ | `nl` | Dutch | OMW 1.4 |
176
+ | `nn` | Norwegian Nynorsk | OMW 1.4 |
177
+ | `pl` | Polish | OMW 1.4 |
178
+ | `pt` | Portuguese | OMW 1.4 |
179
+ | `ro` | Romanian | OMW 1.4 |
180
+ | `sk` | Slovak | OMW 1.4 |
181
+ | `sl` | Slovenian | OMW 1.4 |
182
+ | `sv` | Swedish | OMW 1.4 |
183
+ | `th` | Thai | OMW 1.4 |
184
+ | `zsm` | Standard Malay | OMW 1.4 |
185
+
186
+ ---
187
+
188
+ ## Running tests
189
+
190
+ ```bash
191
+ pip install pytest
192
+ pytest tests/
193
+ ```
194
+
195
+ ---
196
+
197
+ ## License
198
+
199
+ Apache 2.0 — see [LICENSE](LICENSE).