|
1 | 1 |
|
| 2 | +import enum |
| 3 | +import textwrap |
| 4 | +import warnings |
2 | 5 | from collections.abc import Callable, Iterator, Sequence
|
3 | 6 | from typing import Optional, TypeVar
|
4 |
| -import warnings |
5 |
| -import textwrap |
6 | 7 |
|
7 | 8 | import wn
|
8 | 9 | from wn._types import (
|
|
46 | 47 | _INFERRED_SYNSET = '*INFERRED*'
|
47 | 48 |
|
48 | 49 |
|
| 50 | +class _EntityType(str, enum.Enum): |
| 51 | + """Identifies the database table of an entity.""" |
| 52 | + LEXICONS = 'lexicons' |
| 53 | + ENTRIES = 'entries' |
| 54 | + SENSES = 'senses' |
| 55 | + SYNSETS = 'synsets' |
| 56 | + SENSE_RELATIONS = 'sense_relations' |
| 57 | + SENSE_SYNSET_RELATIONS = 'sense_synset_relations' |
| 58 | + SYNSET_RELATIONS = 'synset_relations' |
| 59 | + UNSET = '' |
| 60 | + |
| 61 | + |
49 | 62 | class _DatabaseEntity:
|
50 | 63 | __slots__ = '_id',
|
51 | 64 |
|
52 |
| - _ENTITY_TYPE = '' |
| 65 | + _ENTITY_TYPE: _EntityType = _EntityType.UNSET |
53 | 66 |
|
54 | 67 | def __init__(self, _id: int = NON_ROWID):
|
55 | 68 | self._id = _id # Database-internal id (e.g., rowid)
|
@@ -122,7 +135,7 @@ class Lexicon(_DatabaseEntity):
|
122 | 135 | 'version', 'url', 'citation', 'logo')
|
123 | 136 | __module__ = 'wn'
|
124 | 137 |
|
125 |
| - _ENTITY_TYPE = 'lexicons' |
| 138 | + _ENTITY_TYPE = _EntityType.LEXICONS |
126 | 139 |
|
127 | 140 | def __init__(
|
128 | 141 | self,
|
@@ -341,7 +354,7 @@ class Word(_LexiconElement):
|
341 | 354 | __slots__ = 'id', 'pos', '_forms'
|
342 | 355 | __module__ = 'wn'
|
343 | 356 |
|
344 |
| - _ENTITY_TYPE = 'entries' |
| 357 | + _ENTITY_TYPE = _EntityType.ENTRIES |
345 | 358 |
|
346 | 359 | def __init__(
|
347 | 360 | self,
|
@@ -513,7 +526,7 @@ class Synset(_Relatable):
|
513 | 526 | __slots__ = 'pos', '_ili'
|
514 | 527 | __module__ = 'wn'
|
515 | 528 |
|
516 |
| - _ENTITY_TYPE = 'synsets' |
| 529 | + _ENTITY_TYPE = _EntityType.SYNSETS |
517 | 530 |
|
518 | 531 | def __init__(
|
519 | 532 | self,
|
@@ -869,7 +882,7 @@ class Sense(_Relatable):
|
869 | 882 | __slots__ = '_entry_id', '_synset_id'
|
870 | 883 | __module__ = 'wn'
|
871 | 884 |
|
872 |
| - _ENTITY_TYPE = 'senses' |
| 885 | + _ENTITY_TYPE = _EntityType.SENSES |
873 | 886 |
|
874 | 887 | def __init__(
|
875 | 888 | self,
|
|
0 commit comments