Home | Trees | Indices | Help |
|
---|
|
object --+ | Predictor --+ | WeightNgramPredictor
Compute prediction from n-gram model in database.
![]() |
Class Hierarchy for WeightNgramPredictor |
|
|||
Inherited from Predictor | |||
---|---|---|---|
__metaclass__ Metaclass for defining Abstract Base Classes (ABCs). |
|
|||
|
|||
|
|||
Prediction |
|
||
Prediction |
|
||
|
|||
|
|||
|
|||
dict |
|
||
|
|||
|
|||
Inherited from |
|
|||
__abstractmethods__ =
|
|||
Inherited from Predictor | |||
---|---|---|---|
_abc_cache = <_weakrefset.WeakSet object at 0x7f2a42360550>
|
|||
_abc_negative_cache = <_weakrefset.WeakSet object at 0x7f2a423
|
|||
_abc_negative_cache_version = 39
|
|||
_abc_registry = <_weakrefset.WeakSet object at 0x7f2a42360490>
|
|
|||
Inherited from |
|
WeightNgramPredictor creator.
|
Initialize the database connector. Using the database file path, the n-gram maximum size and the learn mode to initialize and open the database. |
Predict the next word according to the current context. Use the input buffers (thanks to contextMonitor) and the n-gram database to predict the most probable suggestions. A suggestion is a word which can:
In order to compute the suggestions, this method:
|
Compute probability of suggestions and return the most probable ones. The probability of a suggestion is based on its relative frequency toward the whole set of suggestions and the number of single tokens in the database.
|
Learn what need to be learnt by adding n-grams in database.
|
Create a map associating n-grams (lists of words) and their count.
|
Use the input left buffer to expand the n-gram map. This method call cntxt.ContextMonitor.previous_tokens to get the tokens from the left input buffer that are just before the change and add them BEFORE the change n-grams generated by self.make_ngram_map. For instance, if the current left input buffer is: "phone is on the white table " And change is: "table" Then, the n-gram map generated by self.make_ngram_map() will be: {("table"): 1} The n-gram map contain a sinle n-gram of size 1. And so this method will add the tokens preceding the change in the left input buffer to form n-grams of size 2 and more (until it reaches self.maxN): {("the", "white", "table"): 1, ("white", "table"): 1, {"table"): 1}
|
Update the database with the n-grams contained in the n-gram map. Each n-gram of the n-gram map is pushed into the database with its number of occurences (count). If the n-gram is already in the database then its count (number of occurences) is updated. If the n-gram is not in the database then it is simply inserted in it.
|
Make an n-gram then retrieve and return its 'count' entry in the db.
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Jul 14 21:07:50 2015 | http://epydoc.sourceforge.net |