Navigation Menu

Skip to content

Commit

Permalink
fixes generate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
epico committed Jul 27, 2011
1 parent 2575950 commit 0128ad5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
23 changes: 13 additions & 10 deletions generate.py
Expand Up @@ -32,9 +32,9 @@ def generateOneText(infile, modelfile, reportfile):

#begin processing
cmdline = ['./gen_k_mixture_model', '--maximum-occurs-allowed', \
config.getMaximumOccursAllowed(), \
str(config.getMaximumOccursAllowed()), \
'--maximum-increase-rates-allowed', \
config.getMaximumIncreaseRatesAllowed(), \
str(config.getMaximumIncreaseRatesAllowed()), \
'--k-mixture-model-file', \
modelfile, infile + \
config.getSegmentPostfix()]
Expand Down Expand Up @@ -73,6 +73,16 @@ def handleOneIndex(indexpath, subdir, indexname):
if 'GenerateModelEnd' in indexstatus:
modelnum = indexstatus['GenerateModelEnd']

#clean up previous file
modeldir = os.path.join(config.getModelDir(), subdir, indexname)
modelfile = os.path.join( \
modeldir, config.getCandidateModelName(modelnum))
reportfile = modelfile + config.getReportPostfix()
if os.access(modelfile, os.F_OK):
os.unlink(modelfile)
if os.access(reportfile, os.F_OK):
os.unlink(reportfile)

#begin processing
indexfile = open(indexpath, 'r')
for i, oneline in enumerate(indexfile.readlines()):
Expand Down Expand Up @@ -112,14 +122,7 @@ def handleOneIndex(indexpath, subdir, indexname):
aggmodelsize = 0
textnum = nexttextnum
modelnum += 1
modeldir = os.path.join(config.getModelDir(), subdir, indexname)
modelfile = os.path.join( \
modeldir, config.getCandidateModelName(modelnum))
reportfile = modelfile + config.getReportPostfix()
if os.access(modelfile, os.F_OK):
os.unlink(modelfile)
if os.access(reportfile, os.F_OK):
os.unlink(reportfile)

#save current progress in status file
indexstatus['GenerateTextEnd'] = nexttextnum
indexstatus['GenerateModelEnd'] = modelnum
Expand Down
3 changes: 3 additions & 0 deletions lib/myconfig.py
Expand Up @@ -78,6 +78,9 @@ def getMaximumOccursAllowed(self):
def getMaximumIncreaseRatesAllowed(self):
return 3.

def getReportPostfix(self):
return '.report'

def getSegmentPostfix(self):
return '.segmented'

Expand Down
3 changes: 2 additions & 1 deletion lib/utils.py
@@ -1,3 +1,4 @@
import io
import os
import json
from myconfig import MyConfig
Expand Down Expand Up @@ -34,7 +35,7 @@ def write_file(outfile, data):

def get_file_length(infile):
f = open(infile, 'r')
f.seek(0, whence=io.SEEK_END)
f.seek(0, io.SEEK_END)
length = f.tell()
f.close()
return length
Expand Down

0 comments on commit 0128ad5

Please sign in to comment.