Skip to main content

A trie filled with words from several languages (English - en, German - de , French - fr, Spanish - es, Portuguese - pt)

Project description

WordTriePy

This is a small Python package that implements a trie filled with words from several languages (English - en, German - de , French - fr, Spanish - es, Portuguese - pt) implemented as nested dictionaries.

Install

pip install wordtriepy

Usage

To find all characters that could follow the partial word "chair" in the English language, use the get_next_chars() method:

from wordtriepy import WordTrie

t = WordTrie()
print(t.get_next_chars("chair"))
# outputs: ['_end', 'b', 'e', '-', 'i', 'l', 'm', 'p', 's', 'w']

The _end token tells us that "chair" itself is a valid word and there are 4 other characters ('b', 'e', '-', 'i', 'l', 'm', 'p', 's', 'w') that could follow the word "chair" in the English language that could form new valid words.

To get a list of words that can be formed by the partial word "salz" in the German language, use the get_next_words() method:

from wordtriepy import WordTrie

t = WordTrie(language="de")
print(t.get_next_words("salz", topn=5))
# outputs: ['salz', 'salze', 'salzt', 'salzen', 'salzes']

This returns the top 5 words after a breadth-first-search in the German word trie.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wordtriepy-0.0.3.tar.gz (6.8 MB view hashes)

Uploaded Source

Built Distribution

wordtriepy-0.0.3-py3-none-any.whl (7.6 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page