-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
top 10 function, seperate functionality
- Loading branch information
Showing
3 changed files
with
70 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import string | ||
from load_course_info import course_descriptions | ||
|
||
def preprocess_text(text): | ||
""" Tokenization and preprocessing with custom stopwords""" | ||
custom_stopwords = ["of", "the", "in", "and", "on", "an", "a", "to"] | ||
strong_words = ["technology","calculus","buisness", "Artificial Intelligence", "First-Year Writing", "computer","python","java","economics","US","writing","biology","chemistry", "physics", "engineering","ancient" | ||
"programming", "algorithms", "data structures","art","software","anthropology" "databases","fiction","mathematics", "history","civilization"] | ||
|
||
translator = str.maketrans("", "", string.punctuation) | ||
text = text.lower() | ||
text = text.translate(translator) | ||
tokens = text.split() | ||
tokens = [token for token in tokens if token not in custom_stopwords] | ||
for word in strong_words: | ||
if word in tokens: | ||
tokens += [word] * 10 | ||
return " ".join(tokens) | ||
|
||
def removeStopwords(): | ||
"Removes stopwords for all the descriptions " | ||
preprocessed = [] | ||
for desc in course_descriptions: | ||
if desc: | ||
preprocessed.append(preprocess_text(desc)) | ||
return preprocessed | ||
|
||
preprocessed_descriptions = removeStopwords() |