示例#1
0
  @SuppressWarnings("deprecation")
  @Override
  public void run() {
    running = true;
    while (running) {
      try {
        String value = in.readLine();

        if (value == null) {
          running = false;
          break;
        }

        String newValue = "";
        // clears the string for errors.
        for (char c : value.toCharArray()) {
          if (c != 0) {
            newValue += c;
          }
        }
        value = newValue;
        LOG.info("Received: " + value);
        Literal l = Literal.parseLiteral(value);
        try {
          l.addSource(ASSyntax.parseTerm("percept"));
        } catch (ParseException ex) {
          LOG.log(Level.SEVERE, "Could not add source", ex);
        }
        pendingBeliefs.add(l);
      } catch (IOException ex) {
        LOG.log(Level.SEVERE, "Could not read BT input.", ex);
      }
    }
  }
  /** @param message Converts Jason Message to a camel Message and add to the exchange */
  public void agentMessaged(Message message) {
    Exchange exchange = endpoint.createExchange();

    if (endpoint.getUriOption().contains("message")) {
      try {
        String ei = endpoint.getIlloc_force();
        String es = endpoint.getSender();
        String er = endpoint.getReceiver();

        // create message header
        HashMap<String, Object> headerInfo = new HashMap<String, Object>();
        String s = message.getSender();
        String r = message.getReceiver();
        String i = message.getIlForce();
        headerInfo.put("sender", s);
        headerInfo.put("receiver", r);
        headerInfo.put("illoc_force", i);
        headerInfo.put("msg_id", message.getMsgId());

        // Extract out any annotations and add as "annotations" header
        try {
          Literal lit = (Literal) message.getPropCont();
          if (lit != null) {
            ListTerm lt = lit.getAnnots();
            if (lt != null) headerInfo.put("annotations", StringUtils.join(lit.getAnnots(), ','));
          } else headerInfo.put("annotations", "");
        } catch (ClassCastException e) {
        }

        // COmpare the message content with uri options
        Matcher matcher = endpoint.getBodyMatcher(message.getPropCont().toString());

        exchange.getIn().setHeaders(headerInfo);

        // send message to next processor in the route after checking route conditions
        if ((i.equals(ei) || ei == null) && (s.equals(es) || es == null)
            || (r.equals(er) || er == null))
          processMatchedMessage(matcher, exchange, message.getPropCont().toString());

      } catch (Exception e) {

      } finally {
        // log exception if an exception occurred and was not handled
        if (exchange.getException() != null)
          getExceptionHandler()
              .handleException("Error processing exchange", exchange, exchange.getException());
        else {
          String ep = endpoint.getExchangePattern().toString();
          if (ep.equals("InOut")) {
            /*
            if (exchange.getOut() != null)
            {
            	Message m = new Message();
            } */
          }
        }
      }
    }
  }
  public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
    try {
      Agent newAg = new Agent();
      newAg.initAg();

      PlanBodyImpl endofplan = null;
      Literal goal = null;

      // ListTerm annots =
      // ListTermImpl.parseList("[scheme(SchId),mission(MissionId),group(GroupId)]");

      // change all inner plans
      for (Plan p : innerContent.getPL()) {
        // create end of plan: .wait
        InternalActionLiteral wait = new InternalActionLiteral(".wait");
        wait.addTerm(directive.getTerm(0));
        endofplan = new PlanBodyImpl(PlanBody.BodyType.internalAction, wait);

        // create end of plan: !!goal[.....]
        // p.getTrigger().getLiteral().addAnnots( (ListTerm)annots.clone());
        goal = p.getTrigger().getLiteral().copy();
        endofplan.add(new PlanBodyImpl(PlanBody.BodyType.achieveNF, goal));

        // add in the end of plan
        p.getBody().add(endofplan);
        newAg.getPL().add(p, false);
      }

      // add failure plan:
      //    -!goto_near_unvisited[scheme(Sch),mission(Mission)]
      //        <- .current_intention(I);
      //           .print("ooo Failure to goto_near_unvisited ",I);
      //           .wait("+pos(_,_,_)"); // wait next cycle
      //           !!goto_near_unvisited[scheme(Sch),mission(Mission)].
      goal = goal.copy();
      goal.addAnnot(ASSyntax.parseStructure("error(EID)"));
      goal.addAnnot(ASSyntax.parseStructure("error_msg(EMsg)"));
      // goal.addAnnot(ASSyntax.parseStructure("code_line(ELine)"));
      String sp =
          "-!"
              + goal
              + " <- .current_intention(I); "
              + ".println(\"ooo Failure in organisational goal "
              + goal.getFunctor()
              + ": \", EID, \" -- \", EMsg); "
              + ".println(\"ooo intention is \",I); "
              + endofplan
              + ".";
      Plan p = ASSyntax.parsePlan(sp);
      newAg.getPL().add(p);
      return newAg;
    } catch (Exception e) {
      logger.log(Level.SEVERE, "OrgMaintenanceGoal directive error.", e);
    }
    return null;
  }
示例#4
0
文件: EnvHello.java 项目: rlucca/Maro
 public boolean executeAction(String agName, Structure act) {
   String actName = act.getFunctor();
   System.out.println("Action " + actName + " received!");
   if (actName.equals("hello")) {
     Literal l = Literal.parseLiteral("world[source(lucca)]");
     addPercept(l);
   }
   if (actName.equals("clean")) {
     clearPercepts();
   }
   return true;
 }
示例#5
0
  /** Called before the MAS execution with the args informed in .mas2j */
  @Override
  public void init(String[] args) {
    super.init(args);

    logger.info("Java version:" + System.getProperty("java.version"));
    logger.info("Java architecture:" + System.getProperty("sun.arch.data.model"));

    try {
      this.model = new TEPRModel();
    } catch (IOException e) {
      addPercept(Literal.parseLiteral("error(\"Could not inatantiate the model\")"));
      e.printStackTrace();
    }
  }
示例#6
0
文件: DummyNlu.java 项目: adri87/Q-A
  public Collection<Literal> call(String... params) {

    String queryid = params[0]; // first param is the queryid
    // second param is the message. Discard in dummy

    Collection<Literal> res = new LinkedList<Literal>();
    res.add(Literal.parseLiteral("cityfrom(madrid)[query(" + queryid + ")]"));
    res.add(Literal.parseLiteral("cityto(barcelona)[query(" + queryid + ")]"));
    res.add(Literal.parseLiteral("ticket(bussiness)[query(" + queryid + ")]"));
    res.add(Literal.parseLiteral("travel(train)[query(" + queryid + ")]"));
    res.add(Literal.parseLiteral("departuretime(10,00)[query(" + queryid + ")]"));
    res.add(Literal.parseLiteral("departureday(8,5,2012)[query(" + queryid + ")]"));

    return res;
  }
 public PropositionImpl(String prop) {
   super(Literal.parseLiteral(prop));
 }