-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenizer.py
More file actions
31 lines (23 loc) · 830 Bytes
/
Copy pathTokenizer.py
File metadata and controls
31 lines (23 loc) · 830 Bytes
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
from collections import Counter
from nltk.tokenize import RegexpTokenizer
filepath ="D:\PythonProjects\SentimentAnalysis\input\pos.txt"
def tokenizer_fun(fpath):
filename = open(fpath,"r").read()
type(filename)
tokenizer = RegexpTokenizer(r'\w+')
# tokens_lower = word_tokenize(filename.lower())
tokens = tokenizer.tokenize(filename.lower())
# countLower = Counter(tokens_lower)
print (len(tokens))
unigrams_count = Counter(tokens)
print(dict(unigrams_count))
# print(tokens.count("..."))
# print(len(filename))
return tokens
def tokenizer_func(fpath):
import string
fileStream = open(fpath,"r").read().lower()
occurrence = Counter(fileStream.translate(None, string.punctuation).split())
print(occurrence)
#unigrams_list = tokenizer_func(filepath)
#print(count)