File: setup.rst

package info (click to toggle)
python-wn 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,100 kB
  • sloc: python: 8,429; xml: 566; sql: 238; makefile: 12
file content (129 lines) | stat: -rw-r--r-- 4,242 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
Installation and Configuration
==============================

.. seealso::

   This guide is for installing and configuring the Wn software. For
   adding lexicons to the database, see :doc:`guides/lexicons`.


Installing from PyPI
--------------------

Install the latest release from `PyPI <https://pypi.org/project/wn>`_:

.. code-block:: bash

   pip install wn


The Data Directory
------------------

By default, Wn stores its data (such as downloaded LMF files and the
database file) in a ``.wn_data/`` directory under the user's home
directory. This directory can be changed (see `Configuration`_
below). Whenever Wn attempts to download a resource or access its
database, it will check for the existence of, and create if necessary,
this directory, the ``.wn_data/downloads/`` subdirectory, and the
``.wn_data/wn.db`` database file. The file system will look like
this::

    .wn_data/
    ├── downloads
    │   ├── ...
    │   └── ...
    └── wn.db

The ``...`` entries in the ``downloads/`` subdirectory represent the
files of resources downloaded from the web. Their filename is a hash
of the URL so that Wn can avoid downloading the same file twice.


Configuration
-------------

The :py:data:`wn.config` object contains the paths Wn uses for local
storage and information about resources available on the web. To
change the directory Wn uses for storing data locally, modify the
:python:`wn.config.data_directory` member:

.. code-block:: python

   import wn
   wn.config.data_directory = '~/Projects/wn_data'

There are some things to note:

- The downloads directory and database path are always relative to the
  data directory and cannot be changed directly.
- This change only affects subsequent operations, so any data in the
  previous location will not be moved nor deleted.
- This change only affects the current session. If you want a script
  or application to always use the new location, it must reset the
  data directory each time it is initialized.

You can also add project information for remote resources. First you
add a project, with a project ID, full name, and language code. Then
you create one or more versions for that project with a version ID,
resource URL, and license information. This may be done either through
the :py:data:`wn.config` object's
:py:meth:`~wn._config.WNConfig.add_project` and
:py:meth:`~wn._config.WNConfig.add_project_version` methods, or loaded
from a TOML_ file via the :py:data:`wn.config` object's
:py:meth:`~wn._config.WNConfig.load_index` method.

.. _TOML: https://toml.io

.. code-block:: python

   wn.config.add_project('ewn', 'English WordNet', 'en')
   wn.config.add_project_version(
       'ewn', '2020',
       'https://en-word.net/static/english-wordnet-2020.xml.gz',
       'https://creativecommons.org/licenses/by/4.0/',
   )


Rebuilding the Database
-----------------------

New versions of Wn may occasionally alter the database schema in a way
that makes an existing database incompatible with the code. You will
see an error like this (abbreviated):

>>> import wn
>>> wn.Wordnet("oewn:2024")
Traceback (most recent call last):
  [...]
wn.DatabaseError: Wn's schema has changed and is no longer compatible with the database.
Lexicons currently installed:
  odenet:1.4
  oewn:2023
  oewn:2024
  omw-arb:1.4
  [...]]
Run wn.reset_database(rebuild=True) to rebuild the database.

You can then run, as directed, :func:`wn.reset_database` with
``rebuild=True``, which will delete the database, initialize a new one,
and attempt to add all the lexicons that were previously added. You can
also run with ``rebuild=False`` to reinitialize the database without
re-adding lexicons, or alternatively simply delete the database file
from your filesystem. See the documentation for
:func:`wn.reset_database` for more information.


Installing From Source
----------------------

If you wish to install the code from the source repository (e.g., to
get an unreleased feature or to contribute toward Wn's development),
clone the repository and use `Hatch <https://hatch.pypa.io/>`_ to
start a virtual environment with Wn installed:

.. code-block:: console

   $ git clone https://github.com/goodmami/wn.git
   $ cd wn
   $ hatch shell