コード例 #1
0
  public DefiniteClause buildResult(Term t) {
    if (t.getSymbol() != sym) {
      return null;
    }

    if (t.subTerms.length != 3) {
      return null;
    }

    Term p1 = t.subTerms[1].deepCopy();
    Term p2 = t.subTerms[2].deepCopy();

    if (p1.getSymbol() < 0 || p2.getSymbol() < 0) {
      return null;
    }

    String p1s = p1.getSymbolString();
    String p2s = p2.getSymbolString();

    /*
     * Kenthor - extension to support untyped number comparison
     */
    boolean allNumber = false;
    if (Pattern.matches("^[-+]?[0-9]*[.]?[0-9]*$", p1s)
        && Pattern.matches("^[-+]?[0-9]*[.]?[0-9]*$", p2s)) {
      allNumber = true;
    }

    if (allNumber
        || ((p1.getType() == Types.IFLOAT || p1.getType() == Types.IINTEGER)
            && (p2.getType() == Types.IFLOAT || p2.getType() == Types.IINTEGER))) {
      // if ((p1.getType() == Types.IFLOAT || p1.getType() == Types.IINTEGER) &&
      //    (p2.getType() == Types.IFLOAT || p2.getType() == Types.IINTEGER)) {
      double d1;
      double d2;
      try {
        d1 = Double.parseDouble(p1s);
        d2 = Double.parseDouble(p2s);
      } catch (Exception e) {
        return null;
      }
      if (d1 > d2) {
        return null;
      }
    } else if (p1.getType() == Types.ISTRING && p2.getType() == Types.ISTRING) {
      if (p1s.compareTo(p2s) > 0) {
        return null;
      }
    } else {
      return null;
    }

    Term roid =
        new Term(
            SymbolTable.internSymbol("$jdrew-lte-" + p1s + "<=" + p2s),
            SymbolTable.IOID,
            Types.ITHING);

    Vector v = new Vector();
    v.add(roid);
    v.add(p1);
    v.add(p2);

    Term atm = new Term(sym, SymbolTable.INOROLE, Types.IOBJECT, v);
    atm.setAtom(true);
    Vector v2 = new Vector();
    v2.add(atm);
    return new DefiniteClause(v2, new Vector());
  }