I have the following two files, ProcessText.py and test.py, yet when I run test.py I get the error above. I have checked all of the code and there is nothing wrong with the attribute settings(I think). I am new to python but not programming, so if I'm doing something stupid please let me know :). From what I've gathered online it's something to do with the importing, but I don't quite understand what import is messing with what.
from ProcessText import ProcessText
class test:
input = "input string goes here"
ProcessText(input)
tfDict = ProcessText.setTFIDF(input)
for k, v in tfDict:
print(k," : ",v )
import math
import string
import this
from nltk.stem import WordNetLemmatizer
from nltk.corpus import stopwords
from nltk.stem import PorterStemmer
from nltk.tokenize import word_tokenize
class ProcessText:
tfDict = dict()
stemmedWords = []
lemmatizedWords = ""
stemmedWordsRem = []
sentences = []
def __init__(self, input):
lemmatizer = WordNetLemmatizer()
text = word_tokenize(input)
ps = PorterStemmer()
this.stopWordsRem = [word for word in text if not word in stopwords.words()] # removes stop words from input
for each in this.stopWordsRem: # stems input words
this.stemmedWords.append(ps.stem(each))
this.lemmatizedWords = [lemmatizer.lemmatize(w) for w in stemmedWords] # lemmatizes each input word
this.lemmatizedWords = ''.join(this.lemmatizedWords)
this.emPunctuation = this.lemmatizedWords.translate(
str.maketrans('', '', string.punctuation)) # strips punctuation from string
this.sentences = this.lemmatizedWords.split(".")
def setTFIDF(input):
for word in this.remPunctuation: # Finds the TF value of each word
termsCount = 0
if not (word in this.tfDict):
for words in this.lemmatizedWords:
if (words == word):
termsCount += 1
this.tfDict[word] = termsCount
for k, v in this.tfDict.items(): # Finds the TF-IDF value of each word in the input text MIGHT need to add log to this
documentsWithWord = 0
for sentence in this.sentences:
if sentence.find(k):
documentsWithWord += 1
this.tfDict[k] = math.log((len(sentence) / documentsWithWord) * v)
return this.tfDict