// TODO static class CodePatterns extends P { Map<L<S>,S> map = new HashMap<L<S>,S>(); int n; *(int *n) { } S read(S file, L<S> tok) { prepare(file); while (tok.size() > seen) { ++seen; if (seen > n) put(new ArrayList<S>(tok.subList(seen-n-1, seen-1)), tok.get(seen-1)); } if (tok.size() >= n) { L<S> l = new ArrayList<S>(tok.subList(tok.size()-n, tok.size())); for (L<S> pl : map.keySet()) { S pr = map.get(pl); print("pl: " + structure(pl) + ", l: " + structure(l)); Map<S, S> m = makeMapPrefix(pl, l); if (m != null) { S result = m.get(pr); print("map: " + structure(m) + ", result: " + quote(result)); ret result; } } } return null; } void put(L<S> l, S r) { if (isPattern(l, r)) { new L<S> l2; l2.addAll(l); l2.add(r); print("pattern: " + structure(l2)); map.put(l, r); } } boolean isPattern(L<S> l, S r) { /*new Set<S> set; set.addAll(l); set.add(r); return set.size() < l.size()+1;*/ return l.contains(r) && interestingToken(r); } boolean interestingToken(S r) { //return !r.trim().equals(""); for (int i = 0; i < r.length(); i++) if (Character.isLetter(r.charAt(i))) ret true; ret false; } P derive() { Patterns t = new Patterns(n); t.map = new DerivedHashMap<L<S>,S>(map); return t; } P clear() { return new Patterns(n); } }
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001035 |
Snippet name: | CodePatterns (predictor) |
Eternal ID of this version: | #1001035/1 |
Text MD5: | 50aab9d9c36b603126789cbbe3ff4e73 |
Author: | stefan |
Category: | |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-09-16 21:04:23 |
Source code size: | 1607 bytes / 71 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 702 / 614 |
Referenced in: | #1001036 - LastWordToLower (predictor) #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |