Cannot load Wordnet Error

I am trying to compile this code:

from collections import OrderedDict
import pdb
pdb.set_trace()
def alphaDict(words):
    alphas = OrderedDict()
    words = sorted(words, key = str.lower)
    words = filter(None, words);
    for word in words:
        if word[0].upper() not in alphas:
            alphas[word[0].upper()] = []
            alphas[word[0].upper()].append(word.lower())
    return alphas

def listConvert(passage):
    alphabets = " abcdefghijklmnopqrstuvwxyz"
    for char in passage:
        if char.lower() not in alphabets:
            passage = passage.replace(char, "")
            listConvert(passage)
    passage =  rDup(passage.split(" "))
    return passage




def rDup(sequence):
    unique = []
    [unique.append(item) for item in sequence if item not in unique]
    return unique



def otherPrint(word):
    base = "http://dictionary.reference.com/browse/"
    end = "?s=t"
    from nltk.corpus import wordnet as wn
    data = [s.definition() for s in wn.synsets(word)]
    print("<li>")
    print("<a href = '" +base+word+end+"' target = '_blank'><h2 class = 'dictlink'>" +(word.lower())+":</h2></a>") 
    if not data:
        print("Sorry, we could not find this word in our data banks. Please click the word to check <a target = '_blank' class = 'dictlink' href = 'http://www.dictionary.com'>Dictionary.com</a>")
        return
    print("<ul>")
    for key in data:
    print("<li>"+key+"</li>")
    print("</ul>")
    print("</ol>")
    print("</li>")




def formatPrint(word):
    base = "http://dictionary.reference.com/browse/"
    end = "?s=t"

    from PyDictionary import PyDictionary
    pd = PyDictionary()
    data = pd.meaning(word)

    print "<li>"
    print "<a href = '" +base+word+end+"' target = '_blank'><h2 class = 'dictlink'>" +(word.lower())+":</h2></a>" 

    if not data:
    print "Sorry, we could not find this word in our data banks. Please click the word to check <a target = '_blank' class = 'dictlink' href = 'http://www.dictionary.com'>Dictionary.com</a>"
    return
    print "<ol type = 'A'>"
    for key in data:
    print "<li><h3 style = 'color: red;' id = '" +word.lower()+ "'>"+key+"</h3><ul type = 'square'>"
    for item in data[key]:
            print "<li>" +item+"</li>"
    print "</ul>"
    print "</li>"
    print "</ol>"
    print "</li>"




def specPrint(words):
    print "<ol>"
    for word in words:
        otherPrint(word)
    print "</ol>"
    print "<br/>"
    print "<br/>"
    print "<a href = '#list'> Click here</a> to go back to choose another letter<br/>"
    print "<a href = '#sentence'>Click here</a> to view your sentence.<br/>"
    print "<a href = '#header'>Click here</a> to see the owner information.<br/>"
    print "<a href = '../html/main.html'>Click here</a> to go back to the main page."
    print "</div>"
    for x in range(0, 10):
        print "<br/>"

      

To those who answered my previous question, thanks. It worked, I will accept the answer shortly. However, I have a different problem. When I try to import wordnet into the shell (using compile and IDLE commands) the process works fine. However, on xampp, I am getting this error: enter image description here

Can anyone explain this? Thank!

+3


source to share


2 answers


Your for loop is not indented in another loop -

for key in data:
print("<li>"+key+"</li>")
print("</ul>")
print("</ol>")
print("</li>")

      

This is most likely the problem. Try indenting -



for key in data:
    print("<li>"+key+"</li>")
    print("</ul>")
    print("</ol>")
    print("</li>")

      

Also, please understand that python handles tabs

both spaces

differently, so supposing you are indenting one line using tab

and then the next line using 4 spaces

(hand-spaced), this will cause Python's indentation error. You must either use all spaces or all tabs, you cannot use a mixture of both (even if they look the same).

+1


source


A few things. The first is the line indentation. It might just be copying here.

Then, every time you have a colon, you should have the next indented line. Therefore, in the otherPrint function, you have the following:

for key in data:
print("<li>"+key+"</li>")
print("</ul>")
print("</ol>")
print("</li>")

      

At least the first line must be indented. If you want all prints to be in a loop, you need to indent all of them.



You also have the same problem with you if the instructions are in formatPrint. Try sticking them under the hinges and legends and that should clean it up. If you still find the problem, make sure you have the correct number of parentheses and parentheses covering the instructions. Leaving one, you leave the code to the rest.

Also you are using operators print

instead of functions print()

. The operator print

no longer works in Python 3.x ... you have to enclose the whole thing in parentheses.

def formatPrint(word):
    base = "http://dictionary.reference.com/browse/"
    end = "?s=t"

    from PyDictionary import PyDictionary
    pd = PyDictionary()
    data = pd.meaning(word)

    print("<li>")
    print(
          "<a href = '" +base+word+end+"' target = '_blank'>
          <h2 class = 'dictlink'>" +(word.lower())+":</h2></a>"
          )

    if not data:
        print(
              "Sorry, we could not find this word in our data banks. 
               Please click the word to check <a target = '_blank' 
               class = 'dictlink' href
               ='http://www.dictionary.com'>Dictionary.com</a>"
               )
    return
    print("<ol type = 'A'>")
    for key in data:
        print(
              "<li><h3 style = 'color: red;' id = '" +word.lower()+ 
              "'>"+key+"</h3><ul type = 'square'>"
              )
    for item in data[key]:
        print("<li>" +item+"</li>")
        print("</ul>")
        print("</li>")
        print("</ol>")
        print("</li>")

      

+1


source







All Articles