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

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


                for(int i=0; i<f.arity(); i++)
                    rval += "<argument>"+renderGdlToXML(f.get(i))+"</argument>";
                return rval;
            }
        } else if (gdl instanceof GdlRelation) {
            GdlRelation relation = (GdlRelation) gdl;
            if(relation.getName().toString().equals("true"))
            {
                for(int i=0; i<relation.arity(); i++)
                    rval+="<fact>"+renderGdlToXML(relation.get(i))+"</fact>";
                return rval;
            } else {
                rval+="<relation>"+relation.getName()+"</relation>";
                for(int i=0; i<relation.arity(); i++)
                    rval+="<argument>"+renderGdlToXML(relation.get(i))+"</argument>";
                return rval;
            }
        } else {
            System.err.println("gdlToXML Error: could not handle "+gdl.toString());
            return null;
View Full Code Here


        for(Gdl gdl : description)
        {
            boolean notBase = true;
            if(gdl instanceof GdlRelation)
            {
                GdlRelation rel = (GdlRelation)gdl;
                if(rel.getName().toString().equals("base"))
                    notBase = false;
            }
            if(notBase)
                rval.add(gdl);
        }
View Full Code Here

    description = newDescription;
    newDescription = new ArrayList<Gdl>();
    boolean removeBaseSentences = false;
    for (Gdl gdl : description) {
      if (gdl instanceof GdlRelation) {
        GdlRelation relation = (GdlRelation) gdl;
        if (relation.getName() == BASE && relation.arity() != 1) {
          removeBaseSentences = true;
          break;
        }
      }
    }
    //Note that in this case, we have to remove ALL of them or we might
    //misinterpret this as being the new kind of "base" relation
    for (Gdl gdl : description) {
      if (gdl instanceof GdlRelation) {
        GdlRelation relation = (GdlRelation) gdl;
        if (removeBaseSentences && relation.getName() == BASE) {
          //Leave out the relation
        } else {
          newDescription.add(gdl);
        }
      } else {
View Full Code Here

            }
            return GdlPool.getOr(rval);
        } else if(gdl instanceof GdlProposition) {
            return gdl;
        } else if(gdl instanceof GdlRelation) {
            GdlRelation rel = (GdlRelation)gdl;
            List<GdlTerm> rval = new ArrayList<GdlTerm>();
            for(int i=0; i<rel.arity(); i++)
            {
                rval.add((GdlTerm) replaceVariableInternal(rel.get(i), toSubstitute, theReplacement));
            }
            return GdlPool.getRelation(rel.getName(), rval);
        } else if(gdl instanceof GdlRule) {
            GdlRule rule = (GdlRule)gdl;
            List<GdlLiteral> rval = new ArrayList<GdlLiteral>();
            for(int i=0; i<rule.arity(); i++)
            {
View Full Code Here

  private static Gdl replaceVariablesInternal(Gdl gdl,
      Map<GdlVariable, ? extends GdlTerm> assignment) {
    if (gdl instanceof GdlProposition) {
      return gdl;
    } else if (gdl instanceof GdlRelation) {
      GdlRelation relation = (GdlRelation) gdl;
      GdlConstant name = relation.getName();
      List<GdlTerm> newBody = new ArrayList<GdlTerm>(relation.arity());
      for(GdlTerm term : relation.getBody()) {
        newBody.add(replaceVariables(term, assignment));
      }
      return GdlPool.getRelation(name, newBody);
    } else if (gdl instanceof GdlConstant) {
      return gdl;
View Full Code Here

    public static List<Role> computeRoles(List<? extends Gdl> description)
    {
        List<Role> roles = new ArrayList<Role>();
        for (Gdl gdl : description) {
            if (gdl instanceof GdlRelation) {
                GdlRelation relation = (GdlRelation) gdl;
                if (relation.getName().getValue().equals("role")) {
                    roles.add(new Role((GdlConstant) relation.get(0)));
                }
            }
        }
        return roles;
    }
View Full Code Here

      throw new GoalDefinitionException(state, role);
    }

    try
    {
      GdlRelation relation = (GdlRelation) results.iterator().next();
      GdlConstant constant = (GdlConstant) relation.get(1);

      return Integer.parseInt(constant.toString());
    }
    catch (Exception e)
    {
View Full Code Here

    {
        // Skip all propositions that aren't GdlRelations.
        if (!(proposition.getName() instanceof GdlRelation))
            continue;

      GdlRelation relation = (GdlRelation) proposition.getName();
      if (!relation.getName().getValue().equals("goal"))
          continue;

      Role theRole = new Role((GdlConstant) relation.get(0));
      if (!goalPropositions.containsKey(theRole)) {
        goalPropositions.put(theRole, new HashSet<Proposition>());
      }
      goalPropositions.get(theRole).add(proposition);
    }
View Full Code Here

    {
        // Skip all propositions that aren't GdlFunctions.
      if (!(proposition.getName() instanceof GdlRelation))
          continue;

      GdlRelation relation = (GdlRelation) proposition.getName();
      if (relation.getName().getValue().equals("does")) {
        inputPropositions.put(proposition.getName(), proposition);
      }
    }

    return inputPropositions;
View Full Code Here

    {
        // Skip all propositions that aren't GdlRelations.
      if (!(proposition.getName() instanceof GdlRelation))
          continue;

      GdlRelation relation = (GdlRelation) proposition.getName();
      if (relation.getName().getValue().equals("legal")) {
        GdlConstant name = (GdlConstant) relation.get(0);
        Role r = new Role(name);
        if (!legalPropositions.containsKey(r)) {
          legalPropositions.put(r, new HashSet<Proposition>());
        }
        legalPropositions.get(r).add(proposition);
View Full Code Here

TOP

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

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.