0

I wanted to implement a classification application using python 2 and before classification done text should be preprocessed. Classifier and Preprocessor are in different packages. Then I created a object of preprocessing class in class in classification package.

here is my project explorer

enter image description here

preprocessing class

class preprocessing:

def preprocess(self, file):


    inputFile = "text"
    outputFile = "plainText.txt"

    # infile = io.open(inputFile, "r", encoding='utf-8').read()
    outfile = io.open(outputFile, "w", encoding='utf-8')

    text = unnecessaryCharsObj.removeChars(file)
    text = stopWrdsObj.removeStopwords(text)

    text = text.lower()
    plain = text.split()
    stemmObj.stemminig(plain)

    for x in plain:
        outfile.write(x)
        outfile.write(u'\u0020')
    # plaintext = " ".join(str(x) for x in plain)

    # outfile.write(plaintext)
    return outfile
    outfile.close()

preprocessing class object that created in classidier package,

def classify(self):

    dao = DAO();
    procc = preprocessing();
    # Get IDs of uncatergerized news to uncatNewsList
    uncatNewsList = dao.selectUncategerizedNews();

    for news in uncatNewsList:

        description = dao.getDescriptionById(news[0])

        wf = io.open('news.txt', 'w', encoding='utf-8')
        x = description[0][0]
        wf.write(x)
        rf = io.open('news.txt', 'r', encoding='utf-8').read()

        txt = procc.preprocess(rf)

        category = MultinomialNBClassifier().classifier(txt)
        dao.updateNews(news[0],category[0])

But in preprocessing class, it uses a text file in same preprocess package. So I can't do the job as I wished since it return error "No such file or directory: 'stopWordList.txt'"

what can I do for solving this?

theCoder379
  • 197
  • 1
  • 3
  • 16

1 Answers1

0

Please check that the file is in the same path as path of the current executed file. Here is idea: How do I get the path of the current executed file in Python?

Community
  • 1
  • 1
Sergey Belash
  • 1,433
  • 3
  • 16
  • 21