Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

99
LINES

< > BotCompany Repo | #1009474 // RelBot

JavaX fragment (include)

1  
sclass RelBot_Rel {
2  
  S relation;
3  
  L<S> things;
4  
  
5  
  [stdEq]
6  
}
7  
8  
sclass RelBot {
9  
  L<S> categories, things;
10  
  L<Pair<S>> goodOpposites;
11  
  L<Pair<S>> whatIsWhat, whatIsntWhat;
12  
  L<S> relationNames;
13  
  L<RelBot_Rel> relations;
14  
  Map<S, L<S>> identities;
15  
16  
  *(ILister l) {
17  
    categories = l.getList("Categories");
18  
    goodOpposites = l.getList("Good opposites");
19  
    whatIsWhat = l.getList("What is what");
20  
    whatIsntWhat = l.getList("What is not what");
21  
    things = l.getList("Things");
22  
    relations = l.getList("Relations");
23  
    identities = l.getTreeMap("Identities");
24  
  }
25  
26  
  S cat(S s) { setAdd(categories, s); ret s; }
27  
28  
  S answer(S s) {
29  
    new Matches m;
30  
    if "what is *" {
31  
      S w = $1;
32  
      L<S> a = pairList_forwardLookup(whatIsWhat, w);
33  
      L<S> b = pairList_forwardLookup(whatIsntWhat, w);
34  
      L<S> c = pairList_backwardLookup(whatIsWhat, w);
35  
      L<S> d = pairList_backwardLookup(whatIsntWhat, w);
36  
      new L<S> l;
37  
      if (nempty(a)) l.add(w + " " + isAre(a) + " " + textOut_and(a));
38  
      if (nempty(b)) l.add(w + " " + isAre(b) + " not " + textOut_and(b));
39  
      if (nempty(c)) l.add(textOut_and(c) + " " + isAre(c) + w);
40  
      if (nempty(d)) l.add(textOut_and(d) + " " + isAre(d) + " not " + w);
41  
      ret lines(l);
42  
    }
43  
    
44  
    if "cat *" { setAdd(categories, $1); ret "OK, " + n(categories, "category"); }
45  
    if "del cat *" { categories.remove($1); ret "OK, " + n(categories, "category"); }
46  
    if "categories" ret cloneStruct(categories);
47  
    
48  
    if "good opposite * *" { setAdd(goodOpposites, pair(cat($1), cat($2))); ret "OK, " + n(goodOpposites, "good opposite"); }
49  
    if "del good opposite * *" { goodOpposites.remove(pair($1, $2)); ret "OK, " + n(goodOpposites, "good opposite"); }
50  
    if "good opposites" ret cloneStruct(goodOpposites);
51  
    
52  
    if "thing *" { setAdd(things, $1); ret "OK, " + n(things, "thing"); }
53  
    if "things" ret cloneStruct(things);
54  
    
55  
    if "* is *" {
56  
      setAdd_remove(whatIsWhat, whatIsntWhat, pair($1, $2));
57  
      ret "OK, " + n(whatIsWhat, " what is whats");
58  
    }
59  
    if "* is not *|* isn't *" {
60  
      setAdd_remove(whatIsntWhat, whatIsWhat, pair($1, $2));
61  
      ret "OK, " + n(whatIsWhat, " what isn't whats");
62  
    }
63  
    if "forget * isn't *" {
64  
      remove(whatIsntWhat, pair($1, $2));
65  
      ret "OK, " + n(whatIsntWhat, " what isn't whats");
66  
    }
67  
    if "collect things" { collectThings(); ret "OK, " + n(things, 'thing); }
68  
    
69  
    if "relation names" ret sfu(relationNames);
70  
    if "relations" ret lines(map(func(RelBot_Rel r) { relationToText(r) }, relations));
71  
    
72  
    if "rel * ..." {
73  
      RelBot_Rel rel = nu(RelBot_Rel, relation := $1, things := javaTokC(m.rest()));
74  
      setAdd(relations, rel);
75  
      ret "OK: " + relationToText(rel);
76  
    }
77  
    if "forget rel * ..." {
78  
      RelBot_Rel rel = nu(RelBot_Rel, relation := $1, things := javaTokC(m.rest()));
79  
      remove(relations, rel);
80  
      ret "OK, " + n(relations, "relation");
81  
    }
82  
    
83  
    if "identity ..." {
84  
      L<S> l = javaTokC(m.rest();
85  
      L<S> cluster = clusters_add(identities, l);
86  
      ret "OK, new cluster: " + sfu(cluster);
87  
    }
88  
    
89  
    null;
90  
  }
91  
92  
  void collectThings {
93  
    setAddAllQuick(things, flattenPairs(concatLists(whatIsWhat, whatIsntWhat)));
94  
  }
95  
  
96  
  S relationToText(RelBot_Rel r) {
97  
    ret quoteIfNotIdentifier(r.relation) + "(" + join(", ", r.things) + ")";
98  
  }
99  
}

Author comment

Began life as a copy of #1009469

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: #1009474
Snippet name: RelBot
Eternal ID of this version: #1009474/7
Text MD5: 9cfeeee7fa2aa01dccf4fada9b5c8c40
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-04 16:45:43
Source code size: 3440 bytes / 99 lines
Pitched / IR pitched: No / No
Views / Downloads: 503 / 1097
Version history: 6 change(s)
Referenced in: [show references]