Package org.ggp.base.util.gdl.grammar

Examples of org.ggp.base.util.gdl.grammar.GdlNot


  }


  private static void testLiteralForImproperNegation(GdlLiteral literal) throws ValidatorException {
    if(literal instanceof GdlNot) {
      GdlNot not = (GdlNot) literal;
      if(!(not.getBody() instanceof GdlSentence))
        throw new ValidatorException("The negation " + not + " contains a literal " + not.getBody() + " that is not a sentence. Only a single sentence is allowed inside a negation.");
    } else if(literal instanceof GdlOr) {
      GdlOr or = (GdlOr) literal;
      for(int i = 0; i < or.arity(); i++) {
        testLiteralForImproperNegation(or.get(i));
      }
View Full Code Here


  private static void addSentencesInLiteral(GdlLiteral literal,
      Collection<GdlSentence> sentences) {
    if(literal instanceof GdlSentence) {
      sentences.add((GdlSentence) literal);
    } else if(literal instanceof GdlNot) {
      GdlNot not = (GdlNot) literal;
      addSentencesInLiteral(not.getBody(), sentences);
    } else if(literal instanceof GdlOr) {
      GdlOr or = (GdlOr) literal;
      for(int i = 0; i < or.arity(); i++)
        addSentencesInLiteral(or.get(i), sentences);
    } else if(!(literal instanceof GdlDistinct)) {
View Full Code Here

      if(literal instanceof GdlSentence) {
        GdlSentence sentence = (GdlSentence) literal;
        if(SentenceModelUtils.inSentenceFormGroup(sentence, formsControlledByFlow))
          relevantLiterals.add(literal);
      } else if(literal instanceof GdlNot) {
        GdlNot not = (GdlNot) literal;
        GdlSentence innerSentence = (GdlSentence) not.getBody();
        if(SentenceModelUtils.inSentenceFormGroup(innerSentence, formsControlledByFlow))
          relevantLiterals.add(literal);
      }
    }

    //If none are related to the game flow, then that's it. It can
    //happen on any turn.
    //if(relevantLiterals.isEmpty())
      //return getCompleteTurnSet();
    Set<Integer> turnsPossible = new HashSet<Integer>(getCompleteTurnSet());

    //For each of the relevant literals, we need to see if there are assignments
    //such that
    for(GdlLiteral literal : relevantLiterals) {
      List<Integer> turns = new ArrayList<Integer>();
      if(literal instanceof GdlSentence) {
        for(int t = 0; t < getNumTurns(); t++) {
          if(sentencesTrueByTurn.get(t).contains(literal))
            turns.add(t);
          else for(GdlSentence s : sentencesTrueByTurn.get(t)) {
            //Could be true if there's an assignment
            if(null != GdlUtils.getAssignmentMakingLeftIntoRight((GdlSentence)literal, s)) {
              turns.add(t);
              break;
            }
          }
        }
      } else if(literal instanceof GdlNot) {
        GdlNot not = (GdlNot) literal;
        GdlSentence internal = (GdlSentence) not.getBody();
        for(int t = 0; t < getNumTurns(); t++) {
          if(!sentencesTrueByTurn.get(t).contains(internal))
            turns.add(t);
          else for(GdlSentence s : sentencesTrueByTurn.get(t)) {
            if(null != GdlUtils.getAssignmentMakingLeftIntoRight(internal, s)) {
View Full Code Here

    for(GdlLiteral literal : rule.getBody()) {
      if(literal instanceof GdlRelation) {
        if(!SentenceModelUtils.inSentenceFormGroup((GdlRelation)literal, constantSentenceForms))
          result.addAll(GdlUtils.getVariables(literal));
      } else if(literal instanceof GdlNot) {
        GdlNot not = (GdlNot) literal;
        GdlSentence inner = (GdlSentence) not.getBody();
        if(!SentenceModelUtils.inSentenceFormGroup(inner, constantSentenceForms))
          result.addAll(GdlUtils.getVariables(literal));
      }
    }
    return result;
View Full Code Here

            processGdl(distinct.getArg1(), null);
            processGdl(distinct.getArg2(), null);
        }
        else if(gdl instanceof GdlNot)
        {
            GdlNot not = (GdlNot)gdl;
            processGdl(not.getBody(), null);
        }
        else if(gdl instanceof GdlOr)
        {
            GdlOr or = (GdlOr)gdl;
            for(int i=0; i<or.arity(); i++)
View Full Code Here

    }

    private static GdlNot getNotDistinctLiteral(GdlRule rule) {
        for(GdlLiteral literal : rule.getBody()) {
            if(literal instanceof GdlNot) {
                GdlNot not = (GdlNot) literal;
                if(not.getBody() instanceof GdlDistinct) {
                    //For now, we can only deal with this if not both are functions.
                    //That means we have to skip that case at this point.
                    GdlDistinct distinct = (GdlDistinct) not.getBody();
                    if(!(distinct.getArg1() instanceof GdlFunction)
                            || !(distinct.getArg2() instanceof GdlFunction))
                        return not;
                }
            }
View Full Code Here

        GdlDistinct distinct = (GdlDistinct) qPrime;
        isConstant = askDistinct(distinct, goals, context, theta, cache, renamer, askOne, results, alreadyAsking);
      }
      else if (qPrime instanceof GdlNot)
      {
        GdlNot not = (GdlNot) qPrime;
        isConstant = askNot(not, goals, context, theta, cache, renamer, askOne, results, alreadyAsking);
      }
      else if (qPrime instanceof GdlOr)
      {
        GdlOr or = (GdlOr) qPrime;
View Full Code Here

            rval.add(gdl);
            return rval;
        }
        else if(gdl instanceof GdlNot)
        {
            GdlNot not = (GdlNot)gdl;
            expandedChild = expandFirstOr(not.getBody());
            rval = new ArrayList<Gdl>();
            for(Gdl g : expandedChild)
            {
                if(!(g instanceof GdlLiteral)) throw new RuntimeException("Not must have literal child.");
                GdlLiteral lit = (GdlLiteral)g;
View Full Code Here

      return proposition;
    }
    else if ( literal instanceof GdlNot )
    {
      GdlNot not = (GdlNot) literal;

      Proposition input = convertConjunct(not.getBody());
      Not no = new Not();
      Proposition output = new Proposition(GdlPool.getProposition(GdlPool.getConstant("anon")));

      link(input, no);
      link(no, output);
View Full Code Here

        return sentence.get(0).toSentence();
      } else {
        return literal;
      }
    } else if(literal instanceof GdlNot) {
      GdlNot not = (GdlNot) literal;
      return GdlPool.getNot(replaceRelationInLiteral(not.getBody(), trueForm));
    } else if(literal instanceof GdlOr) {
      GdlOr or = (GdlOr) literal;
      List<GdlLiteral> newOrBody = new ArrayList<GdlLiteral>();
      for(int i = 0; i < or.arity(); i++)
        newOrBody.add(replaceRelationInLiteral(or.get(i), trueForm));
View Full Code Here

TOP

Related Classes of org.ggp.base.util.gdl.grammar.GdlNot

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.