pycrossword  0.2
Pure-Python implementation of a crossword puzzle generator and editor
Public Member Functions | Public Attributes | List of all members
pycross.wordsrc.MultiWordsource Class Reference

Combined word source that stores other Wordsource-derived objects and provides the same interface for fetching the results. More...

Inheritance diagram for pycross.wordsrc.MultiWordsource:
pycross.wordsrc.Wordsource

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...
 
- Public Member Functions inherited from pycross.wordsrc.Wordsource
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...
 
- Public Attributes inherited from pycross.wordsrc.Wordsource
 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...
 

Detailed Description

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.

See also
crossword::Crossword::wordsource, gui::MainWindow::wordsrc

Constructor & Destructor Documentation

◆ __init__()

def pycross.wordsrc.MultiWordsource.__init__ (   self,
  order = 'prefer-last',
  max_fetch = None 
)

Constructor.

Parameters
orderstr indicates the preference order for individual word sources and words. Can be one of:
  • 'prefer-last' (default) implements the 'last items first' principle: new word sources will be added at the end of the source container, words will be suggested (extracted) starting from the end of the results list; OR
  • 'prefer-first' implements the 'first items first' principle: new word sources will be added at the start of the source container, words will be suggested (extracted) from the start of the results list
max_fetchint maximum number of suggestions returned from the word source
Warning
None means no limit on suggestions, which may be time/resource consuming!

Reimplemented from pycross.wordsrc.Wordsource.

Member Function Documentation

◆ __len__()

def pycross.wordsrc.MultiWordsource.__len__ (   self)

Python len() overload.

Returns
int number of word sources in MultiWordsource::sources

◆ add()

def pycross.wordsrc.MultiWordsource.add (   self,
  source,
  position = None 
)

Adds a new word source to MultiWordsource::sources.

Parameters
sourceWordsource a Wordsource-derived object - a single word source
positionint | 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

◆ check()

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.

Parameters
wordstr the word (pattern) to find, e.g. 'f ther' or 'father'
posstr | iterable | None part(s) of speech to include in the results - see fetch()
filter_funccallable filtering callback function to exclude words from results - see fetch()
Returns
bool True if the given word (pattern) can be found in the source, False otherwise

Reimplemented from pycross.wordsrc.Wordsource.

◆ clear()

def pycross.wordsrc.MultiWordsource.clear (   self)

Removes all word sources from MultiWordsource::sources.

◆ fetch()

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.

◆ isvalid()

def pycross.wordsrc.MultiWordsource.isvalid (   self)

Valid if at least one word source is valid.

Reimplemented from pycross.wordsrc.Wordsource.

◆ pop_word()

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.

Returns
str last word from the suggestions or None if the suggestions list is empty

Reimplemented from pycross.wordsrc.Wordsource.

◆ remove()

def pycross.wordsrc.MultiWordsource.remove (   self,
  index 
)

Removes a single word source from MultiWordsource::sources.

Parameters
indexint the position index of the word source to remove

◆ truncate()

def pycross.wordsrc.MultiWordsource.truncate (   self,
  suggestions 
)

Truncates the results by the threshold number stored in Wordsource::max_fetch.

Parameters
suggestionslist list of suggested words str
Returns
list truncated list of suggested words or the original list if Wordsource::max_fetch is None

Reimplemented from pycross.wordsrc.Wordsource.

Member Data Documentation

◆ order

pycross.wordsrc.MultiWordsource.order

str the preference order for individual word sources and words

◆ sources

pycross.wordsrc.MultiWordsource.sources

list container for Wordsource objects (word sources)


The documentation for this class was generated from the following file: