[237846] Suggest Post Type From Title Trie [shortened]

229 Conversations | 2,863 Posts + (510 from users, 2,353 from bots) | 4 Uploaded Images +

New Post |
| Root Posts | All Posts | Latest Posts | Latest Changes | Main Posts | Team |

By stefan. Created 2020/11/19 13:15:19, modified 2020/11/19 13:24:30

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 prefix = stringTrie_longestPrefix_loose(trie2, title);
  Pair<S, StringTrie<Set<S>>> p = stringTrie_firstNodeStartingWith(trie2, title);
  if (p == null) null;
  ret "Guessed title continuation: " + quote(p.a) + ". " + gazelleBot_suggestPostTypes(p.b.value, _map, true);
};

Referenced by posts (latest first):