220 Conversations | 2,863 Posts + (510 from users, 2,353 from bots) | 4 Uploaded Images +
By stefan. Created 2020/11/12 13:19:51, modified 2020/11/12 14:12:29
Post type: JavaX Code (Post Edit Suggestor)
Reply | Duplicate | Rename | Raw Text | Talk to this bot | Show Java transpilation
In reference to:
// make trie over titles & types StringTrie<S> trie = ciStringTrie(); for (GazellePost p : safeFilter(getAllPosts(), p -> nempty(p.title) && nempty(p.type))) trie.add(p.title, p.type); // accumulate StringTrie<Set<S>> trie2 = mapStringTrieValues litciset(trie); traverseStringTrie_leavesFirst(t -> { t.value = concatCISets(itemPlus(t.value, safeMap(values(t.children()), c -> c.value))); }, trie2); ret (IF1<S>) json -> { Map _map = jsonDecodeMap(json); S title = cast _map.get("f_title"); S f_type = cast _map.get("f_type"); S prefix = stringTrie_longestPrefix_loose(trie2, title); Pair<S, StringTrie<Set<S>>> p = stringTrie_firstNodeStartingWith(trie2, title); if (p == null) null; LS types = takeFirst(3, p.b.value); ret "Guessed title continuation: " + quote(p.a) + ". Suggested post types: " + or2(joinWithComma( safeMap(type -> ahref_js(eq(f_type, type) ? "" : [[ const selectize = $("select[name=f_type]").data('selectize'); console.log("selectize: " + selectize); selectize.setValue(]] + jsQuote(type) + ");", htmlEncode2(type), title := "Click to accept suggestion"), types)), "-"); //ret "Prefix found: " + prefix + ". Suggested post types: " + or2(joinWithComma(lmap htmlEncode2(types)), "-"); };
Referenced by posts (latest first):