On 7/5/2010 3:19 PM, John Nagle wrote:
  I'm working on street address parsing again, and I'm trying to deal
with some of the harder cases.

The approach below works for the cases given. The "Or" operator ("^") supports backtracking, but "Optional()" apparently does not.


direction = Combine(MatchFirst(map(CaselessKeyword, directionals)) +
    Optional(".").suppress())
        
streetNameOnly = Combine(OneOrMore(Word(alphanums)), adjacent=False,
    joinString=" ").setResultsName("streetname")

streetNameParser =
    ((direction.setResultsName("predirectional") + streetNameOnly)
    ^ streetNameOnly)



                                        John Nagle
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to