Retrieving Tags From Result Of Pos Tagging
Using python how to retrieve only the tags - 'NN', 'JJ' etc from ('[', 'NN'), ('u'Tradus-Under', 'NN'), (''', ''''), (',', ','), ('u'Maintenance', 'JJ'), (''', ''''), (']', '
Solution 1:
Assuming those elements are in a list (I call that list lst
):
importstring
lst = [
('[', 'NN'),
("u'Tradus-Under", 'NN'),
("'", "''"),
(',', ','),
("u'Maintenance", 'JJ'),
("'", "''"),
(']', ':')
]
tags = []
for _,poss_tag in lst:
if(len(poss_tag) == 2 and
poss_tag[0] == poss_tag[1] and
poss_tag[0] in string.ascii_letters):
tags.append(poss_tag)
print(tags)
Output:
['NN', 'NN', 'JJ']
If you want a unique set, you could bounce it to a set and back:
print(list(set(tags)))
Output:
['JJ', 'NN']
Post a Comment for "Retrieving Tags From Result Of Pos Tagging"