Skip to content

Commit

Permalink
doc: custom categories in README.md and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmaxguns committed Apr 11, 2024
1 parent fc5791c commit 1678716
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,34 @@ s.bare_bone_with_adjective()
s.sentence()
```

Words are organized in categories, such as "nouns", "verbs", and "adjectives".
What if you had your own categories of words? You can specify your custom
categories when instantiating the `RandomWord` class:

```python
from wonderwords import RandomWord

cars = ["Chevrolet", "Subaru", "Tesla"]
airplanes = ["Boeing", "Airbus", "Cessna"]
w = RandomWord(cars=cars, airplanes=airplanes)

# Will return a random car or airplane
w.word()

# Will return a random car
w.word(include_categories=["cars"])

# You can also mix and match custom categories with defaults
from wonderwords import Defaults
proper_nouns = ["Austin", "Seattle", "New York"]
w2 = RandomWord(proper_nouns=proper_nouns, common_nouns=Defaults.NOUNS)

# Will return either Seattle or seat
w.word(regex="[Ss]eat.*")
```

Finally, starting with version 2.3, Wonderwords has explicit support for filtering
out profanities form lists of words. At the moment, this is rudimentary:
out profanities from lists of words. At the moment, this is rudimentary:

```python
from wonderwords import is_profanity, filter_profanity
Expand Down
6 changes: 6 additions & 0 deletions tests/test_random_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,9 @@ def test_custom_category_with_defaults(self):
"""Test a custom category using default values"""
gen = RandomWord(my_verb=Defaults.VERBS)
assert gen.word(starts_with="ab") == "abide"

def test_custom_category_with_mixing(self):
"""Test custom categories mixed with default categories."""
proper_nouns = ["Austin", "Seattle", "New York"]
gen = RandomWord(proper_nouns=proper_nouns, common_nouns=Defaults.NOUNS)
assert set(gen.filter(regex="[Ss]eat.*")) == {"Seattle", "seat"}

0 comments on commit 1678716

Please sign in to comment.