lundi 29 juin 2015

How can I extract all satellite adjectives from WordNet NLTK and save them to a text file? (Python))


I am trying to extract all satellite adjective synsets from WordNet and save them to a text file. Note that satellite adjectives are denoted as 's' in the synset name, e.g., "(fantastic.s.02)". The following is my code:

    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()

The error I get is:

TypeError: 'str' does not support the buffer interface  

How can I save the adjectives to the text file? Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire