Re: [Pyparsing] Supporting Spelling Variations
Brought to you by:
ptmcg
From: Paul M. <pa...@al...> - 2007-09-10 13:51:06
|
Tim - Avoid Or in favor of MatchFirst when you have unambiguous alternatives like this. And if you have a priori knowledge of which variation will be more common, put it first in the list. Here are a couple of options: - Suppress( oneOf("specialize specialise") ) - MatchFirst( map(Suppress,["specialize","specialise"]) ) - Regex("speciali[sz]e").suppress() I've not had a chance to test any of these for performance, but they should be equivalent functionally. -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of Tim Cook Sent: Monday, September 10, 2007 3:29 AM To: PyParsing List Subject: [Pyparsing] Supporting Spelling Variations Hi All, I need to support both 'specialise' and 'specialize' (actually there are many British/Australian/US spelling variations like this) My first attempts were to use either an Or list or a MatchFirst list. i.e. Suppress("specialise" Or "specialize") Each of those raised: TypeError: unsupported operand type(s) for ^: 'str' and 'str' My solution (so far) is: specialise = Suppress("specialise") specialize = Suppress("specialize") specialiseSection = (specialise | specialize + ... Is there a better/more efficient approach? Cheers, Tim -- Timothy Cook, MSc Health Informatics Research & Development Services http://timothywayne.cook.googlepages.com/home 01-904-322-8582 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |