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

54
LINES

< > BotCompany Repo | #1022965 // AI_WhatIsBot

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (7096L/47K).

sclass AI_WhatIsBot > AttractorBot {
  IDefinitions definitionsModule;
  
  public void run {
    say("I can learn and tell you what things are");
  }
  
  // CONFIG
  
  class WhatIsAttractor > Attractor {
    S term;
    
    public bool matches(S s) {
      new Matches m;
      if "what is ..."
        ret true with term = $1;
      false;
    }
    
    public void run {
      if (definitionsModule != null) {
        Collection<S> defs = definitionsModule.getDefinitions(term);
        if (nempty(defs)) {
          say(term + " is " + random(defs));
          // TODO: attractors
          ret;
        }
      }
      say("I don't know. What is " + quote(term) + "?");
      lowPrioAttractor(new DefinitionAttractor(term));
    }
  }
  
  record DefinitionAttractor(S term) extends Attractor {
    S value;
    
    public bool matches(S s) {
      new Matches m;
      if "it's ...|it is...|he is...|she is..."
        ret true with value = $1;
      false;
    }
    
    public void run {
      say("OK. " + term + " is " + value + ".");
      if (definitionsModule != null)
        definitionsModule.addDefinition(term, value);
    }
  }
  
  *() {
    standardAttractors(new WhatIsAttractor);
  }
}

Author comment

Began life as a copy of #1022843

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022965
Snippet name: AI_WhatIsBot
Eternal ID of this version: #1022965/10
Text MD5: fe9328894adc7f323cf6a2dca3a705ca
Transpilation MD5: 9fb7ddf738bf106200a6c0c9224a97a5
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-16 16:56:38
Source code size: 1266 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 224 / 696
Version history: 9 change(s)
Referenced in: [show references]