more refactoring
This commit is contained in:
@ -27,6 +27,24 @@ proc save(wordCounts: CountTable; dictName, countName: string) =
|
||||
break
|
||||
|
||||
|
||||
type Config = object
|
||||
srcPath: string
|
||||
dstPath: string
|
||||
|
||||
|
||||
proc parseInput(): Config =
|
||||
result.srcPath = r"../data/BNC/2554/download/Texts/"
|
||||
result.dstPath = "."
|
||||
|
||||
if paramCount() > 0:
|
||||
result.srcPath = paramStr(1)
|
||||
if paramCount() > 1:
|
||||
result.dstPath = paramStr(2)
|
||||
|
||||
if not dirExists(result.srcPath):
|
||||
quit("Could not locate datafiles: directory " & result.srcPath & " does not exist.")
|
||||
|
||||
|
||||
var
|
||||
threadResults: Channel[CountTable[string]]
|
||||
progress: Channel[int]
|
||||
@ -46,17 +64,10 @@ proc processFiles(filenames: seq[string]) =
|
||||
when isMainModule:
|
||||
let start = getMonoTime()
|
||||
|
||||
let basePath =
|
||||
if paramCount() > 0:
|
||||
paramStr(1)
|
||||
else:
|
||||
r"../BNC/2554/download/Texts/"
|
||||
|
||||
if not dirExists(basePath):
|
||||
quit("Could not locate datafiles: directory " & basePath & " does not exist.")
|
||||
let config = parseInput()
|
||||
|
||||
var paths: seq[string]
|
||||
for path in walkDirRec(basePath):
|
||||
for path in walkDirRec(config.srcPath):
|
||||
if path.endsWith(".xml"):
|
||||
paths.add(path)
|
||||
|
||||
@ -79,15 +90,10 @@ when isMainModule:
|
||||
counts.inc(word, count)
|
||||
|
||||
counts.sort()
|
||||
let outPath =
|
||||
if paramCount() > 1:
|
||||
paramStr(2)
|
||||
else:
|
||||
"."
|
||||
|
||||
let
|
||||
dPath = joinPath(outPath, "dictionary.txt")
|
||||
cPath = joinPath(outPath, "counts.txt")
|
||||
dPath = joinPath(config.dstPath, "dictionary.txt")
|
||||
cPath = joinPath(config.dstPath, "counts.txt")
|
||||
save(counts, dPath, cPath)
|
||||
|
||||
echo "Done. Finished in ", (getMonoTime() - start).inMilliseconds.float / 1000, " seconds."
|
||||
|
Reference in New Issue
Block a user