Toro-Angel commited on
Commit
2bdb264
·
verified ·
1 Parent(s): 3d37937

Update analyzer.py

Browse files
Files changed (1) hide show
  1. analyzer.py +4 -1
analyzer.py CHANGED
@@ -6,16 +6,19 @@ import joblib
6
  from sklearn.feature_extraction.text import CountVectorizer
7
  from sklearn.naive_bayes import MultinomialNB
8
  from sklearn.pipeline import Pipeline
 
9
 
10
  app = Flask(__name__)
11
 
12
  # Function to preprocess text data
13
  def clean_text(texts):
14
  cleaned_texts = []
 
15
  for text in texts:
16
  text = text.lower()
17
  text = re.sub(r'[^\w\s]', ' ', text)
18
- cleaned_texts.append(text)
 
19
  return cleaned_texts
20
 
21
  # Function to determine sentiment label based on probability
 
6
  from sklearn.feature_extraction.text import CountVectorizer
7
  from sklearn.naive_bayes import MultinomialNB
8
  from sklearn.pipeline import Pipeline
9
+ from nltk.stem import PorterStemmer
10
 
11
  app = Flask(__name__)
12
 
13
  # Function to preprocess text data
14
  def clean_text(texts):
15
  cleaned_texts = []
16
+ ps = PorterStemmer()
17
  for text in texts:
18
  text = text.lower()
19
  text = re.sub(r'[^\w\s]', ' ', text)
20
+ words = [ps.stem(word) for word in text.split()]
21
+ cleaned_texts.append(' '.join(words))
22
  return cleaned_texts
23
 
24
  # Function to determine sentiment label based on probability