Transpiled version (2217L) is out of date.
1 | !747 |
2 | |
3 | m { |
4 | static new SnippetDB db; |
5 | |
6 | !include #1000989 // SnippetDB |
7 | !include #1000988 // MultiSet |
8 | |
9 | p { |
10 | db.importMySQLDump(gunzipToText("#1000673")); |
11 | |
12 | List<List<S>> rows = db.rowsOrderedBy("sn_created"); |
13 | int i = 0; |
14 | while (i < 3) { |
15 | S text = db.getField(rows.get(i), "sn_text"); |
16 | print(text + "\n==\n"); |
17 | ++i; |
18 | } |
19 | |
20 | /*for (int i = 0; i < Math.min(rows.size(), 10); i++) |
21 | print(db.getField(rows.get(i), "sn_id"));*/ |
22 | } |
23 | |
24 | static L<S> parse(S s) { |
25 | return javaTok(s); |
26 | } |
27 | |
28 | static S complete(S sentence1, S sentence2) { |
29 | L<S> tok1 = parse(sentence1); |
30 | L<S> tok2 = parse(sentence2); |
31 | Map<S, MultiSet<S>> map = makeMMapPrefix(tok1, tok2); |
32 | if (map == null) return null; |
33 | new L<S> tok; |
34 | tok.addAll(tok2.subList(0, tok2.size()-1)); |
35 | for (int i = tok2.size()-1; i < tok1.size(); i++) { |
36 | S t = tok1.get(i); |
37 | MultiSet<S> set = map.get(t); |
38 | tok.add(set == null ? t : set.getMostPopularEntry()); |
39 | } |
40 | return join(tok); |
41 | } |
42 | |
43 | static Map<S, MultiSet<S>> makeMMapPrefix(L<S> tok1, L<S> tok2) { |
44 | if (tok1.size() < tok2.size()) return null; |
45 | |
46 | Map<S, MultiSet<S>> map = new TreeMap<S, MultiSet<S>>(); |
47 | for (int i = 1; i < tok2.size(); i += 2) { |
48 | S t1 = tok1.get(i), t2 = tok2.get(i); |
49 | MultiSet<S> set = map.get(t1); |
50 | if (set == null) |
51 | map.put(t1, new MultiSet<S>(t2)); |
52 | else |
53 | set.add(t2); |
54 | } |
55 | |
56 | // match succeeds |
57 | return map; |
58 | } |
59 | } |
Began life as a copy of #1000987
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000990 |
Snippet name: | Predict snippet continuation according to previous snippets (developing) |
Eternal ID of this version: | #1000990/1 |
Text MD5: | 5b75aceceee537fd287d5eeb95bd21af |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-09-14 17:50:35 |
Source code size: | 1542 bytes / 59 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 586 / 600 |
Referenced in: | [show references] |