Easy word filtering and searching from a custom set of words
Project description
# Wordplay
[![Build Status](https://travis-ci.org/enioluwa23/wordplay.svg?branch=master)](https://travis-ci.org/enioluwa23/wordplay) [![PyPI version](https://img.shields.io/pypi/v/wordplay.svg)](https://pypi.org/project/wordplay/) [![Supported versions](https://img.shields.io/pypi/wheel/wordplay.svg)](https://pypi.org/project/wordplay/) [![PyPI version](https://img.shields.io/pypi/pyversions/wordplay.svg)](https://pypi.org/project/wordplay/)
Python package for word searching utilities.
Using a convenient API, you can filter a set of strings with detailed criteria. There are also more scrabble-like features such as getting all anagrams of a word.
## Install
```bash
pip install wordplay
```
## Background
I initially built this as an algorithm solely to help my endeavors in word games such as Scrabble. It was useful for finding word combinations in every type of situation. However, I realized it could be used for many other purposes, such as filtering email addresses, phone numbers and any set of data really. So I decided to decouple the API from my personal use.
## Usage
Words are stored in a `Dictionary` object. Initialize the dictionary with a [`set`](https://docs.python.org/2/library/stdtypes.html#set) of strings (there are no restrictions on what the string can contain) or `Dictionary()` with no arguments to use the word set sourced from [here](https://github.com/dwyl/english-words). In the future, I will amass a couple of word lists and make them options for initializing the dictionary.
If you do want restrictions on the string, see the documentation for the [`Utils`](https://enioluwa23.github.io/wordplay/api/utils/) module. For complex query parameters, you can use a `Criteria` object. The class uses the builder pattern, making it easy to construct search parameters.
Here is a an example file:
```python
from __future__ import print_function
from wordplay.dictionary import Dictionary
from wordplay.criteria import Criteria
def main():
dictionary = Dictionary()
result = dictionary.get_words_with_any_letters('diction', 6)
print(result)
# ['diotic', 'dition', 'indico', 'indict', 'nidiot', 'odinic']
result = dictionary.get_words_with_any_letters('pox')
print(result)
# ['o', 'op', 'ox', 'p', 'po', 'pox', 'x']
result = dictionary.get_anagrams('aekst')
print(result)
# ['keats', 'skate', 'skeat', 'stake', 'steak', 'takes', 'teaks']
print('car' in dictionary) # Dictionary is directly iterable
# True
criteria = Criteria()
criteria.begins_with('c').ends_with('s').contains('or')
criteria.contains_at(('o', 2), ('r', 4)).size_is(10)
result = dictionary.get_words(criteria)
print(result)
# ['corrosives', 'correlates', 'corrugates']
if __name__ == '__main__':
main()
```
For further example usage see the [Documentation](https://enioluwa23.github.io/wordplay/).
To run tests, use `pytest`.
## Documentation
[API Reference](https://enioluwa23.github.io/wordplay/)
## License
[Apache Software License](https://github.com/enioluwa23/wordplay/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/enioluwa23/wordplay.svg?branch=master)](https://travis-ci.org/enioluwa23/wordplay) [![PyPI version](https://img.shields.io/pypi/v/wordplay.svg)](https://pypi.org/project/wordplay/) [![Supported versions](https://img.shields.io/pypi/wheel/wordplay.svg)](https://pypi.org/project/wordplay/) [![PyPI version](https://img.shields.io/pypi/pyversions/wordplay.svg)](https://pypi.org/project/wordplay/)
Python package for word searching utilities.
Using a convenient API, you can filter a set of strings with detailed criteria. There are also more scrabble-like features such as getting all anagrams of a word.
## Install
```bash
pip install wordplay
```
## Background
I initially built this as an algorithm solely to help my endeavors in word games such as Scrabble. It was useful for finding word combinations in every type of situation. However, I realized it could be used for many other purposes, such as filtering email addresses, phone numbers and any set of data really. So I decided to decouple the API from my personal use.
## Usage
Words are stored in a `Dictionary` object. Initialize the dictionary with a [`set`](https://docs.python.org/2/library/stdtypes.html#set) of strings (there are no restrictions on what the string can contain) or `Dictionary()` with no arguments to use the word set sourced from [here](https://github.com/dwyl/english-words). In the future, I will amass a couple of word lists and make them options for initializing the dictionary.
If you do want restrictions on the string, see the documentation for the [`Utils`](https://enioluwa23.github.io/wordplay/api/utils/) module. For complex query parameters, you can use a `Criteria` object. The class uses the builder pattern, making it easy to construct search parameters.
Here is a an example file:
```python
from __future__ import print_function
from wordplay.dictionary import Dictionary
from wordplay.criteria import Criteria
def main():
dictionary = Dictionary()
result = dictionary.get_words_with_any_letters('diction', 6)
print(result)
# ['diotic', 'dition', 'indico', 'indict', 'nidiot', 'odinic']
result = dictionary.get_words_with_any_letters('pox')
print(result)
# ['o', 'op', 'ox', 'p', 'po', 'pox', 'x']
result = dictionary.get_anagrams('aekst')
print(result)
# ['keats', 'skate', 'skeat', 'stake', 'steak', 'takes', 'teaks']
print('car' in dictionary) # Dictionary is directly iterable
# True
criteria = Criteria()
criteria.begins_with('c').ends_with('s').contains('or')
criteria.contains_at(('o', 2), ('r', 4)).size_is(10)
result = dictionary.get_words(criteria)
print(result)
# ['corrosives', 'correlates', 'corrugates']
if __name__ == '__main__':
main()
```
For further example usage see the [Documentation](https://enioluwa23.github.io/wordplay/).
To run tests, use `pytest`.
## Documentation
[API Reference](https://enioluwa23.github.io/wordplay/)
## License
[Apache Software License](https://github.com/enioluwa23/wordplay/blob/master/LICENSE)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for wordplay-1.0.0a3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aed16493606acc8d229d3f0935faa9d812eef77b3601918ade6b859e90356c6f |
|
MD5 | 5885eecc6ff01c0e3c131255a75a5fb1 |
|
BLAKE2b-256 | b524b9565ab407c9e9c3d778d2c1ae7c5159b833b508bdc303435e3d164924e1 |