-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_whisk_clf.py
51 lines (38 loc) · 1.17 KB
/
all_whisk_clf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pandas as pd
import numpy as np
import re
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer
import joblib
def tokenise_and_stem_text(text):
'''
INPUTS:
text (string) - what you want to be lemmatised
OUTPUTS:
lemmas (list) - list of lemmatised next
'''
# Import stopword list and update with a few of my own
stopword_list = stopwords.words("english")
[stopword_list.append(i) for i in ['nose', 'palate', 'taste', 'finish']]
# Normalise text - remove numbers too as we don't need them
text = re.sub(r"[^a-zA-Z]", " ", text.lower())
# tokenise
words = text.split()
# Checks it's a word and removes stop words
words = [word for word in words if word not in stopword_list]
# Create stemmer object
stemmer = PorterStemmer()
# Add lemmas
lemmas = []
for word in words:
lemmas.append(stemmer.stem(word))
return lemmas
def getnose(array):
return array[:,0]
def getpalate(array):
return array[:,1]
def getfinish(array):
return array[:,2]
def get_whisky_classifier():
whiskyclassifier = joblib.load("whisky_classifier.pkl")
return whiskyclassifier