public DefiniteClause buildResult(Term t) { if (t.getSymbol() != symbol) { return null; } if (t.subTerms.length != 3) { return null; } Term p2 = t.subTerms[2].deepCopy(); if (p2.getSymbol() < 0) { return null; } if (p2.getType() != Types.IFLOAT && p2.getType() != Types.IINTEGER) { return null; } String p2s = p2.getSymbolString(); double p2d; try { p2d = Double.parseDouble(p2s); } catch (Exception e) { return null; } double result = Math.tan(p2d); String results = "" + result; Term r1 = new Term(SymbolTable.internSymbol(results), SymbolTable.INOROLE, Types.IFLOAT); Term roid = new Term(SymbolTable.internSymbol("$jdrew-tan-" + p2s), SymbolTable.IOID, Types.ITHING); Vector v = new Vector(); v.add(roid); v.add(r1); v.add(p2); Term atm = new Term(symbol, SymbolTable.INOROLE, Types.IOBJECT, v); atm.setAtom(true); Vector v2 = new Vector(); v2.add(atm); return new DefiniteClause(v2, new Vector()); }
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(); 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()); }