gpt4 book ai didi

python :getting the count for the adjectives in a string

转载 作者:太空宇宙 更新时间:2023-11-04 05:44:42 25 4
gpt4 key购买 nike

<分区>

我有一个字符串s=“X 先生很棒。他很棒。Y 先生也很棒。”

我需要从字符串中提取所有形容词以及每个形容词的数量。例如该字符串包含形容词“awesome”、“amazing”,其中 2 表示 awesome,1 表示 amazing。

为了提取形容词,我使用了 NLTK。这是提取形容词的代码,

adjectives =[token for token, pos in nltk.pos_tag(nltk.word_tokenize(b)) if pos.startswith('JJ')]

我需要代码为字符串中的每个形容词获取一个计数器。它应该像形容词:反对

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com