def anotherword(response): #Some rudimentary synonyms and antonyms. choice=input('Enter your choice: \n 1.Synonyms.\n2.Antonyms\n') if(int(choice)>2): print("Invalid Choice") exit() word=input("Enter the word:") w = Word(word) what='' if('1') in choice: temp=w.synonyms() what='Synonyms' elif('2') in choice: temp=w.antonyms() what='Antonyms' print('Showing %s of %s'%(what,word)) for t in temp: print(t)
def process_words(self): """ Sort words, look for duplicates, then get synonyms and write to output files. Looking for duplicates here because that is an indication that multiple sources think the term is appropriate for the given grade level. """ # print(self.words) # get duplicate words - the words we want to use words = self.words duplicates = list(set([x for x in words if words.count(x) > 1])) duplicates.sort() """ try a different way """ for word in duplicates: try: w = Word(word) except MisspellingError: continue else: # There are 3 relevance levels you can use, 1 will give the set with the most words # and possibly some irrelevant words. Here we use 3 to make sure everything stays on topic. syns = w.synonyms(relevance=3) if syns: for s in syns: self.outputFiles[1].write(word + " " + s + "\n") ants = w.antonyms(relevance=3) if ants: for a in ants: self.outputFiles[2].write(word + " " + a + "\n") if syns or ants: self.outputFiles[0].write(word + " " + self.gradeLevel + "\n")