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

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


    {
      return not;
    }
    else
    {
      GdlLiteral body = substituteLiteral(not.getBody(), theta);
      return GdlPool.getNot(body);
    }
  }
View Full Code Here


  private boolean satisfies(Map<GdlVariable, GdlConstant> assignment,
      GdlLiteral literal, SetMultimap<SentenceForm, GdlSentence> sentencesSoFar) {
    if (literal instanceof GdlSentence) {
      return satisfiesSentence(assignment, (GdlSentence) literal, sentencesSoFar);
    } else if (literal instanceof GdlNot) {
      GdlLiteral body = ((GdlNot) literal).getBody();
      if (!(body instanceof GdlSentence)) {
        throw new IllegalStateException("Negated literal should be a sentence but isn't: " + body);
      }
      return !satisfiesSentence(assignment, (GdlSentence) body, sentencesSoFar);
    } else if (literal instanceof GdlDistinct) {
      return satisfiesDistinct(assignment, (GdlDistinct) literal);
    } else if (literal instanceof GdlOr) {
      GdlOr or = (GdlOr) literal;
      for (int i = 0; i < or.arity(); i++) {
        GdlLiteral innerLiteral = or.get(i);
        if (satisfies(assignment, innerLiteral, sentencesSoFar)) {
          return true;
        }
      }
      return false;
View Full Code Here

        }
      } else if(literal instanceof GdlOr) {
        //We'll look one layer deep for the cyclic kind
        GdlOr or = (GdlOr) literal;
        for(int i = 0; i < or.arity(); i++) {
          GdlLiteral internal = or.get(i);
          if(internal instanceof GdlRelation) {
            GdlRelation relation = (GdlRelation) internal;
            if(ancestorsGraph.get(relation.getName()).contains(head)) {
              cyclicRelations.add(relation);
            } //Don't add acyclic relations, as we can't count on them
View Full Code Here

  }
  private static void getUnsupportedVariablesInLiteral(GdlLiteral literal,
      Collection<GdlVariable> unsupportedVariables) {
    //We're looking for all variables in distinct or negated relations
    if(literal instanceof GdlNot) {
      GdlLiteral internal = ((GdlNot) literal).getBody();
      if(internal instanceof GdlRelation) {
        getVariablesInBody(((GdlRelation) internal).getBody(), unsupportedVariables);
      }
    } else if(literal instanceof GdlOr) {
      GdlOr or = (GdlOr) literal;
View Full Code Here

      GdlDistinct distinct = (GdlDistinct) literal;
      GdlTerm term1 = cleanParentheses(distinct.getArg1());
      GdlTerm term2 = cleanParentheses(distinct.getArg2());
      return GdlPool.getDistinct(term1, term2);
    } else if(literal instanceof GdlNot) {
      GdlLiteral body = ((GdlNot) literal).getBody();
      return GdlPool.getNot(cleanParentheses(body));
    } else if(literal instanceof GdlOr) {
      GdlOr or = (GdlOr) literal;
      List<GdlLiteral> disjuncts = new ArrayList<GdlLiteral>();
      for(int i = 0; i < or.arity(); i++)
View Full Code Here

      GdlDistinct distinct = (GdlDistinct) gdl;
      GdlTerm arg1 = replaceVariables(distinct.getArg1(), assignment);
      GdlTerm arg2 = replaceVariables(distinct.getArg2(), assignment);
      return GdlPool.getDistinct(arg1, arg2);
    } else if (gdl instanceof GdlNot) {
      GdlLiteral internal = ((GdlNot) gdl).getBody();
      return GdlPool.getNot(replaceVariables(internal, assignment));
    } else if (gdl instanceof GdlOr) {
      GdlOr or = (GdlOr) gdl;
      List<GdlLiteral> newInternals = new ArrayList<GdlLiteral>(or.arity());
      for (int i = 0; i < or.arity(); i++) {
View Full Code Here

  }

  private static void rearrangeDistinctsAndNots(List<GdlLiteral> ruleBody) {
    Integer oldIndex = findDistinctOrNotToMoveIndex(ruleBody);
    while (oldIndex != null) {
      GdlLiteral literalToMove = ruleBody.get(oldIndex);
      ruleBody.remove((int) oldIndex);
      reinsertLiteralInRightPlace(ruleBody, literalToMove);

      oldIndex = findDistinctOrNotToMoveIndex(ruleBody);
    }
View Full Code Here

  //Returns null if no distincts have to be moved.
  private static Integer findDistinctOrNotToMoveIndex(List<GdlLiteral> ruleBody) {
    Set<GdlVariable> setVars = Sets.newHashSet();
    for (int i = 0; i < ruleBody.size(); i++) {
      GdlLiteral literal = ruleBody.get(i);
      if (literal instanceof GdlSentence) {
        setVars.addAll(GdlUtils.getVariables(literal));
      } else if (literal instanceof GdlDistinct
          || literal instanceof GdlNot) {
        if (!allVarsInLiteralAlreadySet(literal, setVars)) {
View Full Code Here

      results.add(theta);
      return true;
    }
    else
    {
      GdlLiteral literal = goals.removeFirst();
      GdlLiteral qPrime = Substituter.substitute(literal, theta);

      boolean isConstant;

      if (qPrime instanceof GdlDistinct)
      {
View Full Code Here

  private static void reinsertLiteralInRightPlace(List<GdlLiteral> ruleBody,
      GdlLiteral literalToReinsert) {
    Set<GdlVariable> setVars = Sets.newHashSet();
    for (int i = 0; i < ruleBody.size(); i++) {
      GdlLiteral literal = ruleBody.get(i);
      if (literal instanceof GdlSentence) {
        setVars.addAll(GdlUtils.getVariables(literal));

        if (allVarsInLiteralAlreadySet(literalToReinsert, setVars)) {
          ruleBody.add(i + 1, literalToReinsert);
View Full Code Here

TOP

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

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.