!7 p { L> nodePairs = chatHistory_peepHole_nodePairs(); print("Have " + n(nodePairs, "node pair")); // Analysis new MultiMap index; // left text to right node for (Pair p : nodePairs) { L texts = web_texts(p.a); for (S text : texts) index.setPut(text, p.b); } print("Index size: " + index.keysSize() + " / " + index.size()); MultiSet ms = multiMapAsMultiSet(index); new L outWebs; for (S key : ms.highestFirst()) { L nodes = index.get(key); if (l(nodes) < 2) continue; print(l(nodes) + " - testing key " + key); L common = web_commonTexts(nodes); LL l = map web_texts(nodes); if (nempty(common)) { print(" Always: " + common); outWebs.add(webFromTriples2(key, ll("then", "checked " + n(nodes, "time")), common)); for (L x : l ) x.removeAll(common); } //Pair p = web_mostCommonTextWithCount(nodes); Pair p = mostCommonWithCount(l); if (p != null && p.b > 1) { int percent = ratioToIntPercent(p.b, l(nodes)); print(" Often (" + percent + "%): " + p.a + " (" + p.b + ")"); outWebs.add(webFromTriples2(key, ll("then maybe", "(" + p.b + "/" + n(nodes, "time") + ")"), p.a)); } } print("Made " + n(outWebs, "out web")); //showWeb(last(outWebs)); if (isMain()) showWeb(firstWebContaining(outWebs, "then maybe")); saveGZStructure("peephole-webs.structure.gz", outWebs); }