-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
35 lines (29 loc) · 959 Bytes
/
utils.py
File metadata and controls
35 lines (29 loc) · 959 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
31
32
33
34
35
import re
import nltk
from nltk.corpus import stopwords
from nltk.stem import PorterStemmer
stop_words = set(stopwords.words('english'))
import xml.etree.cElementTree as em
alphabet_selector = re.compile("[^a-zA-Z]")
ps = PorterStemmer()
def update_words(word_dict, entry, istext=False):
if istext:
entry = re.split(alphabet_selector, entry)
else:
pass
if entry:
for item in entry:
string_list = re.split(alphabet_selector, item)
for word in string_list:
word = ps.stem(word.lower())
if word:
if word not in stop_words:
if word not in word_dict:
word_dict[word] = 0
word_dict[word] += 1
else:
pass
def get_context(data):
context = em.iterparse(data, events=("start", "end"))
context = iter(context)
return context