[egenix-users] A quiestion from a mx.TextTools newbie
Wenping Wang
wenping0 at yahoo.com
Fri Mar 6 10:21:32 CET 2009
Hello Friends,
I'm new to mx.TextTools & am learning this powerful tool by reading David Mertz's excellent book "Text Processing in Python". Naturally I tried the examples in the book. One particular example concerning mx.TextTools is the one under "mx.TextTools.AppendTagobj" on Page 307.
Unfortunately, that example from David's book doesn't work. I was able to tweak the code to make it work. But I was puzzled why it doesn't work. I attach the segment of codes here.
#--- example code starts
from mx.TextTools import *
#--- 1st approach: failure
words = (('word', AllIn+AppendTagobj, alpha),
(None, AllIn, whitespace, MatchFail, -1))
tag('this and that', words)
#--- 2nd approach: success
words = (('word', AllIn, alpha),
(None, AllIn, whitespace, +1),
(None,EOF,Here,-2))
tag('this and that', words)
#--- 3rd approach: success
word = []
def emiter(tl,txt,l,r,s):
word.append(txt[l:r])
words = ((emiter, AllIn+CallTag, alpha),
(None, AllIn, whitespace, MatchFail, -1))
tag('this and that', words)
#--- example code ends
Can someone provide me some insight why the 1st approach doesn't work while the 2nd & 3rd work? BTW, I'm using mx.TextTools 3.1.2 on Windows.
Thanks much.
Best,
Wenping Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /mailman-archives/egenix-users/attachments/20090306/bd4301a2/attachment.htm
More information about the egenix-users
mailing list