marisa-trie README

The project's README from github.com/pytries/marisa-trie. As one markdown file: README.md.

MARISA Trie

|PyPI Version| |PyPI Status| |PyPI Python Versions| |Github Build Status|

.. tip::

Become **my boss** to help me work on this awesome software, and make the world better:

|Patreon|

Static memory-efficient Trie-like structures for Python (3.9+) based on marisa-trie_ C++ library.

String data in a MARISA-trie may take up to 50x-100x less memory than in a standard Python dict; the raw lookup speed is comparable; trie also provides fast advanced methods like prefix search.

.. note::

There are official SWIG-based Python bindings included
in C++ library distribution; this package provides alternative
Cython-based pip-installable Python bindings.

.. _marisa-trie: https://github.com/s-yata/marisa-trie

Installation

::

python -m pip install -U marisa-trie

Usage

See tutorial_ and API_ for details.

For immutable str -> str mappings, use marisa_trie.StringTrie (implemented as two internal tries plus a compact ID mapping table).

.. _tutorial: https://marisa-trie.readthedocs.io/en/latest/tutorial.html .. _API: https://marisa-trie.readthedocs.io/en/latest/api.html

Current limitations

License

Wrapper code is licensed under MIT License.

Bundled marisa-trie_ C++ library is dual-licensed under LGPL or BSD 2-clause license.

.. |PyPI Version| image:: https://img.shields.io/pypi/v/marisa-trie.svg :target: https://pypi.python.org/pypi/marisa-trie/ .. |PyPI Status| image:: https://img.shields.io/pypi/status/marisa-trie.svg :target: https://pypi.python.org/pypi/marisa-trie/ .. |PyPI Python Versions| image:: https://img.shields.io/pypi/pyversions/marisa-trie.svg :target: https://pypi.python.org/pypi/marisa-trie/ .. |Github Build Status| image:: https://github.com/pytries/marisa-trie/actions/workflows/tests.yml/badge.svg :target: https://github.com/pytries/marisa-trie/actions/workflows/tests.yml .. |Patreon| image:: https://img.shields.io/badge/Patreon-F96854?style=for-the-badge&logo=patreon&logoColor=white :target: https://www.patreon.com/mschoentgen

marisa-trie (pytries/marisa-trie)

Searching Database…

Что это такое?Статические экономные по памяти структуры данных, похожие на префиксные деревья (trie), для Python, построенные на основе C++-библиотеки marisa-trie. Строки, которые в них хранятся, занимают в 50–100 раз меньше памяти, чем в обычном словаре Python, при сопоставимой скорости поиска и быстром поиске по префиксу.
Это библиотека, которую я добавляю в свой Python-проект, или отдельный инструмент?Это библиотека, которая ставится через pip и импортируется в Python-код. Она предоставляет привязки на основе Cython как альтернативу официальным привязкам на SWIG, которые идут в поставке C++-библиотеки.
Какие версии Python она поддерживает?Python 3.9 или новее; в темах на GitHub также заявлена поддержка PyPy3.
Какие у неё сейчас есть ограничения?read() и write() работают только с настоящими файлами, а не с файлоподобными объектами — в таких случаях используйте pickle. Метод .prefixes() у BytesTrie и RecordTrie довольно медленный, и аналога через итератор у него нет; у классов trie есть методы keys() и items(), но нет values(). Сборки под Mingw32 тоже не тестировались.
С лицензией всё просто, если я хочу использовать её в коммерческом проекте?В основном да: код-обёртка распространяется по лицензии MIT, но входящая в комплект C++-библиотека marisa-trie имеет двойную лицензию — LGPL или BSD 2-clause, поэтому при распространении C++-части проверьте условия LGPL.
Какие виды trie-структур есть в этом пакете?Основной документированный класс — StringTrie, для неизменяемых отображений строк в строки (str-to-str); внутри он устроен как два trie плюс компактная таблица сопоставления с идентификаторами. Также доступны классы Trie, BytesTrie и RecordTrie.
Структуры называются «статическими» — это значит, что они только для чтения?Да — trie строится один раз, а дальше вы только обращаетесь к ней с запросами. StringTrie явно предназначена для неизменяемых отображений строк в строки, то есть возможность обновления обменивается на компактный расход памяти и быстрый поиск.
Что такое MARISA?Это C++-библиотека, на которой основан этот пакет: marisa-trie реализует сами компактные trie-структуры и организацию памяти, а этот репозиторий добавляет к ней Python-привязки на основе Cython и публикует их на PyPI.
Creator
pytries
Size
3.2 MB
Stars
1.1K
Age
14y
Commits · 90 Days