Giter Site home page Giter Site logo

enioluwas / wordplay Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 1.0 3.96 MB

Python package for easy filtering and searching of word sets.

Home Page: https://enioluwa23.github.io/wordplay/

License: Apache License 2.0

Python 100.00%
python2 python3 pypi search filter scrabble

wordplay's Introduction

Wordplay

Build Status PyPI version Supported versions PyPI version

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

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 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. 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 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:

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.

To run tests, use pytest.

Documentation

API Reference

License

Apache Software License

wordplay's People

Contributors

enioluwas avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ndeoligence

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.