-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_topic.py
More file actions
63 lines (49 loc) · 1.37 KB
/
get_topic.py
File metadata and controls
63 lines (49 loc) · 1.37 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
#====================
#read the content of the message into a variable
#size/print only needed for dev/debug
with open("messagebody.txt") as f:
content = f.read()
#size = len(content)
#print (content)
#=====================
#loop through the keywords list and search the content for each keyword
with open("keywords.txt")as m:
meta = m.read().splitlines()
#find the matching words
for var in meta:
import re
x = re.findall(var, content)
#display the found words with counts
#print (x , len(x))
#=====================
#of the found words, which is the most common
#could be expanded later to extract top 3 from list/array as m1, m2, m3
#useful for better matches and topic analysis
import collections
c = collections.Counter(x).most_common(1)
#print ('most common match =', c)
for key, value in c:
#print(key, value)
m1 = key
#print(m1)
#=====================
#get the paired topic
pairset = {}
with open("pairs.txt") as p:
for line in p:
(key, val) = line.split(':')
a = key
v = val
#print (v)
if m1 in key:
#print(v)
topic = v
print (topic)
#======================
#do something with the topic
#======================
#======================
#close the files
f.close()
m.close()
p.close()