from nltk.corpus import wordnet as wn from syllables import estimate # syns = wn.synsets("program") # print(syns[0].name()) # grief = wn.synsets('grief') # love = wn.synsets('love') # # print(grief.path_similarity(love)) # # print(grief) # print(grief[0].definition()) # print(love[0].definition()) abstractNouns = list([i for i in wn.synset('abstraction.n.06').closure(lambda s:s.hyponyms())]) print(len(abstractNouns)) d = {} for n in abstractNouns: if str(estimate(n.name())) in d.keys(): d[str(estimate(n.name()))].append(n.lemmas()[0].name()) else: d[str(estimate(n.name()))] = [n.lemmas()[0].name()] # print(n.lemmas()[0].name(),estimate(n.name())) for i in d: with open(f'{i}_syllable.txt', 'a') as f: for ind, l in enumerate(d[i]): if ind < len(d[i]) - 1: f.write(f'{l}\n'.replace('_', ' ')) else: f.write(f'{l}'.replace('_', ' '))