Exemplo n.º 1
0
 /** Convenience routine taking Strings; lookup is done in SymbolTable. */
 public Method findMethod(String name, String sig) {
   SymbolTable syms = VM.getVM().getSymbolTable();
   Symbol nameSym = syms.probe(name);
   Symbol sigSym = syms.probe(sig);
   if (nameSym == null || sigSym == null) {
     return null;
   }
   return findMethod(nameSym, sigSym);
 }
Exemplo n.º 2
0
 /**
  * Call this function if you want to parse expressions which involve complex numbers. This method
  * specifies "i" as the imaginary unit (0,1). Two functions re() and im() are also added for
  * extracting the real or imaginary components of a complex number respectively.
  *
  * <p>
  *
  * @since 2.3.0 alpha The functions cmod and arg are added to get the modulus and argument.
  * @since 2.3.0 beta 1 The functions complex and polar to convert x,y and r,theta to Complex.
  * @since Feb 05 added complex conjugate conj.
  */
 public void addComplex() {
   // add constants to Symbol Table
   symTab.addConstant("i", new Complex(0, 1));
   funTab.put("re", new Real());
   funTab.put("im", new Imaginary());
   funTab.put("arg", new Arg());
   funTab.put("cmod", new Abs());
   funTab.put("complex", new ComplexPFMC());
   funTab.put("polar", new Polar());
   funTab.put("conj", new Conjugate());
 }
Exemplo n.º 3
0
 /**
  * Gets the object representing the variable with a given name.
  *
  * @param name the name of the variable to find.
  * @return the Variable object or null if name not found.
  * @since 2.3.0 alpha
  */
 public Variable getVar(String name) {
   return symTab.getVar(name);
 }
Exemplo n.º 4
0
 /**
  * Sets the value of a variable. The variable must exist beforehand.
  *
  * @param name name of the variable.
  * @param val the initial value of the variable.
  * @throws NullPointerException if the variable has not been previously created with {@link
  *     #addVariable(String,Object)} first.
  * @since 2.3.0 alpha
  * @since April 05 - throws an exception if variable unset.
  */
 public void setVarValue(String name, Object val) {
   symTab.setVarValue(name, val);
 }
Exemplo n.º 5
0
 /**
  * Returns the value of the variable with given name.
  *
  * @param name name of the variable.
  * @return the current value of the variable.
  * @since 2.3.0 alpha
  */
 public Object getVarValue(String name) {
   return symTab.getVar(name).getValue();
 }
Exemplo n.º 6
0
 /**
  * Removes a variable from the parser. For example after calling addStandardConstants(),
  * removeVariable("e") might be called to remove the euler constant from the set of variables.
  *
  * @return The value of the variable if it was added earlier. If the variable is not in the table
  *     of variables, <code>null</code> is returned.
  */
 public Object removeVariable(String name) {
   return symTab.remove(name);
 }
Exemplo n.º 7
0
 /**
  * Adds a new variable to the parser as an object, or updates the value of an existing variable.
  * This must be done before parsing an expression so the parser is aware that the new variable may
  * be contained in the expression.
  *
  * @param name Name of the variable to be added
  * @param object Initial value or new value for the variable
  */
 public void addVariable(String name, Object object) {
   symTab.makeVarIfNeeded(name, object);
 }
Exemplo n.º 8
0
 /**
  * Adds a new complex variable to the parser, or updates the value of an existing variable. This
  * must be done before parsing an expression so the parser is aware that the new variable may be
  * contained in the expression.
  *
  * @param name Name of the variable to be added
  * @param re Initial real value or new real value for the variable
  * @param im Initial imaginary value or new imaginary value for the variable
  * @return Complex object of the variable
  */
 public Complex addVariable(String name, double re, double im) {
   Complex object = new Complex(re, im);
   symTab.makeVarIfNeeded(name, object);
   return object;
 }
Exemplo n.º 9
0
 /**
  * Adds a new variable to the parser, or updates the value of an existing variable. This must be
  * done before parsing an expression so the parser is aware that the new variable may be contained
  * in the expression.
  *
  * @param name Name of the variable to be added
  * @param value Initial value or new value for the variable
  * @return Double object of the variable
  */
 public Double addVariable(String name, double value) {
   Double object = new Double(value);
   symTab.makeVarIfNeeded(name, object);
   return object;
 }
Exemplo n.º 10
0
 /**
  * Adds a constant. This is a variable whose value cannot be changed.
  *
  * @since 2.3.0 beta 1
  */
 public void addConstant(String name, Object value) {
   symTab.addConstant(name, value);
 }
Exemplo n.º 11
0
 /**
  * Adds the constants pi and e to the parser. As addStandardFunctions(), this method should be
  * called immediately after the JEP object is created.
  */
 public void addStandardConstants() {
   // add constants to Symbol Table
   symTab.addConstant("pi", new Double(Math.PI));
   symTab.addConstant("e", new Double(Math.E));
 }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      address = PAConfiguration.getAddress();
      port = PAConfiguration.getPort(instantiation);
      poslAddress = PAConfiguration.getPOSL(instantiation, topic);
      rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
      messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
      System.exit(0);
    }
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {
      System.out.println("5 Publicty Chair Servlet");
      System.out.println(response.toString());

      BufferedReader brd = request.getReader();

      String input = "";
      String message = "";

      while (!input.equals("</RuleML>")) {

        input = brd.readLine();

        message = message + input;
      }
      String[] varOrder = getVariableOrder(message);
      System.out.println("Received Message: " + message);

      //	BackwardReasoner br = new BackwardReasoner();
      //   Iterator solit =null;
      //   DefiniteClause dc = null;
      //   SymbolTable.reset();

      POSLParser pp = new POSLParser();
      // String contents = "c(a).\nc(b).\nc(c).";

      Date t1 = new GregorianCalendar().getTime();
      System.out.println(t1.getHours() + ":" + t1.getMinutes());
      // append time to contents

      System.out.println("day: " + t1.getDay());
      System.out.println("day: " + t1.getYear());
      System.out.println("day: " + t1.getMonth());

      // time
      String time = "time(" + t1.getHours() + ":integer).";
      System.out.println(time);

      String url = poslAddress;

      // String url = "http://www.jdrew.org/oojdrew/test.posl";
      String contents = "";

      // day of the week
      int day = t1.getDay();
      boolean weekday = true;

      if (day == 0 || day == 6) {
        weekday = false;
      }

      String dayOfWeek;

      if (weekday) {
        dayOfWeek = "day(weekday).";
      } else {
        dayOfWeek = "day(weekend).";
      }
      // full date
      Calendar cal = new GregorianCalendar();

      int year = cal.get(Calendar.YEAR);
      int month = cal.get(Calendar.MONTH) + 1;
      int day2 = cal.get(Calendar.DAY_OF_MONTH);

      String date;

      String day3 = "" + day2;

      if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7
          || day2 == 8 || day2 == 9) {

        day3 = "0" + day2;
      }

      if (month == 10 || month == 11 || month == 12) date = "" + year + month + day3;
      else date = "" + year + "0" + month + day3;

      date = "date(" + date + ":integer).";

      System.out.println(date);

      String url2 = rdfAddress;
      HttpClient client2 = new HttpClient();
      GetMethod method2 = new GetMethod(url2);
      method2.setFollowRedirects(true);
      String typestr = "";
      // Execute the GET method
      int statusCode2 = client2.executeMethod(method2);
      if (statusCode2 != -1) {
        typestr = method2.getResponseBodyAsString();
      }
      System.out.println("Types: " + typestr);
      Types.reset();
      RDFSParser.parseRDFSString(typestr);

      try {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(url);
        method.setFollowRedirects(true);

        // Execute the GET method
        int statusCode = client.executeMethod(method);
        if (statusCode != -1) {
          contents = method.getResponseBodyAsString();
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      contents = contents + "\n" + time;
      contents = contents + "\n" + dayOfWeek;
      contents = contents + "\n" + date;

      BackwardReasoner br = new BackwardReasoner();
      Iterator solit = null;
      DefiniteClause dc = null;
      SymbolTable.reset();

      pp.parseDefiniteClauses(contents);

      br.loadClauses(pp.iterator());
      System.out.println("TEST");
      Iterator it = pp.iterator();
      while (it.hasNext()) {
        DefiniteClause d = (DefiniteClause) it.next();
        System.out.println("Loaded clause: " + d.toPOSLString());
      }

      br = new BackwardReasoner(br.clauses, br.oids);

      MessageParser m = new MessageParser(message);
      Element atom = null;

      try {

        atom = m.parseForContent();

      } catch (Exception e) {

        System.out.println("Invalid Message");
        // out.flush();

      }

      QueryBuilder q = new QueryBuilder(atom);
      String query = q.generateDoc();
      System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
      RuleMLParser qp = new RuleMLParser();

      try {

        dc = qp.parseRuleMLQuery(query);

      } catch (Exception e) {
        System.out.println("Invalid Query");
        // out.flush();
      }

      // solit = br.iterativeDepthFirstSolutionIterator(dc);

      solit = br.iterativeDepthFirstSolutionIterator(dc);

      int varSize = 0;

      while (solit.hasNext()) {

        Vector data = new Vector();

        BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

        Hashtable varbind = gl.varBindings;
        javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
        root.setAllowsChildren(true);

        javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

        int i = 0;
        Object[][] rowdata = new Object[varbind.size()][2];
        varSize = varbind.size();

        Enumeration e = varbind.keys();
        while (e.hasMoreElements()) {
          Object k = e.nextElement();
          Object val = varbind.get(k);
          String ks = (String) k;
          rowdata[i][0] = ks;
          rowdata[i][1] = val;
          i++;
        }

        data.addElement(rowdata);
        String[] messages = new String[data.size()];
        MessageGenerator g =
            new MessageGenerator(
                data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder);
        messages = g.Messages2();

        String appender = "";

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        for (int i1 = 0; i1 < data.size(); i1++) {
          System.out.println(i1 + ")" + messages[i1].toString());
          props.put("text", messages[i1].toString());
          InputStream in = msg.sendGetMessage(props);
        }
        System.out.println("NEXT MESSAGE");
      }

      MessageGenerator g =
          new MessageGenerator(
              null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel());

      URL sender = new URL(address + ":" + port);
      HttpMessage msg = new HttpMessage(sender);
      Properties props = new Properties();

      String finalMessage = g.finalMessage(query);

      System.out.println(finalMessage);

      props.put("text", finalMessage);
      InputStream in = msg.sendGetMessage(props);

      System.out.println("Stop_Communication");

    } catch (Exception e) {
      System.out.println("ERROR has occured : " + e.toString());
    }
    out.close();
  }