Sirapatrwan commited on
Commit
4f8669a
·
verified ·
1 Parent(s): d455f22

Add part of speech tagging

Browse files
Files changed (1) hide show
  1. part_of_speech_tagging.py +26 -0
part_of_speech_tagging.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import nltk
2
+ from nltk.tokenize import word_tokenize
3
+ nltk.download('punkt')
4
+ nltk.download('averaged_perceptron_tagger')
5
+
6
+
7
+ class POSTagging:
8
+ """Part of Speech Tagging on text data"""
9
+
10
+ def __init__(self):
11
+ pass
12
+
13
+ def classify(self, text):
14
+ """
15
+ Generate Part of Speech tags.
16
+
17
+ Parameters:
18
+ text (str): The user input string to generate tags for
19
+
20
+ Returns:
21
+ predictions (list): list of tuples containing words and their respective tags
22
+ """
23
+
24
+ text = word_tokenize(text)
25
+ predictions = nltk.pos_tag(text)
26
+ return predictions