Package jp.ac.kobe_u.cs.prolog.lang

Examples of jp.ac.kobe_u.cs.prolog.lang.SymbolTerm


      Term car = ((ListTerm) tmp).car().dereference();
      if (car.isVariable()) {
        throw new PInstantiationException(this, 2);
      }
      if (car.isStructure()) {
        SymbolTerm functor = ((StructureTerm) car).functor();
        Term[] args = ((StructureTerm) car).args();
        if (functor.equals(SYM_FORCE_1)) {
          Term bool = args[0].dereference();
          if (bool.equals(SYM_TRUE)) {
            forceFlag = true;
          } else if (bool.equals(SYM_FALSE)) {
            forceFlag = false;
          } else {
            throw new IllegalDomainException(this, 2,
                "close_option", car);
          }
        } else {
          throw new IllegalDomainException(this, 2, "close_option",
              car);
        }
      } else {
        throw new IllegalDomainException(this, 2, "close_option", car);
      }
      tmp = ((ListTerm) tmp).cdr().dereference();
    }
    // stream
    a1 = a1.dereference();
    if (a1.isVariable()) {
      throw new PInstantiationException(this, 1);
    } else if (a1.isSymbol()) {
      if (!engine.getStreamManager().containsKey(a1)) {
        throw new ExistenceException(this, 1, "stream", a1, "");
      }
      stream = ((JavaObjectTerm) engine.getStreamManager().get(a1))
          .object();
    } else if (a1.isJavaObject()) {
      stream = ((JavaObjectTerm) a1).object();
    } else {
      throw new IllegalDomainException(this, 1, "stream_or_alias", a1);
    }
    if (stream instanceof PushbackReader) {
      PushbackReader in = (PushbackReader) stream;
      if (in.equals(engine.getUserInput())) {
        return cont;
      }
      if (in.equals(engine.getCurrentInput())) {
        engine.setCurrentInput(engine.getUserInput());
      }
      try {
        in.close();
      } catch (IOException e) {
        throw new TermException(new JavaObjectTerm(e));
      }
    } else if (stream instanceof PrintWriter) {
      PrintWriter out = (PrintWriter) stream;
      if (out.checkError()) {
        if (!forceFlag) {
          throw new SystemException("output stream error");
        }
      }
      out.flush();
      if (out.equals(engine.getUserOutput())
          || out.equals(engine.getUserError())) {
        return cont;
      }
      if (out.equals(engine.getCurrentOutput())) {
        engine.setCurrentOutput(engine.getUserOutput());
      }
      out.close();
    } else {
      throw new IllegalDomainException(this, 1, "stream_or_alias", a1);
    }
    // delete associated entries from the stream manager
    HashMapOfTerm streamManager = engine.getStreamManager();
    if (a1.isSymbol()) {
      streamManager.remove(engine.getStreamManager().get(a1));
      streamManager.remove(a1);
    } else if (a1.isJavaObject()) {
      Term tmp2 = streamManager.get(a1);
      while (!tmp2.isNil()) {
        Term car = ((ListTerm) tmp2).car().dereference();
        if (car.isStructure()) {
          SymbolTerm functor = ((StructureTerm) car).functor();
          Term[] args = ((StructureTerm) car).args();
          if (functor.equals(SYM_ALIAS_1)) {
            Term alias = args[0].dereference();
            streamManager.remove(alias);
          }
        }
        tmp2 = ((ListTerm) tmp2).cdr().dereference();
View Full Code Here


      Term car = ((ListTerm) tmp).car().dereference();
      if (car.isVariable()) {
        throw new PInstantiationException(this, 2);
      }
      if (car.isStructure()) {
        SymbolTerm functor = ((StructureTerm) car).functor();
        Term[] args = ((StructureTerm) car).args();
        if (functor.equals(SYM_ALIAS_1)) {
          Term alias = args[0].dereference();
          if (!alias.isSymbol()) {
            throw new IllegalDomainException(this, 2,
                "hash_option", car);
          } else {
View Full Code Here

  @Override
  protected double priorActionProbability(SymbolTerm action, PlayerId playerId) {
    ToPrologTermVisitor visitor = getTopVisitor();
    IntegerTerm gameId = new IntegerTerm(visitor.getGameId());
    IntegerTerm actionId = new IntegerTerm(visitor.getActionId() + 1);
    SymbolTerm player = SymbolTerm.makeSymbol("player_" + playerId.getId());
    SymbolTerm round = visitor.getRound();
    VariableTerm p = new VariableTerm();
    PRED_prior_action_probability_6 pedicate = new PRED_prior_action_probability_6(
        gameId, actionId, player, action, round, p, null);
    String goal = pedicate.toString();
    goal = goal.replace(p.toString(), "P") + ".";
View Full Code Here

    ToPrologTermVisitor visitor = getTopVisitor();
    Predicate prior_action_probability = new PRED_prior_action_probability_6();
    VariableTerm p = new VariableTerm();
    IntegerTerm gameId = new IntegerTerm(visitor.getGameId());
    IntegerTerm actionId = new IntegerTerm(visitor.getActionId() + 1);
    SymbolTerm playerName = SymbolTerm.makeSymbol("player_" + playerId.getId());
    Term[] args = { gameId, actionId, playerName, action, visitor.getRound(), p };
    if (logger.isDebugEnabled()) {
      logger.debug(new PRED_prior_action_probability_6(gameId, actionId, playerName, action, visitor.getRound(), p, null));
    }
    if (!executeGoal(prior_action_probability, args)) {
View Full Code Here

        getCardTerm(card), }));
  }

  @Override
  protected void gameFlop(int cardNumber, Card card) {
    SymbolTerm term;
    if (cardNumber == 1) {
      term = game_flop_1;
    } else if (cardNumber == 2) {
      term = game_flop_1;
    } else if (cardNumber == 3) {
View Full Code Here

  }

  @Override
  protected void gamePlayerHoleCards(int cardNumber,
      ShowdownPlayer showdownPlayer, Card card) {
    SymbolTerm term;
    if (cardNumber == 1) {
      term = game_player_hole_card_1;
    } else if (cardNumber == 2) {
      term = game_player_hole_card_2;
    } else {
View Full Code Here

      t = new ListTerm(SYM_DOT, t);
      if (!a2.unify(t, engine.trail)) {
        return engine.fail();
      }
    } else if (a1.isStructure()) {
      SymbolTerm sym = SymbolTerm.makeSymbol(((StructureTerm) a1)
          .functor().name());
      Term[] args = ((StructureTerm) a1).args();
      Term t = SYM_NIL;
      for (int i = args.length; i > 0; i--) {
        t = new ListTerm(args[i - 1], t);
      }
      if (!a2.unify(new ListTerm(sym, t), engine.trail)) {
        return engine.fail();
      }
    } else if (a1.isVariable()) {
      a2 = a2.dereference();
      if (a2.isVariable()) {
        throw new PInstantiationException(this, 2);
      } else if (a2.equals(SYM_NIL)) {
        throw new IllegalDomainException(this, 2, "non_empty_list", a2);
      } else if (!a2.isList()) {
        throw new IllegalTypeException(this, 2, "list", a2);
      }
      Term head = ((ListTerm) a2).car().dereference();
      Term tail = ((ListTerm) a2).cdr().dereference();
      if (head.isVariable()) {
        throw new PInstantiationException(this, 2);
      }
      if (tail.equals(SYM_NIL)) {
        if (head.isSymbol() || head.isNumber() || head.isJavaObject()
            || head.isClosure()) {
          if (!a1.unify(head, engine.trail)) {
            return engine.fail();
          }
          return cont;
        } else {
          throw new IllegalTypeException(this, 2, "atomic", head);
        }
      }
      if (!head.isSymbol()) {
        throw new IllegalTypeException(this, 2, "atom", head);
      }
      Term x = tail;
      while (!x.equals(SYM_NIL)) {
        if (x.isVariable()) {
          throw new PInstantiationException(this, 2);
        }
        if (!x.isList()) {
          throw new IllegalTypeException(this, 2, "list", a2);
        }
        x = ((ListTerm) x).cdr().dereference();
      }
      int n = ((ListTerm) a2).length() - 1;
      SymbolTerm sym = SymbolTerm.makeSymbol(((SymbolTerm) head).name(),
          n);
      Term[] args = new Term[n];
      for (int i = 0; i < n; i++) {
        args[i] = ((ListTerm) tail).car().dereference();
        tail = ((ListTerm) tail).cdr().dereference();
View Full Code Here

      Term car = ((ListTerm) tmp).car().dereference();
      if (car.isVariable()) {
        throw new PInstantiationException(this, 4);
      }
      if (car.isStructure()) {
        SymbolTerm functor = ((StructureTerm) car).functor();
        Term[] args = ((StructureTerm) car).args();
        if (functor.equals(SYM_ALIAS_1)) {
          alias = args[0].dereference();
          if (!alias.isSymbol()) {
            throw new IllegalDomainException(this, 4,
                "stream_option", car);
          }
View Full Code Here

      }
      Term[] args = new Term[n];
      for (int i = 0; i < n; i++) {
        args[i] = new VariableTerm(engine);
      }
      SymbolTerm sym = SymbolTerm.makeSymbol(((SymbolTerm) a2).name(), n);
      if (!a1.unify(new StructureTerm(sym, args), engine.trail)) {
        return engine.fail();
      }
      return cont;
    }
View Full Code Here

TOP

Related Classes of jp.ac.kobe_u.cs.prolog.lang.SymbolTerm

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.