1

i want to build a class that can automaticly doing some text preprocessing when input a text string, the variable of what I'm input is docs_new

class prepro():
    def __init__(self):
        pass
    def low(self,docs_new):
             lower_case = docs_new.lower()

first i build a class that can process it but, i know its wrong right? so how to make the .lower() work on a docs_new when docs_new is a list.

docs_new = [input('input a text: ')]
new_tfidf= tfidf.transform(prepro.lower_case) -> i know this code of a line is wrong.
featureselection= selection.transform(x_newtfidf) 
predicted = classifier.predict(featureselection)
print(predicted)

when i input a text its error

AttributeError: type object 'prepro' has no attribute 'lower_case'

here i want to Input a text then i want the docs_new doing automatic prepro whitin class called preproand how should i code it? thank you

Sdtv
  • 55
  • 1
  • 7
  • See this question - https://stackoverflow.com/questions/2709821/what-is-the-purpose-of-the-word-self – Michael Delgado Jun 08 '20 at 08:33
  • The second question is. I want to know how to use the docs_new that already process to lower case in class. So i can call it. Into new_tfidf= tfidf.transform(variable) what variable should i call to get my docs_new that already process into lower case – Sdtv Jun 08 '20 at 13:22

1 Answers1

0

I am not sure what the question of the scond part is, but to answer "how to make the .lower() work on a docs_new when docs_new is a list?"

docs_new = ['DOC_A','DOC_B']
docs_new_lower = [doc.lower() for doc in docs_new]

print(docs_new_lower)
Finn
  • 2,333
  • 1
  • 10
  • 21
  • The second question is. I want to know how to use the docs_new that already process to lower case in class. So i can call it. Into new_tfidf= tfidf.transform(variable) what variable should i call to get my docs_new that already process into lower case @Finn – Sdtv Jun 08 '20 at 13:20
  • Are your questions: 1. You want a class that makes `.lower()` of each string it gets? 2. And then you want to know how you can access the string with only lower letters? Could you please add the code where you create the prepo instance (that is where you have something like `... = prepro()` )? – Finn Jun 09 '20 at 09:26
  • Yes thats what i'm asking for. The code is all there. I'm bad in coding with a class. The first and the second code above is 1 actually. So i made a class prepro() then make a method/variable lower_case inside a class, Then i confuse how can i use that class to process the docs_new and outputting a low case of text from what we input in the docs_new – Sdtv Jun 10 '20 at 10:22