constructing and using large lexicon in a program
Michael Torrie
torriem at gmail.com
Mon Aug 2 13:52:42 EDT 2010
On 08/02/2010 11:46 AM, Majdi Sawalha wrote:
> I am developing a morphological analyzer that depends on a large lexicon. i
> construct a Lexicon class that reades a text file and construct a dictionary of
> the lexicon entries.
> the other class will use the lexicon class to chech if the word is found in the
> lexicon. the problem that this takes long time as each time an object of that
> class created, then it needs to call the lexicon many times. then when the
> lexicon is called it re-construct the lexicon again. is there any way to
> construct the lexicon one time during the execution of the program? and then the
> other modules will search the already constructed lexicon.
Can you not create a module that, upon import, initializes this lexicon
as a module attribute? Modules are by definition singleton objects,
which is the pattern that you probably need. Any other module could
import this module and get the already-created lexicon object.
More information about the Python-list
mailing list