-
Notifications
You must be signed in to change notification settings - Fork 1
/
readfiles.py
45 lines (35 loc) · 1.61 KB
/
readfiles.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
34
35
36
37
38
39
40
41
42
43
44
45
def readtrainingdata(batchsize, docindex, docpath, labpath):
docs = file(docpath).readlines()
labels = file(labpath).readlines()
if ((docindex + batchsize) <= len(docs)):
outputdocs = docs[docindex: docindex + batchsize]
outputlabs = labels[docindex: docindex + batchsize]
docindex = docindex + batchsize + 1
if ((docindex + batchsize) > len(docs)):
outputdocs = docs[docindex:]
outputlabs = labels[docindex:]
docindex = batchsize - (len(docs) - docindex)
outputdocs[0:0] = docs[0:docindex]
outputlabs[0:0] = labels[0:docindex]
docindex = docindex + 1
return (outputdocs, outputlabs, docindex)
def readtrainingdata1(batchsize, docindex, docs, labels):
if ((docindex + batchsize) <= len(docs)):
outputdocs = docs[docindex: (docindex + batchsize)]
outputlabs = labels[docindex: (docindex + batchsize)]
docindex = docindex + batchsize + 1
return (outputdocs, outputlabs, docindex)
if ((docindex + batchsize) > len(docs)):
outputdocs = docs[docindex:]
outputlabs = labels[docindex:]
docindex = batchsize - (len(docs) - docindex)
outputdocs[0:0] = docs[0:docindex]
outputlabs[0:0] = labels[0:docindex]
docindex = docindex + 1
return (outputdocs, outputlabs, docindex)
def readtestdata(docpath, labpath, lambdapath, mupath):
docs = file(docpath).readlines()
goldlabels = file(labpath).readlines()
_lambda = file(lambdapath).readlines()
mu = file(mupath).readlines()
return (docs, goldlabels, _lambda, mu)