sclass RelBot_Rel { S relation; L things; [stdEq] } sclass RelBot { L categories, things; L> goodOpposites; L> whatIsWhat, whatIsntWhat; L relationNames; L relations; Map> identities; *(ILister l) { categories = l.getList("Categories"); goodOpposites = l.getList("Good opposites"); whatIsWhat = l.getList("What is what"); whatIsntWhat = l.getList("What is not what"); things = l.getList("Things"); relations = l.getList("Relations"); identities = l.getTreeMap("Identities"); } S cat(S s) { setAdd(categories, s); ret s; } S answer(S s) { new Matches m; if "what is *" { S w = $1; L a = pairList_forwardLookup(whatIsWhat, w); L b = pairList_forwardLookup(whatIsntWhat, w); L c = pairList_backwardLookup(whatIsWhat, w); L d = pairList_backwardLookup(whatIsntWhat, w); new L l; if (nempty(a)) l.add(w + " " + isAre(a) + " " + textOut_and(a)); if (nempty(b)) l.add(w + " " + isAre(b) + " not " + textOut_and(b)); if (nempty(c)) l.add(textOut_and(c) + " " + isAre(c) + w); if (nempty(d)) l.add(textOut_and(d) + " " + isAre(d) + " not " + w); ret lines(l); } if "cat *" { setAdd(categories, $1); ret "OK, " + n(categories, "category"); } if "del cat *" { categories.remove($1); ret "OK, " + n(categories, "category"); } if "categories" ret cloneStruct(categories); if "good opposite * *" { setAdd(goodOpposites, pair(cat($1), cat($2))); ret "OK, " + n(goodOpposites, "good opposite"); } if "del good opposite * *" { goodOpposites.remove(pair($1, $2)); ret "OK, " + n(goodOpposites, "good opposite"); } if "good opposites" ret cloneStruct(goodOpposites); if "thing *" { setAdd(things, $1); ret "OK, " + n(things, "thing"); } if "things" ret cloneStruct(things); if "* is *" { setAdd_remove(whatIsWhat, whatIsntWhat, pair($1, $2)); ret "OK, " + n(whatIsWhat, " what is whats"); } if "* is not *|* isn't *" { setAdd_remove(whatIsntWhat, whatIsWhat, pair($1, $2)); ret "OK, " + n(whatIsWhat, " what isn't whats"); } if "forget * isn't *" { remove(whatIsntWhat, pair($1, $2)); ret "OK, " + n(whatIsntWhat, " what isn't whats"); } if "collect things" { collectThings(); ret "OK, " + n(things, 'thing); } if "relation names" ret sfu(relationNames); if "relations" ret lines(map(func(RelBot_Rel r) { relationToText(r) }, relations)); if "rel * ..." { RelBot_Rel rel = nu(RelBot_Rel, relation := $1, things := javaTokC(m.rest())); setAdd(relations, rel); ret "OK: " + relationToText(rel); } if "forget rel * ..." { RelBot_Rel rel = nu(RelBot_Rel, relation := $1, things := javaTokC(m.rest())); remove(relations, rel); ret "OK, " + n(relations, "relation"); } if "identity ..." { L l = javaTokC(m.rest(); L cluster = clusters_add(identities, l); ret "OK, new cluster: " + sfu(cluster); } null; } void collectThings { setAddAllQuick(things, flattenPairs(concatLists(whatIsWhat, whatIsntWhat))); } S relationToText(RelBot_Rel r) { ret quoteIfNotIdentifier(r.relation) + "(" + join(", ", r.things) + ")"; } }