0
from nltk.corpus import wordnet as wn

def getSynonyms(word, pos):
    synonymList1 = []
    for data1 in word:
        tmp1data1 = []
        wordnetSynset1 = wn.synsets(data1)
        for syn in wordnetSynset1:
            if syn.pos() == wn.NOUN:
                newSyn1 = [data1, wn.NOUN]#, wn.VERB)
                tmp1data1.append(newSyn1)
                break
            if syn.pos() == wn.VERB:
                newSyn2 = [data1, wn.VERB]
                tmp1data1.append(newSyn2)
                break
            if syn.pos() == wn.ADV:
                newSyn3 == [data1, wn.ADV]
                tmp1data1.append(newSyn3)
                break
            if syn.pos() == wn.ADJ:
                newSyn4 == [data1, wn.ADJ]
                tmp1data1.append(newSyn4)
                break
        return tmp1data1
        tempList1 = []
        for synset1 in tmp1data1:
            synLemmas = synset1.lemma_names()
            for i in xrange(len(synLemmas)):
                word = synLemmas[i]
                tempList1.append(word)
        synonymList1.append(tempList1)
    return synonymList1

words1 = ['move']
pos = ['n','v','a','r']
syn1 = getSynonyms(words1, pos)

print syn1

And it said error on :

elif syn.pos() == wn.VERB:
                         ^
IndentationError: unindent does not match any outer indentation level

I don't understand why there's an indent error start from wn.VERB but not from wn.NOUN. Can someone help me for this?

Also if you don't mind, can you check whether if my codes for showing word synonyms and wordnet pos tags are correct or wrong? Thanks

sang
  • 375
  • 2
  • 8
  • 23
  • 3
    Your code does not match your error message. – Klaus D. Jul 17 '17 at 03:08
  • Possible duplicate of [IndentationError: unindent does not match any outer indentation level](https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) – Adonis Jul 17 '17 at 07:30

0 Answers0