1 | sclass ActualThoughtSpace extends AbstractThoughtSpace implements AutoCloseable { |
2 | new TripleIndex index; |
3 | int limit; // 0 = no limit |
4 | Map<TripleWeb, Bool> blocked = newWeakHashMap(); |
5 | Set<Symbol> blockedA, blockedB; |
6 | |
7 | *() {} |
8 | *(int *limit) {} |
9 | *(AbstractThoughtSpace parent) { super(parent); } |
10 | |
11 | public GlobalID postTriple(T3<Symbol> t, bool verified) { |
12 | print("Posting: " + t + " / " + verified); |
13 | if (limitReached()) fail("Thought space limit reached"); |
14 | TripleWeb w = tripleWeb(t); |
15 | w.verified(verified); |
16 | index.addTriple(w); |
17 | ret w.globalID(); |
18 | } |
19 | |
20 | // existence of triple has already been checked |
21 | public GlobalID postTriple(T3<Symbol> t) { |
22 | if (limitReached()) fail("Thought space limit reached"); |
23 | TripleWeb w = tripleWeb(t); |
24 | index.addTriple(w); |
25 | ret w.globalID(); |
26 | } |
27 | |
28 | bool limitReached() { |
29 | ret limit > 0 && size() >= limit; |
30 | } |
31 | |
32 | /*public bool hasTriple(Symbol a, Symbol b, Symbol c) { |
33 | ret index.getExact(a, b, c) != null; |
34 | }*/ |
35 | |
36 | L<TripleRef<Symbol>> get(Symbol s) { |
37 | ret ai_triplesToTripleRefs_lazyList(s, getTriples(s)); |
38 | } |
39 | |
40 | L<TripleRef<Symbol>> get(Symbol s, int position) { |
41 | ret ai_triplesToTripleRefs_lazyList(s, getTriples(s, position)); |
42 | } |
43 | |
44 | L<TripleWeb> getTriples(Symbol s) { |
45 | L<TripleWeb> l = parent == null ? null : filterNonBlockedTriples_lazy(parent.getTriples(s)); |
46 | ret combineLists(l, index.getTriples(ai_shortenForIndex(s))); |
47 | } |
48 | |
49 | L<TripleWeb> getTriples(Symbol s, int position) { |
50 | L<TripleWeb> l = parent == null ? null : filterNonBlockedTriples_lazy(parent.getTriples(s, position)); |
51 | ret combineLists(l, index.getTriples(ai_shortenForIndex(s), position)); |
52 | } |
53 | |
54 | L<TripleWeb> getOneTwo(Symbol a, Symbol b) { |
55 | ret index.getOneTwo(a, b); |
56 | } |
57 | |
58 | L<TripleWeb> filterNonBlockedTriples_lazy(final L<TripleWeb> l) { |
59 | class FilterList extends LazyList<TripleWeb> { |
60 | final int n = l(l); |
61 | public int size() { ret n; } |
62 | public TripleWeb get(int i) { |
63 | TripleWeb w = syncGet(l, i); |
64 | if (w != null && isBlocked(w)) null; |
65 | ret w; |
66 | } |
67 | } |
68 | ret new FilterList; |
69 | } |
70 | |
71 | L<TripleWeb> filterNonBlockedTriples(L<TripleWeb> l) { |
72 | if (empty(blockedA) && empty(blockedB)) ret l; |
73 | L<TripleWeb> out = emptyListWithCapacity(l); |
74 | for (TripleWeb w : l) |
75 | if (!isBlocked(w)) |
76 | out.add(w); |
77 | ret out; |
78 | } |
79 | |
80 | bool isBlocked(TripleWeb t) { |
81 | ret contains(blockedA, t.a) || contains(blockedB, t.b); |
82 | } |
83 | |
84 | int size() { ret index.size(); } |
85 | |
86 | public void close() { |
87 | thoughtSpaceDone(this); |
88 | } |
89 | |
90 | Collection<TripleWeb> allTriples() { ret index.allTriples(); } |
91 | |
92 | void setBlockedA(Collection<? extends CharSequence> l) { |
93 | blockedA = asSymbolSet(allToSymbol(l)); |
94 | } |
95 | } |
Began life as a copy of #1012051
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: | #1012640 |
Snippet name: | ActualThoughtSpace [LIVE] |
Eternal ID of this version: | #1012640/42 |
Text MD5: | 5e3033968fdab463f6684128c8d26f02 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-01-13 21:13:29 |
Source code size: | 2847 bytes / 95 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 522 / 1096 |
Version history: | 41 change(s) |
Referenced in: | [show references] |