-
Notifications
You must be signed in to change notification settings - Fork 0
/
ml.py
32 lines (24 loc) · 872 Bytes
/
ml.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
28
29
30
31
32
"""
Core logic for learning to identify keywords.
"""
from collections import defaultdict
class NaiveDictLookup:
def __init__(self, authorkey, readerkey, combinedkey, hist='reader'):
self.authorkey = authorkey
self.readerkey = readerkey
self.combinedkey = combinedkey
self.keymap = {'reader': self.readerkey, 'author': self.authorkey,
'combined': self.combinedkey}
# Halt if invalid type of histogram
if hist not in self.keymap:
raise ValueError('NaiveDictLookup has failed to initialize because' \
+ 'your choice of histogram type is invalid')
# Assemble histogram
self.anshist = defaultdict(lambda:0)
for docname,answers in self.authorkey.items():
for a in answers:
self.anshist[a] += 1
def keywords(text):
return
if __name__ == '__main__':
print stemString('cows are stemmed')