configurable output dir

This commit is contained in:
Joseph Montanaro 2021-07-26 20:54:13 -07:00
parent d9b542823b
commit 7caac67689
4 changed files with 16 additions and 16 deletions

View File

View File

View File

@ -26,25 +26,13 @@ proc runCmd(command: string, input = "", cache = ""): string =
quit(exitCode)
result = output
proc pathExists(filename: string): bool =
let (output, code) = gorgeEx("ls " & filename)
return code == 0
task(dictionary, "Generate dictionary from BNC XML files"):
if not pathExists("BNC"):
quit("Cannot build dictionary: BNC data files not found.", 1)
echo "Building dictionary"
echo runCmd("nim c --run --threads:on -d:release -d:lto src/process.nim")
task(showexec, "this is a test"):
let (output, exitCode) = gorgeEx("ls BNC")
echo output
echo exitCode
let output = runCmd("nim c --run --threads:on -d:release -d:lto src/process.nim BNC/2554/download/Texts src/")
echo output.strip().splitlines()[^1]
before(build):
if not pathExists("src/dictionary.txt"):
if not dirExists("src/dictionary.txt"):
dictionaryTask()

View File

@ -52,6 +52,9 @@ when isMainModule:
else:
r"../BNC/2554/download/Texts/"
if not dirExists(basePath):
quit("Could not locate datafiles: directory " & basePath & " does not exist.")
var paths: seq[string]
for path in walkDirRec(basePath):
if path.endsWith(".xml"):
@ -76,6 +79,15 @@ when isMainModule:
counts.inc(word, count)
counts.sort()
save(counts, "dictionary.txt", "counts.txt")
let outPath =
if paramCount() > 1:
paramStr(2)
else:
"."
let
dPath = joinPath(outPath, "dictionary.txt")
cPath = joinPath(outPath, "counts.txt")
save(counts, dPath, cPath)
echo "Done. Finished in ", (getMonoTime() - start).inMilliseconds.float / 1000, " seconds."