-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpreprocessing.py
More file actions
22 lines (20 loc) · 834 Bytes
/
Copy pathpreprocessing.py
File metadata and controls
22 lines (20 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import nltk
from nltk.corpus import stopwords
from nltk.stem.wordnet import WordNetLemmatizer
import re
def pre_process(text):
stop_words = set(stopwords.words('english'))
new_words = ["fig", "figure", "image", "sample", "using",
"show", "result", "large",
"also", "one", "two", "three",
"four", "five", "seven", "eight", "nine"]
stop_words = list(stop_words.union(new_words))
text = text.lower()
text = re.sub("</?.*?>", " <> ", text)
text = re.sub("(\\d|\\W)+", " ", text)
text = text.split()
text = [word for word in text if word not in stop_words]
text = [word for word in text if len(word) >= 3]
lmtzr = WordNetLemmatizer()
text = [lmtzr.lemmatize(word) for word in text]
return ' '.join(text)