-
Notifications
You must be signed in to change notification settings - Fork 4
/
nlp_example.py
28 lines (23 loc) · 1021 Bytes
/
nlp_example.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
"""
Copyright © 2020 Johnson & Johnson
"""
import pandas as pd
from nlprov.preprocessing import preprocess_text
from nlprov.vectorize import vectorize_text, vectorize_new_text
from nlprov.similarity_calc import similarity_calculation
text = pd.Series(data=[" Combination of spaces. ",
"MixEd CASe",
",./;'[]\-=",
'<>?:"{}|_+',
'!@#$%^&*()`~"',
"lemmas needed",
"ducks and cats and ponies are not similar",
"c'est français",
"das ist deutsch",
"this is una mezcla"])
preprocessed_text = preprocess_text(text)
vec_text, vec_obj = vectorize_text(preprocessed_text)
new_text = pd.Series(data=["ducks and cats are not similar"])
new_preprocessed_text = preprocess_text(new_text)
new_vec_text = vectorize_new_text(new_preprocessed_text, vec_obj)
similarity = similarity_calculation(new_vec_text, vec_text)