sclass AI_SubSpace implements AI_PostHandler, AI_CacheChecker { int limit; new MultiMap index; new HashMap websByID; new L webs; *() {} *(int *limit) {} // existence of triple has already been checked public S postTriple(T3 t) { if (limitReached()) fail("Subspace limit reached"); Web web = webFromTriple(t); websByID.put(web.globalID, web); webs.add(web); for (WebNode node : web_nodesAndRelations(web)) for (S text : asSet(node.texts())) index.put(ai_shortenForIndex(text), node); ret web.globalID; } public bool hasTriple(S a, S b, S c) { L webs = ai_withoutInvalidWebs(nodesToWebs(shortestList3( index.get(a), index.get(b), index.get(c)))); ret webs_search_noVar_bool(webFromTriples(a, b, c), webs); } bool limitReached() { ret limit > 0 && l(websByID) >= limit; } L indexedNodes_rawLookup(s) { ret index.get(ai_shortenForIndex(s)); } }