Package tipy :: Module cntxt :: Class ContextChangeDetector
[hide private]
[frames] | no frames]

Class ContextChangeDetector

source code

object --+
         |
        ContextChangeDetector

Detect context change.

A context change can occure when some special characters appear in the buffers:

It is important to detect context change because some operations such as n-gram learning from input or suggested words suppression have to be carried out upon context changes.

Class Hierarchy for ContextChangeDetector
Class Hierarchy for ContextChangeDetector

Instance Methods [hide private]
 
__init__(self, lowercase, config)
ContextChangeDetector creator.
source code
 
update_monitored_scope(self, string)
Move the monitored scope according to the string length.
source code
boolean
context_change(self, leftBuffer)
Check if the context has changed.
source code
list
change(self, leftBuffer)
Return the (part of the) token(s) appearing after a change.
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, lowercase, config)
(Constructor)

source code 

ContextChangeDetector creator.

Parameters:
  • config (drvr.Configuration) - It is used to retrieve the ContextMonitor settings from the configuration file.
  • lowercase (boolean) - Indicate if the tokens should be convert to lowercase.
Overrides: object.__init__

update_monitored_scope(self, string)

source code 

Move the monitored scope according to the string length.

Parameters:
  • string (str) - Every characters inputed in the monitored buffer.

context_change(self, leftBuffer)

source code 

Check if the context has changed.

To determine if a context change occure or not it is important to scan the input left buffer and the monitored scope. A change occure if:

  • The monitored scope is not part of the left buffer.
  • The monitored scope is part of the left buffer and a separator character appear in the left buffer part wich is not the monitored scope.
Parameters:
  • leftBuffer (str) - The input left buffer.
Returns: boolean
True or False weither the context has changed or not.

change(self, leftBuffer)

source code 

Return the (part of the) token(s) appearing after a change.

When a change occure it is necessary to retrieve the characters forming (partial) tokens which have been inputed AFTER the change and this is what this method do. Weither a change occure or not is determined by self.context_change().

Parameters:
  • leftBuffer (str) - The input left buffer.
Returns: list
(Part of) tokens inputed after the last change.

Note: If no change have been registered yet then the leftBuffer is returned.