what does "tree.subtree()" method returns with the filter which does not match any subtree?

50 views
Skip to first unread message

karm...@gmail.com

unread,
Dec 26, 2020, 7:43:27 AM12/26/20
to nltk-users
Hello,

I have the following example of "nltk.tree.Tree" instance.

tree = Tree('S', [('我们', 'rr'), (',', 'wd'), Tree('BI', [('像', 'p')]), Tree('OBJ', [('中国', 'ns')]), Tree('RES', [('一样', 'uyy')]), ('地', 'ude2'), Tree('DIM', [('坚持', 'v')]), ('这么', 'rz'), ('长久', 'a'), ('而', 'cc'), ('无所畏惧', 'vl'), (',', 'wd')])

I want to find a specific subtree, let's say whose label is 'RES'. The code below shows what I want.

for subtree in tree.subtrees(lambda x: x.label() == 'RES'):
    print(subtree.__repr__())
> Tree('RES', [('一样', 'uyy')])

However, when it is given the label not in the tree(eg. 'EXT'), the code returns nothing.

for subtree in tree.subtrees(lambda x: x.label() == 'EXT'):
    print(subtree.__repr__())
> (NOTHING!!!)

I need to distinguish the two situation by using 'if statement' but I can't, because I don't know what it returns in the latter case. 


oleg kapanadze

unread,
May 17, 2021, 7:04:37 AMMay 17
to nltk-users
Hello, Karm (if I may),

I am trying without a success to get a mixed (the Georgian utf-8  and Latin)  text in a single file on the monitor. I can see, you have a mixed text in your example. Could you, please, let me know, how can I cope with this issue in my case.
 Thanks in advance
Please, for feedback use my institutional email e-mil: okapa...@uni-potsdam.de

Oleg

შაბათი, 26 დეკემბერი, 2020-ში 16:43:27 UTC+4-ზე karm...@gmail.com-მა დაწერა:
Reply all
Reply to author
Forward
0 new messages