pos_tag(word_tokenize("John's big idea isn't all that bad."))
[('John', 'NNP'), ("'s", 'POS'), ('big', 'JJ'), ('idea', 'NN'), ('is',
'VBZ'), ("n't", 'RB'), ('all', 'DT'), ('that', 'DT'), ('bad', 'JJ'),
('.', '.')]
根本不识别语法。我如何在成对的第二个值中迭代检查JJ
。
答案 0 :(得分:6)
它看起来像一对对象列表(大小为2的元组)。
迭代它很简单:
for text, type in pos_tag(word_tokenize("John's big idea isn't all that bad.")):
if type == 'JJ':
print 'text:', text
print 'type:', type
答案 1 :(得分:1)
看起来像是一个包含2元组的列表。
[x for x in L if x[1] == 'JJ']
答案 2 :(得分:1)
list_values = [
('John', 'NNP'),
("'s", 'POS'),
('big', 'JJ'),
('idea', 'NN'),
('is', 'VBZ'),
("n't", 'RB'),
('all', 'DT'),
('that', 'DT'),
('bad', 'JJ'),
('.', '.')
]
for (a, b) in list_values:
if b == 'JJ':
DoSomething(a,b)