| 1 |
|
| 2 |
wn |
| 3 |
=== |
| 4 |
|
| 5 |
.. automodule:: wn |
| 6 |
|
| 7 |
|
| 8 |
Project Management Functions |
| 9 |
---------------------------- |
| 10 |
|
| 11 |
.. autofunction:: download |
| 12 |
.. autofunction:: add |
| 13 |
.. autofunction:: add_lexical_resource |
| 14 |
.. autofunction:: remove |
| 15 |
.. autofunction:: export |
| 16 |
.. autofunction:: projects |
| 17 |
.. autofunction:: reset_database |
| 18 |
|
| 19 |
|
| 20 |
Wordnet Query Functions |
| 21 |
----------------------- |
| 22 |
|
| 23 |
While it is best to first instantiate a :class:`Wordnet` object with a |
| 24 |
specific lexicon and use that for querying (see :ref:`default-mode`), |
| 25 |
the following functions are also available for quick and simple |
| 26 |
queries. |
| 27 |
|
| 28 |
.. autofunction:: word |
| 29 |
.. autofunction:: words |
| 30 |
.. autofunction:: lemmas |
| 31 |
.. autofunction:: sense |
| 32 |
.. autofunction:: senses |
| 33 |
.. autofunction:: synset |
| 34 |
.. autofunction:: synsets |
| 35 |
.. autofunction:: lexicons |
| 36 |
|
| 37 |
|
| 38 |
The Wordnet Class |
| 39 |
----------------- |
| 40 |
|
| 41 |
.. autoclass:: Wordnet |
| 42 |
|
| 43 |
.. automethod:: word |
| 44 |
.. automethod:: words |
| 45 |
.. automethod:: lemmas |
| 46 |
.. automethod:: sense |
| 47 |
.. automethod:: senses |
| 48 |
.. automethod:: synset |
| 49 |
.. automethod:: synsets |
| 50 |
.. automethod:: lexicons |
| 51 |
.. automethod:: expanded_lexicons |
| 52 |
.. automethod:: describe |
| 53 |
|
| 54 |
|
| 55 |
Words, Senses, and Synsets |
| 56 |
-------------------------- |
| 57 |
|
| 58 |
The results of primary queries against a lexicon are :class:`Word`, |
| 59 |
:class:`Sense`, or :class:`Synset` objects. See |
| 60 |
:doc:`../guides/wordnet` for more information about the concepts these |
| 61 |
object represent. |
| 62 |
|
| 63 |
Word Objects |
| 64 |
'''''''''''' |
| 65 |
|
| 66 |
.. class:: Word |
| 67 |
|
| 68 |
:class:`Word` (or "lexical entry") objects encode information about |
| 69 |
word forms independent from their meaning. |
| 70 |
|
| 71 |
.. autoattribute:: id |
| 72 |
|
| 73 |
The identifier used within a lexicon. |
| 74 |
|
| 75 |
.. autoattribute:: pos |
| 76 |
|
| 77 |
The part of speech of the Word. |
| 78 |
|
| 79 |
.. automethod:: lemma |
| 80 |
.. automethod:: forms |
| 81 |
.. automethod:: senses |
| 82 |
.. automethod:: synsets |
| 83 |
.. automethod:: lexicon |
| 84 |
.. automethod:: metadata |
| 85 |
.. automethod:: confidence |
| 86 |
.. automethod:: derived_words |
| 87 |
.. automethod:: translate |
| 88 |
|
| 89 |
|
| 90 |
Sense Objects |
| 91 |
''''''''''''' |
| 92 |
|
| 93 |
.. class:: Sense |
| 94 |
|
| 95 |
:class:`Sense` objects represent a pairing of a :class:`Word` and a |
| 96 |
:class:`Synset`. |
| 97 |
|
| 98 |
.. autoattribute:: id |
| 99 |
|
| 100 |
The identifier used within a lexicon. |
| 101 |
|
| 102 |
.. automethod:: word |
| 103 |
.. automethod:: synset |
| 104 |
.. automethod:: examples |
| 105 |
.. automethod:: lexicalized |
| 106 |
.. automethod:: adjposition |
| 107 |
.. automethod:: frames |
| 108 |
.. automethod:: counts |
| 109 |
.. automethod:: lexicon |
| 110 |
.. automethod:: metadata |
| 111 |
.. automethod:: confidence |
| 112 |
.. automethod:: relations |
| 113 |
.. automethod:: synset_relations |
| 114 |
.. automethod:: get_related |
| 115 |
.. automethod:: get_related_synsets |
| 116 |
.. automethod:: closure |
| 117 |
.. automethod:: relation_paths |
| 118 |
.. automethod:: translate |
| 119 |
|
| 120 |
|
| 121 |
Synset Objects |
| 122 |
'''''''''''''' |
| 123 |
|
| 124 |
.. class:: Synset |
| 125 |
|
| 126 |
:class:`Synset` objects represent a set of words that share a |
| 127 |
meaning. |
| 128 |
|
| 129 |
.. autoattribute:: id |
| 130 |
|
| 131 |
The identifier used within a lexicon. |
| 132 |
|
| 133 |
.. autoattribute:: pos |
| 134 |
|
| 135 |
The part of speech of the Synset. |
| 136 |
|
| 137 |
.. autoproperty:: ili |
| 138 |
|
| 139 |
The interlingual index of the Synset. |
| 140 |
|
| 141 |
.. automethod:: definition |
| 142 |
.. automethod:: definitions |
| 143 |
.. automethod:: examples |
| 144 |
.. automethod:: senses |
| 145 |
.. automethod:: lexicalized |
| 146 |
.. automethod:: lexfile |
| 147 |
.. automethod:: lexicon |
| 148 |
.. automethod:: metadata |
| 149 |
.. automethod:: confidence |
| 150 |
.. automethod:: words |
| 151 |
.. automethod:: lemmas |
| 152 |
.. automethod:: hypernyms |
| 153 |
.. automethod:: hyponyms |
| 154 |
.. automethod:: holonyms |
| 155 |
.. automethod:: meronyms |
| 156 |
.. automethod:: relations |
| 157 |
.. automethod:: get_related |
| 158 |
.. automethod:: closure |
| 159 |
.. automethod:: relation_paths |
| 160 |
.. automethod:: translate |
| 161 |
|
| 162 |
.. The taxonomy methods below have been moved to wn.taxonomy |
| 163 |
|
| 164 |
.. method:: hypernym_paths(simulate_root=False) |
| 165 |
|
| 166 |
Shortcut for :func:`wn.taxonomy.hypernym_paths`. |
| 167 |
|
| 168 |
.. method:: min_depth(simulate_root=False) |
| 169 |
|
| 170 |
Shortcut for :func:`wn.taxonomy.min_depth`. |
| 171 |
|
| 172 |
.. method:: max_depth(simulate_root=False) |
| 173 |
|
| 174 |
Shortcut for :func:`wn.taxonomy.max_depth`. |
| 175 |
|
| 176 |
.. method:: shortest_path(other, simulate_root=False) |
| 177 |
|
| 178 |
Shortcut for :func:`wn.taxonomy.shortest_path`. |
| 179 |
|
| 180 |
.. method:: common_hypernyms(other, simulate_root=False) |
| 181 |
|
| 182 |
Shortcut for :func:`wn.taxonomy.common_hypernyms`. |
| 183 |
|
| 184 |
.. method:: lowest_common_hypernyms(other, simulate_root=False) |
| 185 |
|
| 186 |
Shortcut for :func:`wn.taxonomy.lowest_common_hypernyms`. |
| 187 |
|
| 188 |
|
| 189 |
Relations |
| 190 |
--------- |
| 191 |
|
| 192 |
The :meth:`Sense.relation_map` and :meth:`Synset.relation_map` methods |
| 193 |
return a dictionary mapping :class:`Relation` objects to resolved |
| 194 |
target senses or synsets. They differ from :meth:`Sense.relations` |
| 195 |
and :meth:`Synset.relations` in two main ways: |
| 196 |
|
| 197 |
1. Relation objects map 1-to-1 to their targets instead of to a list |
| 198 |
of targets sharing the same relation name. |
| 199 |
2. Relation objects encode not just relation names, but also the |
| 200 |
identifiers of sources and targets, the lexicons they came from, and |
| 201 |
any metadata they have. |
| 202 |
|
| 203 |
One reason why :class:`Relation` objects are useful is for inspecting |
| 204 |
relation metadata, particularly in order to distinguish ``other`` |
| 205 |
relations that differ only by the value of their ``dc:type`` metadata: |
| 206 |
|
| 207 |
>>> oewn = wn.Wordnet('oewn:2024') |
| 208 |
>>> alloy = oewn.senses("alloy", pos="v")[0] |
| 209 |
>>> alloy.relations() # appears to only have one 'other' relation |
| 210 |
{'derivation': [Sense('oewn-alloy__1.27.00..')], 'other': [Sense('oewn-alloy__1.27.00..')]} |
| 211 |
>>> for rel in alloy.relation_map(): # but in fact there are two |
| 212 |
... print(rel, rel.subtype) |
| 213 |
... |
| 214 |
Relation('derivation', 'oewn-alloy__2.30.00..', 'oewn-alloy__1.27.00..') None |
| 215 |
Relation('other', 'oewn-alloy__2.30.00..', 'oewn-alloy__1.27.00..') material |
| 216 |
Relation('other', 'oewn-alloy__2.30.00..', 'oewn-alloy__1.27.00..') result |
| 217 |
|
| 218 |
Another reason why they are useful is to determine the source of a |
| 219 |
relation used in :doc:`interlingual queries <../guides/interlingual>`. |
| 220 |
|
| 221 |
>>> es = wn.Wordnet("omw-es", expand="omw-en") |
| 222 |
>>> mapa = es.synsets("mapa", pos="n")[0] |
| 223 |
>>> rel, tgt = next(iter(mapa.relation_map().items())) |
| 224 |
>>> rel, rel.lexicon() # relation comes from omw-en |
| 225 |
(Relation('hypernym', 'omw-en-03720163-n', 'omw-en-04076846-n'), <Lexicon omw-en:1.4 [en]>) |
| 226 |
>>> tgt, tgt.words(), tgt.lexicon() # target is in omw-es |
| 227 |
(Synset('omw-es-04076846-n'), [Word('omw-es-representación-n')], <Lexicon omw-es:1.4 [es]>) |
| 228 |
|
| 229 |
.. class:: Relation |
| 230 |
|
| 231 |
:class:`Relation` objects model relations between senses or synsets. |
| 232 |
|
| 233 |
.. attribute:: name |
| 234 |
|
| 235 |
The name of the relation. Also called the relation "type". |
| 236 |
|
| 237 |
.. attribute:: source_id |
| 238 |
|
| 239 |
The identifier of the source entity of the relation. |
| 240 |
|
| 241 |
.. attribute:: target_id |
| 242 |
|
| 243 |
The identifier of the target entity of the relation. |
| 244 |
|
| 245 |
.. autoattribute:: subtype |
| 246 |
.. automethod:: lexicon |
| 247 |
.. automethod:: metadata |
| 248 |
.. automethod:: confidence |
| 249 |
|
| 250 |
|
| 251 |
Additional Classes |
| 252 |
------------------ |
| 253 |
|
| 254 |
.. class:: Form |
| 255 |
|
| 256 |
:class:`Form` objects are returned by :meth:`Word.lemma` and |
| 257 |
:meth:`Word.forms` when the :python:`data=True` argument is used, |
| 258 |
and they make accessible several optional properties of word forms. |
| 259 |
The word form itself is available via the :attr:`value` attribute. |
| 260 |
|
| 261 |
>>> inu = wn.words('犬', lexicon='wnja')[0] |
| 262 |
>>> inu.forms(data=True)[3] |
| 263 |
Form(value='いぬ') |
| 264 |
>>> inu.forms(data=True)[3].script |
| 265 |
'hira' |
| 266 |
|
| 267 |
The :attr:`script` is often unspecified (i.e., :python:`None`) and |
| 268 |
this carries the implicit meaning that the form uses the canonical |
| 269 |
script for the word's language or wordnet, whatever it may be. |
| 270 |
|
| 271 |
.. attribute:: value |
| 272 |
|
| 273 |
The word form string. |
| 274 |
|
| 275 |
.. attribute:: id |
| 276 |
|
| 277 |
An optional form identifier used within a lexicon. These |
| 278 |
identifiers are often :python:`None`. |
| 279 |
|
| 280 |
.. attribute:: script |
| 281 |
|
| 282 |
The script of the word form. This should be an `ISO 15924 |
| 283 |
<https://en.wikipedia.org/wiki/ISO_15924>`_ code, or :python:`None`. |
| 284 |
|
| 285 |
.. method:: pronunciations |
| 286 |
|
| 287 |
Return the list of :class:`Pronunciation` objects. |
| 288 |
|
| 289 |
.. method:: tags |
| 290 |
|
| 291 |
Return the list of :class:`Tag` objects. |
| 292 |
|
| 293 |
.. automethod:: lexicon |
| 294 |
|
| 295 |
|
| 296 |
.. class:: Pronunciation |
| 297 |
|
| 298 |
:class:`Pronunciation` objects encode a text or audio |
| 299 |
representation of how a word is pronounced. They are returned by |
| 300 |
:meth:`Form.pronunciations`. |
| 301 |
|
| 302 |
.. autoattribute:: value |
| 303 |
|
| 304 |
The encoded pronunciation. |
| 305 |
|
| 306 |
.. autoattribute:: variety |
| 307 |
|
| 308 |
The language variety this pronunciation belongs to. |
| 309 |
|
| 310 |
.. autoattribute:: notation |
| 311 |
|
| 312 |
The notation used to encode the pronunciation. For example: the |
| 313 |
International Phonetic Alphabet (IPA). |
| 314 |
|
| 315 |
.. autoattribute:: phonemic |
| 316 |
|
| 317 |
:python:`True` when the encoded pronunciation is a generalized |
| 318 |
phonemic description, or :python:`False` for more precise |
| 319 |
phonetic transcriptions. |
| 320 |
|
| 321 |
.. autoattribute:: audio |
| 322 |
|
| 323 |
A URI to an associated audio file. |
| 324 |
|
| 325 |
.. automethod:: lexicon |
| 326 |
|
| 327 |
|
| 328 |
.. autoclass:: Tag |
| 329 |
|
| 330 |
:class:`Tag` objects encode categorical information about word |
| 331 |
forms. They are returned by :meth:`Form.tags`. |
| 332 |
|
| 333 |
.. autoattribute:: tag |
| 334 |
|
| 335 |
The text value of the tag. |
| 336 |
|
| 337 |
.. autoattribute:: category |
| 338 |
|
| 339 |
The category, or kind, of the tag. |
| 340 |
|
| 341 |
.. automethod:: lexicon |
| 342 |
|
| 343 |
|
| 344 |
.. autoclass:: Count |
| 345 |
|
| 346 |
:class:`Count` objects model sense counts previously computed over |
| 347 |
some corpus. They are returned by :meth:`Sense.counts`. |
| 348 |
|
| 349 |
.. autoattribute:: value |
| 350 |
|
| 351 |
The count of sense occurrences. |
| 352 |
|
| 353 |
.. automethod:: lexicon |
| 354 |
.. automethod:: metadata |
| 355 |
.. automethod:: confidence |
| 356 |
|
| 357 |
|
| 358 |
.. class:: Example |
| 359 |
|
| 360 |
:class:`Example` objects model example phrases for senses and |
| 361 |
synsets. They are returned by :meth:`Sense.examples` and |
| 362 |
:meth:`Synset.examples` when the :python:`data=True` argument is |
| 363 |
given. |
| 364 |
|
| 365 |
.. autoattribute:: text |
| 366 |
|
| 367 |
The example text. |
| 368 |
|
| 369 |
.. autoattribute:: language |
| 370 |
|
| 371 |
The language of the example. |
| 372 |
|
| 373 |
.. automethod:: lexicon |
| 374 |
.. automethod:: metadata |
| 375 |
.. automethod:: confidence |
| 376 |
|
| 377 |
|
| 378 |
.. class:: Definition |
| 379 |
|
| 380 |
:class:`Definition` objects model synset definitions. They are |
| 381 |
returned by :meth:`Synset.definition` when the :python:`data=True` |
| 382 |
argument is given. |
| 383 |
|
| 384 |
.. autoattribute:: text |
| 385 |
|
| 386 |
The example text. |
| 387 |
|
| 388 |
.. autoattribute:: language |
| 389 |
|
| 390 |
The language of the example. |
| 391 |
|
| 392 |
.. autoattribute:: source_sense_id |
| 393 |
|
| 394 |
The id of the particular sense the definition is for. |
| 395 |
|
| 396 |
.. automethod:: lexicon |
| 397 |
.. automethod:: metadata |
| 398 |
.. automethod:: confidence |
| 399 |
|
| 400 |
|
| 401 |
Interlingual Indices |
| 402 |
-------------------- |
| 403 |
|
| 404 |
As of Wn v1.0.0, see :mod:`wn.ili` classes and functions for ILIs |
| 405 |
|
| 406 |
|
| 407 |
Lexicon Objects |
| 408 |
--------------- |
| 409 |
|
| 410 |
.. class:: Lexicon |
| 411 |
|
| 412 |
Lexicon objects contain attributes and metadata about a single |
| 413 |
:doc:`lexicon <../guides/lexicons>`. |
| 414 |
|
| 415 |
.. autoattribute:: id |
| 416 |
|
| 417 |
The lexicon's identifier. |
| 418 |
|
| 419 |
.. autoattribute:: label |
| 420 |
|
| 421 |
The full name of lexicon. |
| 422 |
|
| 423 |
.. autoattribute:: language |
| 424 |
|
| 425 |
The BCP 47 language code of lexicon. |
| 426 |
|
| 427 |
.. autoattribute:: email |
| 428 |
|
| 429 |
The email address of the wordnet maintainer. |
| 430 |
|
| 431 |
.. autoattribute:: license |
| 432 |
|
| 433 |
The URL or name of the wordnet's license. |
| 434 |
|
| 435 |
.. autoattribute:: version |
| 436 |
|
| 437 |
The version string of the resource. |
| 438 |
|
| 439 |
.. autoattribute:: url |
| 440 |
|
| 441 |
The project URL of the wordnet. |
| 442 |
|
| 443 |
.. autoattribute:: citation |
| 444 |
|
| 445 |
The canonical citation for the project. |
| 446 |
|
| 447 |
.. autoattribute:: logo |
| 448 |
|
| 449 |
A URL or path to a project logo. |
| 450 |
|
| 451 |
.. automethod:: metadata |
| 452 |
.. automethod:: confidence |
| 453 |
.. automethod:: specifier |
| 454 |
.. automethod:: modified |
| 455 |
.. automethod:: requires |
| 456 |
.. automethod:: extends |
| 457 |
.. automethod:: extensions |
| 458 |
.. automethod:: describe |
| 459 |
|
| 460 |
|
| 461 |
The wn.config Object |
| 462 |
-------------------- |
| 463 |
|
| 464 |
Wn's data storage and retrieval can be configured through the |
| 465 |
:data:`wn.config` object. |
| 466 |
|
| 467 |
.. seealso:: |
| 468 |
|
| 469 |
:doc:`../setup` describes how to configure Wn using the |
| 470 |
:data:`wn.config` instance. |
| 471 |
|
| 472 |
.. autodata:: config |
| 473 |
|
| 474 |
It is an instance of the :class:`~wn._config.WNConfig` class, which is |
| 475 |
defined in a non-public module and is not meant to be instantiated |
| 476 |
directly. Configuration should occur through the single |
| 477 |
:data:`wn.config` instance. |
| 478 |
|
| 479 |
.. autoclass:: wn._config.WNConfig |
| 480 |
|
| 481 |
.. autoattribute:: data_directory |
| 482 |
.. autoattribute:: database_path |
| 483 |
.. attribute:: allow_multithreading |
| 484 |
|
| 485 |
If set to :python:`True`, the database connection may be shared |
| 486 |
across threads. In this case, it is the user's responsibility to |
| 487 |
ensure that multiple threads don't try to write to the database |
| 488 |
at the same time. The default is :python:`False`. |
| 489 |
|
| 490 |
.. autoattribute:: downloads_directory |
| 491 |
.. automethod:: add_project |
| 492 |
.. automethod:: add_project_version |
| 493 |
.. automethod:: get_project_info |
| 494 |
.. automethod:: get_cache_path |
| 495 |
.. automethod:: list_cache_entries |
| 496 |
.. automethod:: update |
| 497 |
.. automethod:: load_index |
| 498 |
|
| 499 |
|
| 500 |
Auxiliary WNConfig Types |
| 501 |
'''''''''''''''''''''''' |
| 502 |
|
| 503 |
The following classes are argument or return types of |
| 504 |
:class:`~wn._config.WNConfig` objects. They are documented here for reference, |
| 505 |
but are not meant to be created directly. |
| 506 |
|
| 507 |
.. autoclass:: wn._config.ResourceType |
| 508 |
|
| 509 |
Enumeration of resource types. |
| 510 |
|
| 511 |
.. autoattribute:: WORDNET |
| 512 |
.. autoattribute:: ILI |
| 513 |
|
| 514 |
|
| 515 |
.. autoclass:: wn._config.ProjectInfo |
| 516 |
:members: |
| 517 |
:undoc-members: |
| 518 |
|
| 519 |
Dictionary of information about a project. |
| 520 |
|
| 521 |
|
| 522 |
.. autoclass:: wn._config.VersionInfo |
| 523 |
:members: |
| 524 |
:undoc-members: |
| 525 |
|
| 526 |
Dictionary of information about a resource version. |
| 527 |
|
| 528 |
|
| 529 |
.. autoclass:: wn._config.ResolvedProjectInfo |
| 530 |
:members: |
| 531 |
:undoc-members: |
| 532 |
|
| 533 |
Dictionary of information about a specific project resource. |
| 534 |
|
| 535 |
|
| 536 |
.. autoclass:: wn._config.CacheEntry |
| 537 |
:members: |
| 538 |
:undoc-members: |
| 539 |
|
| 540 |
Dictionary of information about files in the download cache. |
| 541 |
|
| 542 |
|
| 543 |
Exceptions |
| 544 |
---------- |
| 545 |
|
| 546 |
.. autoexception:: Error |
| 547 |
.. autoexception:: DatabaseError |
| 548 |
.. autoexception:: WnWarning |