1 | sclass ActualThoughtSpace extends AbstractThoughtSpace { |
2 | new TripleIndex index; |
3 | int limit; // 0 = no limit |
4 | L<Triple<S>> blockedPatterns = listWithNotify(r { blocked.clear(); }); |
5 | Map<TripleWeb, Bool> blocked = newWeakHashMap(); |
6 | |
7 | *() {} |
8 | *(int *limit) {} |
9 | *(AbstractThoughtSpace parent) { super(parent); } |
10 | |
11 | // existence of triple has already been checked |
12 | public GlobalID postTriple(T3<S> t) { |
13 | if (limitReached()) fail("Thought space limit reached"); |
14 | TripleWeb w = tripleWeb(t); |
15 | index.addTriple(w); |
16 | ret w.globalID(); |
17 | } |
18 | |
19 | bool limitReached() { |
20 | ret limit > 0 && size() >= limit; |
21 | } |
22 | |
23 | L<TripleRef<S>> get(S s) { |
24 | ret ai_triplesToTripleRefs_lazyList(s, getTriples(s)); |
25 | } |
26 | |
27 | L<TripleWeb> getTriples(S s) { |
28 | L<TripleWeb> l = filterNonBlockedTriples(parent.getTriples(s)); |
29 | ret combineLists(l, index.getTriples(ai_shortenForIndex(s))); |
30 | } |
31 | |
32 | L<TripleRef<S>> filterNonBlocked(L<TripleRef<S>> l) { |
33 | if (empty(blockedPatterns)) ret l; |
34 | L<TripleRef<S>> out = emptyListWithCapacity(l); |
35 | for (TripleRef<S> ref : l) |
36 | if (!isBlocked((TripleWeb) ref.triple)) |
37 | out.add(ref); |
38 | ret out; |
39 | } |
40 | |
41 | L<TripleWeb> filterNonBlockedTriples(L<TripleWeb> l) { |
42 | if (empty(blockedPatterns)) ret l; |
43 | L<TripleWeb> out = emptyListWithCapacity(l); |
44 | for (TripleWeb w : l) |
45 | if (!isBlocked(w)) |
46 | out.add(w); |
47 | ret out; |
48 | } |
49 | |
50 | bool isBlocked(TripleWeb t) { |
51 | Bool b = blocked.get(t); |
52 | if (b != null) ret b; |
53 | b = false; |
54 | for (T3<S> pat : blockedPatterns) |
55 | if (simpleMatchTriple_dollarVars(pat, t) != null) { |
56 | b = true; |
57 | break; |
58 | } |
59 | blocked.put(t, b); |
60 | ret b; |
61 | } |
62 | |
63 | int size() { ret index.size(); } |
64 | } |
Began life as a copy of #1012640
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: | #1012676 |
Snippet name: | ActualThoughtSpace with original blocking (very flexible but slow) |
Eternal ID of this version: | #1012676/3 |
Text MD5: | 5922e919b7fb84edc1974256f702b39e |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-12-10 02:53:14 |
Source code size: | 1774 bytes / 64 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 429 / 633 |
Version history: | 2 change(s) |
Referenced in: | [show references] |