Пример #1
0
  /** Output the vertex to text. */
  public void output(Vertex output) {
    if (!isEnabled()) {
      return;
    }

    Vertex sense = output.mostConscious(Primitive.SENSE);
    // If not output to IRC, ignore.
    if ((sense == null) || (!getPrimitive().equals(sense.getData()))) {
      return;
    }
    try {
      if (getChannel() != null) {
        log("Output:", Bot.FINE, output);
        getChannel().sendMessage(printInput(output) + "\n");
        for (ChannelListener listener : getChannelListeners()) {
          ChannelEvent event =
              new ChannelEvent(getChannel(), getNick(), getUserName(), printInput(output));
          listener.onMessage(event);
        }
        this.lastUsers.remove(0);
        this.lastUsers.add(getNick());
      }
    } catch (Exception exception) {
      log(exception);
    }
  }
Пример #2
0
 /** Set the current conversation. */
 public void setConversation(Vertex conversation) {
   if (conversation == null) {
     this.conversation = null;
   } else {
     this.conversation = conversation.getId();
   }
 }
Пример #3
0
 /** Process the text sentence. */
 public void inputSentence(
     String text, String userName, List<String> targetUserNames, Network network) {
   Vertex input = createInputSentence(text.trim(), network);
   input.addRelationship(Primitive.INSTANTIATION, Primitive.CHAT);
   // Process speaker.
   Vertex user = network.createSpeaker(userName);
   input.addRelationship(Primitive.SPEAKER, user);
   // Process target speakers.
   Set<String> uniqueTargetUserNames = new HashSet<String>();
   for (String targetUserName : targetUserNames) {
     if (!targetUserName.equals(userName) && !uniqueTargetUserNames.contains(targetUserName)) {
       uniqueTargetUserNames.add(targetUserName);
       Vertex targetUser = null;
       if (targetUserName.equals(getNick()) || targetUserName.equals(getNickAlt())) {
         targetUser = network.createVertex(Primitive.SELF);
       } else {
         targetUser = network.createSpeaker(targetUserName);
       }
       input.addRelationship(Primitive.TARGET, targetUser);
     }
   }
   user.addRelationship(Primitive.INPUT, input);
   // Process conversation.
   Vertex conversation = getConversation(network);
   if (conversation == null) {
     conversation = network.createInstance(Primitive.CONVERSATION);
     conversation.addRelationship(Primitive.TYPE, Primitive.CHAT);
     setConversation(conversation);
     conversation.addRelationship(Primitive.SPEAKER, Primitive.SELF);
     for (String eachUser : getUsers()) {
       conversation.addRelationship(Primitive.SPEAKER, network.createSpeaker(eachUser));
     }
   }
   Language.addToConversation(input, conversation);
   network.save();
   getBot().memory().addActiveMemory(input);
 }