tipy :: prdct :: PredictorActivator :: Class PredictorActivator
[hide private]
[frames] | no frames]

Class PredictorActivator

source code

object --+
         |
        PredictorActivator

Query the predictors listed in the registry to get their suggestions.

This class has access to a PredictorRegistry and asks the predictors listed in this PredictorRegistry to call their predict() method, store the resulting Prediction instances, merge them into a single Prediction instance and return it.

Class Hierarchy for PredictorActivator
Class Hierarchy for PredictorActivator

Instance Methods [hide private]
 
__init__(self, config, predictorRegistry)
PredictorActivator creator.
source code
 
pred_worker(self, predictor, queue, factor)
Worker function for the predictor predict() methods.
source code
Prediction
predict(self, factor=1)
Build a list of every predicted words.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, config, predictorRegistry)
(Constructor)

source code 

PredictorActivator creator.

Parameters:
  • config (drvr.Configuration) - The configuration dictionary is used in order to retrieve the PredictorActivator settings from the config file.
  • predictorRegistry (PredictorRegistry) - The class needs to access the PredictorRegistry to call their predict() method.
Overrides: object.__init__

pred_worker(self, predictor, queue, factor)

source code 

Worker function for the predictor predict() methods.

This method is used as the predictors workers target. It push the predictor's prdct.Predictor.predict method result (a Prediction instance) in a queue (which is used because it is thread-safe).

Parameters:
  • predictor (Predictor based class.) - The Predictor based class instance.
  • queue (multiprocessing.Queue) - A queue in which the result will be pushed.
  • factor (int) - A factor used to increase the number of suggestions.

predict(self, factor=1)

source code 

Build a list of every predicted words.

Call the predict() method of every predictors in the registry then merge their Prediction into a single Prediction instance.

Parameters:
  • factor (int) - A factor used to increase the number of suggestions.
Returns: Prediction
The merged Prediction instance containing every suggestions of every Prediction instances sorted in descending order according to their probabilities.

Change Log:

  • 16/06/15: The method now uses multi-processing. It concurrently runs every predictors's predict() method which allow a significant speed augmentation. The queue is used because it is thread safe. The point is that when the threads args are passed to the PredictorActivator.pred_worker(), they are packed up with pickle, shipped to the other process, where they are unpacked used. A list wouldn't be passed but would be cloned.

Note: Using multi-processing allow significant speed boost. The next benchmark have been maid runing 100 * 10 different contexts predictions:


Total time without multi-processing: 86.785 s Total time wit multi-processing: 76.513 s

To Do (0.0.9): Demonize the processes, set a timeout value. When the time runs out the unfinished workers return their results as is. This can alter the prediction qality but totaly avoid any possible "slow predictions".