如何从wordnetnltk中提取所有附属形容词并保存到文本文件中?

2024-10-08 20:23:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从WordNet中提取所有附属形容词语法集,并将它们保存到文本文件中。注意,附属形容词在synset名称中表示为“s”,例如“(fantactic.s.02)”。以下是我的代码:

def extract_sat_adjectives():
    sat_adj_counter = 0
    sat_adjectives = []
    for i in wn.all_synsets():
        if i.pos() in ['s']:
            sat_adj_counter +=1
            sat_adjectives = sat_adjectives + [i.name()]
    fo = open("C:\\Users\\Nora\\Desktop\\satellite_adjectives.txt", "wb")
    for x in sat_adjectives:
        fo.write("%s\n" % x)
    fo.close()


extract_sat_adjectives()

我得到的错误是:

^{pr2}$

如何将形容词保存到文本文件中?提前谢谢。在


Tags: in名称forcounter语法extractsatwordnet

热门问题