Package net.sf.kpex.prolog

Examples of net.sf.kpex.prolog.Term


  {
    if (null == C)
    {
      return null;
    }
    Term Vs = C.varsOf();
    Clause SuperC = new Clause(Vs, C);
    SuperC.dict = C.dict;
    Clause NamedSuperC = SuperC.cnumbervars(false);
    Term Ns = NamedSuperC.getHead();
    Term NamedC = NamedSuperC.getBody();
    return new Fun("clause", C, Vs, NamedC, Ns);
  }
View Full Code Here


   * Removes a matching Term from the blackboards and signals failure if no
   * such term is found.
   */
  public Term cin(String k, Term pattern)
  {
    Term found = take(k, pattern);
    // if(found!=null) {
    // found=found.matching_copy(pattern);
    // }
    if (found == null)
    {
      found = Const.NO;
    }
    else
    {
      found = new Fun("the", found.copy());
    }
    return found;
  }
View Full Code Here

    {
      return Const.NIL;
    }
    Fun R = new Fun("$", To.size());
    To.copyInto(R.args);
    Term T = ((Cons) R.listify()).args[1];
    return T;
  }
View Full Code Here

   * first solution to the query or "no" if no such solution exists
   */
  public static String askJinni(String query)
  {
    Clause Goal = getGoal(query);
    Term Body = Goal.getBody();
    return askJinni(Body).prettyPrint();
  }
View Full Code Here

   * evalutes a query
   */
  public static void evalGoal(Clause Goal)
  {
    Clause NamedGoal = Goal.cnumbervars(false);
    Term Names = NamedGoal.getHead();
    if (!(Names instanceof Fun))
    { // no vars in Goal
      Term Result = Prog.firstSolution(Goal.getHead(), Goal.getBody());
      if (!Const.NO.eq(Result))
      {
        Result = Const.YES;
      }
      IO.println(Result.toString());
      return;
    }

    Prog E = new Prog(Goal, null);

    for (int i = 0;; i++)
    {
      Term R = Prog.ask_engine(E);
      // IO.mes("GOAL:"+Goal+"\nANSWER: "+R);
      if (R == null)
      {
        IO.println("no");
        break;
      }
      if (Names instanceof Fun)
      {
        Fun NamedR = (Fun) R.numberVars();
        for (int j = 0; j < Names.getArity(); j++)
        {
          IO.println(((Fun) Names).getArg(j) + "=" + NamedR.getArg(j));
        }
        // IO.println(";");
View Full Code Here

  protected Term next() throws IOException
  {
    int n = nextToken();
    inClause = true;
    Term T;
    switch (n)
    {
      case TT_WORD:
        T = getWord(false);
        break;
View Full Code Here

    return Character.toString((char) c);
  }

  private Term getWord(boolean quoted) throws IOException
  {
    Term T;
    if (quoted && 0 == sval.length())
    {
      T = makeConst("");
    }
    else
View Full Code Here

    return new IntToken((int) n);
  }

  private final Term makeNumber(double nval)
  {
    Term T;
    if (Math.floor(nval) == nval)
    {
      T = makeInt(nval);
    }
    else
View Full Code Here

  @Override
  public int exec(Prog p)
  {
    Sink S = (Sink) getArg(0);
    Term X = getArg(1);
    if (0 == S.putElement(X))
    {
      IO.errmes("error in putElement: " + X);
    }
    return 1;
View Full Code Here

   * @see net.sf.kpex.prolog.FunBuiltin#exec(net.sf.kpex.prolog.Prog)
   */
  @Override
  public int exec(Prog p)
  {
    Term Cs = ((Nonvar) getArg(0)).toChars();
    return putArg(1, Cs, p);
  }
View Full Code Here

TOP

Related Classes of net.sf.kpex.prolog.Term

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.