synset 0.9.0
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.
- package/LICENSE +21 -0
- package/README.md +190 -0
- package/dist/cli.cjs +1139 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1116 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +1139 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +319 -0
- package/dist/index.d.ts +319 -0
- package/dist/index.js +1048 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 king8fisher
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# synset
|
|
2
|
+
|
|
3
|
+
WordNet dictionary parser with Zod validation, query utilities, and CLI.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install synset
|
|
9
|
+
# or
|
|
10
|
+
bun add synset
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Library
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {
|
|
19
|
+
fetchWordNet,
|
|
20
|
+
loadWordNet,
|
|
21
|
+
buildIndex,
|
|
22
|
+
getDefinitions,
|
|
23
|
+
getSynonyms,
|
|
24
|
+
getHypernyms,
|
|
25
|
+
findSynsets,
|
|
26
|
+
} from 'synset'
|
|
27
|
+
|
|
28
|
+
// Fetch WordNet data (auto-discovers latest version, downloads & caches ~100MB XML)
|
|
29
|
+
const { lexicon, version } = await fetchWordNet()
|
|
30
|
+
console.log(`Loaded WordNet ${version}`)
|
|
31
|
+
|
|
32
|
+
// Or load from local file
|
|
33
|
+
const lexicon = await loadWordNet('./path/to/english-wordnet-{YEAR}.xml')
|
|
34
|
+
|
|
35
|
+
// Or request specific version
|
|
36
|
+
const { lexicon } = await fetchWordNet({ version: '2024' })
|
|
37
|
+
|
|
38
|
+
// Build index for fast lookups
|
|
39
|
+
const index = buildIndex(lexicon)
|
|
40
|
+
|
|
41
|
+
// Query
|
|
42
|
+
getDefinitions(index, 'dog')
|
|
43
|
+
// [{ text: "a member of the genus Canis...", synset, partOfSpeech: "n" }, ...]
|
|
44
|
+
|
|
45
|
+
getSynonyms(index, 'happy')
|
|
46
|
+
// [{ word: "glad", entry, synset }, ...]
|
|
47
|
+
|
|
48
|
+
getHypernyms(index, 'dog')
|
|
49
|
+
// [Synset for "canine", Synset for "domestic animal", ...]
|
|
50
|
+
|
|
51
|
+
findSynsets(index, 'bank')
|
|
52
|
+
// [Synset for "financial institution", Synset for "river bank", ...]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### CLI
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Show definitions
|
|
59
|
+
synset define dog
|
|
60
|
+
|
|
61
|
+
# List synonyms
|
|
62
|
+
synset synonyms happy
|
|
63
|
+
|
|
64
|
+
# Show hypernyms (more general terms)
|
|
65
|
+
synset hypernyms dog
|
|
66
|
+
|
|
67
|
+
# Show all relations
|
|
68
|
+
synset related computer
|
|
69
|
+
|
|
70
|
+
# Pre-download WordNet data
|
|
71
|
+
synset fetch
|
|
72
|
+
|
|
73
|
+
# Use local file instead of cache
|
|
74
|
+
synset define dog --file ./path/to/english-wordnet-{YEAR}.xml
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Exports
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
// Zod schemas (runtime validation)
|
|
81
|
+
import { Lexicon, Synset, Sense, LexicalEntry } from 'synset'
|
|
82
|
+
|
|
83
|
+
// TypeScript types
|
|
84
|
+
import type { LexiconType, SynsetType, SenseType } from 'synset'
|
|
85
|
+
|
|
86
|
+
// Human-readable labels
|
|
87
|
+
import { PartsOfSpeechLabels, SynsetRelationLabels } from 'synset'
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Runtime
|
|
91
|
+
|
|
92
|
+
- **Bun**: Full support (recommended)
|
|
93
|
+
- **Node.js 18+**: Supported for remote fetching. Local file parsing requires Bun due to `file://` URL fetch limitations.
|
|
94
|
+
|
|
95
|
+
## Development
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
bun install
|
|
99
|
+
bun test
|
|
100
|
+
bun run check # typecheck
|
|
101
|
+
bun run build # build dist/
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Dictionary Module
|
|
105
|
+
|
|
106
|
+
- WordNet
|
|
107
|
+
- Format:
|
|
108
|
+
- https://globalwordnet.github.io/schemas/
|
|
109
|
+
- XML file source:
|
|
110
|
+
- https://github.com/globalwordnet/english-wordnet
|
|
111
|
+
- Latest version auto-discovered and downloaded by tests
|
|
112
|
+
- XML format:
|
|
113
|
+
[DTD](https://globalwordnet.github.io/schemas/WN-LMF-1.3.dtd)
|
|
114
|
+
- Manually copied over to
|
|
115
|
+
- `WN-LMF-1.3.dtd`
|
|
116
|
+
|
|
117
|
+
### WordNet XML Source Structure
|
|
118
|
+
|
|
119
|
+
(Originally created with `xmlstarlet` against the 2023 xml file).
|
|
120
|
+
|
|
121
|
+
`$ xmlstarlet el data/english-wordnet-2023.xml | sort | uniq | sort`
|
|
122
|
+
(with unicode symbols added manually)
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
📂 LexicalResource root node
|
|
126
|
+
📂 Lexicon desc of the database: id prefix, language, version, ...
|
|
127
|
+
📂 LexicalEntry an id for grouping children that can be refed by a Synset.
|
|
128
|
+
📄 Form
|
|
129
|
+
📂 Lemma
|
|
130
|
+
📄 Pronunciation
|
|
131
|
+
📂 Sense
|
|
132
|
+
📄 SenseRelation
|
|
133
|
+
📂 Synset
|
|
134
|
+
📄 Definition
|
|
135
|
+
📄 Example
|
|
136
|
+
📄 ILIDefinition
|
|
137
|
+
📄 SynsetRelation
|
|
138
|
+
📄 SyntacticBehaviour
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Schema Verification
|
|
142
|
+
|
|
143
|
+
Stats accumulated with:
|
|
144
|
+
* `$ xmlstarlet el data/english-wordnet-2023.xml | sort | uniq -c | sort -n`
|
|
145
|
+
* `$ grep -oE '<[A-Za-z]+' data/english-wordnet-2024.xml | sed 's/<//g' | sort | uniq -c | sort -n`
|
|
146
|
+
|
|
147
|
+
Element counts comparison (schema unchanged between releases):
|
|
148
|
+
|
|
149
|
+
| Element | 2023 | 2024 |
|
|
150
|
+
| ------------------ | -----: | -----: |
|
|
151
|
+
| LexicalResource | 1 | 1 |
|
|
152
|
+
| Lexicon | 1 | 1 |
|
|
153
|
+
| SyntacticBehaviour | 39 | 39 |
|
|
154
|
+
| ILIDefinition | 2700 | 3216 |
|
|
155
|
+
| Form | 4474 | 4474 |
|
|
156
|
+
| Pronunciation | 44671 | 44669 |
|
|
157
|
+
| Example | 49638 | 49723 |
|
|
158
|
+
| Synset | 120135 | 120630 |
|
|
159
|
+
| Definition | 120141 | 120635 |
|
|
160
|
+
| SenseRelation | 122041 | 122018 |
|
|
161
|
+
| LexicalEntry | 161338 | 161705 |
|
|
162
|
+
| Lemma | 161338 | 161705 |
|
|
163
|
+
| Sense | 212071 | 212478 |
|
|
164
|
+
| SynsetRelation | 293864 | 297150 |
|
|
165
|
+
|
|
166
|
+
## Zod Test Coverage
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
📂 LexicalResource [-] (basic test for a parent)
|
|
170
|
+
📂 Lexicon [-] (basic test for a parent)
|
|
171
|
+
📂 LexicalEntry [x]
|
|
172
|
+
📄 Form [x]
|
|
173
|
+
📂 Lemma [x]
|
|
174
|
+
📄 Pronunciation [x]
|
|
175
|
+
📂 Sense [x]
|
|
176
|
+
📄 SenseRelation [x]
|
|
177
|
+
📂 Synset [x]
|
|
178
|
+
📄 Definition [x]
|
|
179
|
+
📄 Example [x]
|
|
180
|
+
📄 ILIDefinition [x]
|
|
181
|
+
📄 SynsetRelation [x]
|
|
182
|
+
📄 SyntacticBehaviour [x]
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## TODO
|
|
186
|
+
|
|
187
|
+
- [ ] Support [Open English Namenet](https://en-word.net/) - proper nouns (people, places, etc.) were moved to a separate resource starting with 2025 release
|
|
188
|
+
- [ ] Option to fetch "2025+" edition which includes curated proper nouns from Namenet
|
|
189
|
+
- [ ] CLI `--json` flag for JSON output
|
|
190
|
+
- [ ] CLI colored output (disable with `--no-color`)
|