An extended editor for wordnets, building on the popular 'wn' package with additional features for synset creation and relation management.
Project description
wn-editor-extended
An extended editor for wordnets, building on the popular wn package with additional features for synset creation and relation management.
This is an extended fork of wn-editor by Jannes Müller, with additional features and bug fixes.
Features
- Edit WordNet databases directly from Python
- Create synsets with words, definitions, and relations
- Set part-of-speech on synsets and entries
- Manage relations (hypernyms, hyponyms, etc.)
- Full compatibility with the
wnpackage
Enhancements over original wn-editor
SynsetEditor.set_pos()- Set part of speech on synsetsSynsetEditor.add_word(word, pos=None)- Add words with optional POS- Fixed form creation to set
rank=0(required forwn.synsets()to find new terms) - Fixed various edge cases in ID generation
Installation
pip install wn-editor-extended
Quick Start
import wn
from wn_editor.editor import LexiconEditor, SynsetEditor
# Download WordNet if needed
wn.download('ewn:2020')
# Get an editor for an installed lexicon
lex_edit = LexiconEditor('ewn')
# Create a new synset
synset_editor = lex_edit.create_synset()
synset_editor.add_word('blockchain', pos='n')
synset_editor.add_definition('A decentralized digital ledger technology')
# Get the synset object
new_synset = synset_editor.as_synset()
print(f"Created: {new_synset.id()}")
# Verify it can be found
print(wn.synsets('blockchain')) # Should find the new synset
Editing Existing Synsets
import wn
from wn_editor.editor import SynsetEditor
# Get an existing synset
dog_synset = wn.synsets('dog', pos='n')[0]
# Create an editor for it
editor = SynsetEditor(dog_synset)
# Add a new word/synonym
editor.add_word('canine')
# Modify definition
editor.mod_definition('A domesticated carnivorous mammal')
Setting Relations
from wn_editor.editor import LexiconEditor, _set_relation_to_synset
lex_edit = LexiconEditor('ewn')
# Create a new synset
synset_editor = lex_edit.create_synset()
synset_editor.add_word('neural_ranker', pos='n')
synset_editor.add_definition('A ranking model using neural networks')
new_synset = synset_editor.as_synset()
# Set hypernym relation (15 is the database ID for hypernym)
hypernym = wn.synset('ewn-06590830-n') # software synset
_set_relation_to_synset(new_synset, hypernym, 15)
API Reference
LexiconEditor
LexiconEditor(lexicon_id: str)
.create_synset() -> SynsetEditor
SynsetEditor
SynsetEditor(synset_or_rowid)
.add_word(word: str, pos: str = None) -> SynsetEditor
.add_definition(definition: str) -> SynsetEditor
.mod_definition(definition: str) -> SynsetEditor
.set_pos(pos: str) -> SynsetEditor
.as_synset() -> wn.Synset
Requirements
- Python 3.9+
- wn >= 0.9.1
Acknowledgments
License
MIT License - See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wn_editor_extended-0.6.1.tar.gz.
File metadata
- Download URL: wn_editor_extended-0.6.1.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
298c10959ae19ff57c826b32221d394a69c09500212d729eee981875ec9a5511
|
|
| MD5 |
7feaa06aa293d9bb7e30cabf15bd3a08
|
|
| BLAKE2b-256 |
1fa621de67d72aca951c7bf26ee2b4bd0b811a7e993867180cf6caee5be60d2a
|
File details
Details for the file wn_editor_extended-0.6.1-py3-none-any.whl.
File metadata
- Download URL: wn_editor_extended-0.6.1-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57faa88135ad87198a6362779c0ec56af068a7c40e25c7374fb86f17a24fcb23
|
|
| MD5 |
d39b46aed0e27a2390a6b233b14ad93c
|
|
| BLAKE2b-256 |
90ecd25d0b70728f070e892fc2b59f5cb0be8e8500316ad34e28b43f9c6d6559
|