static int ai_writeTripleFile(Collection triples, OutputStream out) ctex { print("Writing triple file"); new L names; new Map index; ai_writeTripleFile_precollectNames(names, index, triples); new ByteArrayOutputStream baos; PrintWriter writer = utf8printWriter(baos); int n = 0; for (TripleWeb w : triples) { ++n; S title = null; S moreInfo = quote(str(w.globalID())) + " " + quote(unnull(title)) + " " + quote(unnull(w.source())) + " " + (w.unverified() ? "u" : "v") + " " + w.created(); O result = w.result(); if (result != null) moreInfo += " (" + sfu(result) + ")"; writer.write( ai_writeTripleFile_indexGet(names, index, w.a) + " " + ai_writeTripleFile_indexGet(names, index, w.b) + " " + ai_writeTripleFile_indexGet(names, index, w.c) + " " + moreInfo + "\n"); } writer.flush(); //out.println(struct(names)); print("Have " + n2(names, "name") + ", " + toM(baos.size()) + "M buffered bytes"); PrintWriter writer2 = utf8printWriter(out); for (S s : names) writer2.println(quoteUnlessIdentifierOrInteger(s)); writer2.println(); writer2.flush(); baos.writeTo(out); ret n; } static int ai_writeTripleFile_indexGet(L names, Map index, S s) { Int i = index.get(s); if (i == null) { i = l(names); names.add(s); index.put(s, i); } ret i; } static void ai_writeTripleFile_precollectNames(L names, Map index, Collection triples) { for (TripleWeb w : triples) { ai_writeTripleFile_indexGet(names, index, w.a); ai_writeTripleFile_indexGet(names, index, w.b); ai_writeTripleFile_indexGet(names, index, w.c); } sortInPlaceIC(names); index.clear(); for i over names: index.put(names.get(i), i); }