pycrossword
0.2
Pure-Python implementation of a crossword puzzle generator and editor
|
Combined word source that stores other Wordsource-derived objects and provides the same interface for fetching the results. More...
Public Member Functions | |
def | __init__ (self, order='prefer-last', max_fetch=None) |
Constructor. More... | |
def | isvalid (self) |
Valid if at least one word source is valid. More... | |
def | add (self, source, position=None) |
Adds a new word source to MultiWordsource::sources. More... | |
def | clear (self) |
Removes all word sources from MultiWordsource::sources. More... | |
def | remove (self, index) |
Removes a single word source from MultiWordsource::sources. 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 | truncate (self, suggestions) |
Truncates the results by the threshold number stored in Wordsource::max_fetch. More... | |
def | fetch (self, word=None, blank=' ', pos=None, filter_func=None, shuffle=True, truncate=True) |
Fetches results from all the word sources and combines them into one list of words. 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 | __len__ (self) |
Python len() overload. More... | |
![]() | |
def | shuffle (self, suggestions) |
Shuffles the results randomly. More... | |
def | __repr__ (self) |
Python repr() overload. More... | |
def | __bool__ (self) |
Python bool() overload. More... | |
Public Attributes | |
order | |
str the preference order for individual word sources and words More... | |
sources | |
list container for Wordsource objects (word sources) More... | |
![]() | |
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... | |
Combined word source that stores other Wordsource-derived objects and provides the same interface for fetching the results.
The individual word sources are treated as one single word source when retrieving / truncating and extracting suggested words, but each source can be shuffled individually, and toggled 'on' and 'off' using their current Wordsource::active values. Being flexible, this is the default implementation for the crossword word source.
def pycross.wordsrc.MultiWordsource.__init__ | ( | self, | |
order = 'prefer-last' , |
|||
max_fetch = None |
|||
) |
Constructor.
order | str indicates the preference order for individual word sources and words. Can be one of:
|
max_fetch | int maximum number of suggestions returned from the word source |
None
means no limit on suggestions, which may be time/resource consuming! Reimplemented from pycross.wordsrc.Wordsource.
def pycross.wordsrc.MultiWordsource.__len__ | ( | self | ) |
Python len()
overload.
int
number of word sources in MultiWordsource::sources def pycross.wordsrc.MultiWordsource.add | ( | self, | |
source, | |||
position = None |
|||
) |
Adds a new word source to MultiWordsource::sources.
source | Wordsource a Wordsource-derived object - a single word source |
position | int | None position index in MultiWordsource::sources to add the word source to; if None (default) the index will depend on the value of MultiWordsource::order |
def pycross.wordsrc.MultiWordsource.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 from pycross.wordsrc.Wordsource.
def pycross.wordsrc.MultiWordsource.clear | ( | self | ) |
Removes all word sources from MultiWordsource::sources.
def pycross.wordsrc.MultiWordsource.fetch | ( | self, | |
word = None , |
|||
blank = ' ' , |
|||
pos = None , |
|||
filter_func = None , |
|||
shuffle = True , |
|||
truncate = True |
|||
) |
Fetches results from all the word sources and combines them into one list of words.
Reimplemented from pycross.wordsrc.Wordsource.
def pycross.wordsrc.MultiWordsource.isvalid | ( | self | ) |
Valid if at least one word source is valid.
Reimplemented from pycross.wordsrc.Wordsource.
def pycross.wordsrc.MultiWordsource.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 from pycross.wordsrc.Wordsource.
def pycross.wordsrc.MultiWordsource.remove | ( | self, | |
index | |||
) |
Removes a single word source from MultiWordsource::sources.
index | int the position index of the word source to remove |
def pycross.wordsrc.MultiWordsource.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 from pycross.wordsrc.Wordsource.
pycross.wordsrc.MultiWordsource.order |
str
the preference order for individual word sources and words
pycross.wordsrc.MultiWordsource.sources |
list
container for Wordsource objects (word sources)