Rewrite transpile script with better memory usage
authornickolas360 <nickolas360@users.noreply.github.com>
Sat, 12 Nov 2016 09:57:41 +0000 (09:57 +0000)
committernickolas360 <nickolas360@users.noreply.github.com>
Sat, 12 Nov 2016 09:57:41 +0000 (09:57 +0000)
transpile.js [deleted file]
transpile.py [new file with mode: 0755]

diff --git a/transpile.js b/transpile.js
deleted file mode 100644 (file)
index d0c2cf6..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/* translate second order JSON markov chain to delimited text files */
-
-const fs = require("fs"),
-      chain = JSON.parse(fs.readFileSync(process.argv[2]).toString());
-
-var out = [];
-
-Object.keys(json).forEach(A => Object.keys(json[A]).forEach(B => Object.keys(json[A][B]).forEach(C => {
-    out.push(`${A} ${B} ${C} ${json[A][B][C]}`)
-})));
-
-console.log(out.join("\n"));
diff --git a/transpile.py b/transpile.py
new file mode 100755 (executable)
index 0000000..039959a
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env python3
+import json
+import sys
+
+with open(sys.argv[1]) as f:
+    markov_dict = json.load(f)
+for first, first_dict in markov_dict.items():
+    for second, second_dict in first_dict.items():
+        for third, count in second_dict.items():
+            print(first, second, third, count)
This page took 0.027676 seconds and 4 git commands to generate.