pycrossword
0.3
Pure-Python implementation of a crossword puzzle generator and editor
|
Base class for word source objects. More...
Public Member Functions | |
def | __init__ (self, max_fetch=None, shuffle=True) |
Constructor. More... | |
def | isvalid (self) |
Checks if it is a valid word source. More... | |
def | truncate (self, suggestions) |
Truncates the results by the threshold number stored in Wordsource::max_fetch. More... | |
def | shuffle (self, suggestions) |
Shuffles the results randomly. More... | |
def | fetch (self, word=None, blank=' ', pos=None, filter_func=None, shuffle=True, truncate=True) |
Fetches suggestions (as a list of strings) for a given word pattern (mask). More... | |
def | check (self, word, pos=None, filter_func=None) |
Checks if a given word or word pattern is found in the word source. More... | |
def | pop_word (self, suggestions) |
Retrieves the last suggestion (word) from the list of suggestions, removing that word from the original results. More... | |
def | __repr__ (self) |
Python repr() overload. More... | |
def | __bool__ (self) |
Python bool() overload. More... | |
Public Attributes | |
max_fetch | |
int maximum number of suggestions returned from the word source More... | |
shuffle_words | |
bool if True , fetched words will be shuffled More... | |
active | |
bool if True , this word source will be used; otherwise it will be ignored More... | |
Base class for word source objects.
Provides core methods for fetching, shuffling, truncating the results and other bare-bones stuff.
def pycross.wordsrc.Wordsource.__init__ | ( | self, | |
max_fetch = None , |
|||
shuffle = True |
|||
) |
Constructor.
max_fetch | int maximum number of suggestions returned from the word source (None means no limit on suggestions, which may be time/resource consuming!) |
shuffle | bool if True , fetched words will be shuffled |
Reimplemented in pycross.wordsrc.MultiWordsource.
def pycross.wordsrc.Wordsource.__bool__ | ( | self | ) |
Python bool()
overload.
bool
the result of isvalid() def pycross.wordsrc.Wordsource.__repr__ | ( | self | ) |
Python repr()
overload.
str
human-readable representation of Wordsource object def pycross.wordsrc.Wordsource.check | ( | self, | |
word, | |||
pos = None , |
|||
filter_func = None |
|||
) |
Checks if a given word or word pattern is found in the word source.
word | str the word (pattern) to find, e.g. 'f ther' or 'father' |
pos | str | iterable | None part(s) of speech to include in the results - see fetch() |
filter_func | callable filtering callback function to exclude words from results - see fetch() |
bool
True
if the given word (pattern) can be found in the source, False
otherwise Reimplemented in pycross.wordsrc.MultiWordsource.
def pycross.wordsrc.Wordsource.fetch | ( | self, | |
word = None , |
|||
blank = ' ' , |
|||
pos = None , |
|||
filter_func = None , |
|||
shuffle = True , |
|||
truncate = True |
|||
) |
Fetches suggestions (as a list
of strings) for a given word pattern (mask).
word | str | None the word pattern to find suggestions for, e.g. 'f th ' |
blank | str placeholder character for unknown (blank) letters (default = whitespace) |
pos | str | iterable | None part(s) of speech to include in the results:
|
filter_func | callable filtering callback function to exclude words from results. Prototype is: filter_func(word: str) -> bool
True to include the word). If None (default), no filtering will be performed. |
shuffle | bool True (default) to shuffle the results randomly |
truncate | bool True (default) to truncate the results by Wordsource::max_fetch |
list
list of strings - the words matching the given pattern Reimplemented in pycross.wordsrc.MultiWordsource, pycross.wordsrc.TextWordsource, and pycross.wordsrc.DBWordsource.
def pycross.wordsrc.Wordsource.isvalid | ( | self | ) |
Checks if it is a valid word source.
bool
True
if valid, False
if not valid Reimplemented in pycross.wordsrc.MultiWordsource, pycross.wordsrc.TextWordsource, and pycross.wordsrc.DBWordsource.
def pycross.wordsrc.Wordsource.pop_word | ( | self, | |
suggestions | |||
) |
Retrieves the last suggestion (word) from the list of suggestions, removing that word from the original results.
str
last word from the suggestions or None if the suggestions list is empty Reimplemented in pycross.wordsrc.MultiWordsource.
def pycross.wordsrc.Wordsource.shuffle | ( | self, | |
suggestions | |||
) |
Shuffles the results randomly.
suggestions | list list of suggested words str |
list
randomly shuffled list of suggested words or the original list if Wordsource::shuffle_words == False
def pycross.wordsrc.Wordsource.truncate | ( | self, | |
suggestions | |||
) |
Truncates the results by the threshold number stored in Wordsource::max_fetch.
suggestions | list list of suggested words str |
list
truncated list of suggested words or the original list if Wordsource::max_fetch is None
Reimplemented in pycross.wordsrc.MultiWordsource.
pycross.wordsrc.Wordsource.active |
bool
if True
, this word source will be used; otherwise it will be ignored
pycross.wordsrc.Wordsource.max_fetch |
int
maximum number of suggestions returned from the word source
pycross.wordsrc.Wordsource.shuffle_words |
bool
if True
, fetched words will be shuffled