-
Notifications
You must be signed in to change notification settings - Fork 4
/
docid.py
34 lines (25 loc) · 685 Bytes
/
docid.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
33
import pickle
class DocID:
def __init__(self):
self.docIDTable = dict()
def get_doc_num(self):
return len(self.docIDTable)
def set(self, term, docID, termPos):
value = self.docIDTable.get(term, [])
value.append((docID, termPos))
self.docIDTable[term] = value
def get(self, term):
return self.docIDTable.get(term, [])
def dump(self, file):
f = open(file, "w")
pickle.dump(self.docIDTable, f)
f.close()
def load(self, file):
f = open(file)
self.docIDTable = pickle.load(f)
f.close()
def pretty_print(self):
for key, value in self.docIDTable.iteritems():
print key
print "*****"
print value