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

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


    Set<GdlRelation> cyclicRelations = new HashSet<GdlRelation>();
    Set<GdlRelation> acyclicRelations = new HashSet<GdlRelation>();
    for(GdlLiteral literal : rule.getBody()) {
      //Is it a relation?
      if(literal instanceof GdlRelation) {
        GdlRelation relation = (GdlRelation) literal;
        //Is it in a cycle with the head?
        if(ancestorsGraph.get(relation.getName()).contains(head)) {
          cyclicRelations.add(relation);
        } else {
          acyclicRelations.add(relation);
        }
      } 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
          }
        }
      }
    }

    for(GdlRelation relation : cyclicRelations) {
      for(GdlTerm term : relation.getBody()) {
        //There are three ways to be okay
        boolean safe = false;
        //One: Is it ground?
        if(term.isGround())
          safe = true;
View Full Code Here


    for(Component component : componentSet) {
      if(component instanceof Proposition) {
        Proposition p = (Proposition) component;
        GdlSentence sentence = p.getName();
        if(sentence instanceof GdlRelation) {
          GdlRelation relation = (GdlRelation) sentence;
          if(relation.getName().equals(NEXT)) {
            p.setName(GdlPool.getProposition(GdlPool.getConstant("anon")));
          }
        }
      }
    }
View Full Code Here

   */
  public static void removeInits(PropNet pn) {
    List<Proposition> toRemove = new ArrayList<Proposition>();
    for(Proposition p : pn.getPropositions()) {
      if(p.getName() instanceof GdlRelation) {
        GdlRelation relation = (GdlRelation) p.getName();
        if(relation.getName() == INIT) {
          toRemove.add(p);
        }
      }
    }

View Full Code Here

      GdlSentence sentence = p.getName();
      if(sentence instanceof GdlProposition) {
        if(sentence.getName() == TERMINAL || sentence.getName() == INIT_CAPS)
          continue;
      } else {
        GdlRelation relation = (GdlRelation) sentence;
        GdlConstant name = relation.getName();
        if(name == LEGAL || name == GOAL || name == DOES
            || name == INIT)
          continue;
      }
      if(p.getInputs().size() < 1) {
View Full Code Here

            {
                List<GdlTerm> ms2 = new ArrayList<GdlTerm>(mergeSet);
                Collections.sort(ms2, new SortTerms());
                body.add(GdlPool.getFunction(valConst, ms2));
            }
            GdlRelation toAdd = GdlPool.getRelation(baseConstant, body);
            rval.add(toAdd);
        }

        return rval;
    }
View Full Code Here

    void processGdl(Gdl gdl, GdlConstant parent)
    {
        if(gdl instanceof GdlRelation)
        {
            GdlRelation relation = (GdlRelation) gdl;
            String name = relation.getName().toString();
            if(!name.equals("base"))
            {
                for(Gdl gdl2 : relation.getBody())
                    processGdl(gdl2, relation.getName());
            }
        }
        else if(gdl instanceof GdlRule)
        {
            GdlRule rule = (GdlRule) gdl;
View Full Code Here

    private void findAndInstantiateBaseProps(Gdl gdl)
    {
        if(gdl instanceof GdlRelation)
        {
            GdlRelation relation = (GdlRelation) gdl;
            String name = relation.getName().toString();
            if(name.equals("init"))
            {
                if(relation.arity()!=1)
                    throw new RuntimeException("Can't init more than one thing as far as I know.");
                GdlTerm template = relation.get(0);
                if(template instanceof GdlConstant)
                {
                    List<GdlTerm> body = new ArrayList<GdlTerm>();
                    body.add(template);
                    GdlRelation toAdd = GdlPool.getRelation(baseConstant, body);
                    baseRelations.add(toAdd);
                    System.err.println("Weird init of constant");
                }
                else if(template instanceof GdlVariable)
                {
                    System.err.println("Weird init of constant");
                    List<GdlTerm> body = new ArrayList<GdlTerm>();
                    body.add(universalDom);
                    GdlRelation toAdd = GdlPool.getRelation(baseConstant, body);
                    baseRelations.add(toAdd);
                    System.err.println("Weird init of variable");
                }
                else if(template instanceof GdlFunction)
                {
View Full Code Here

            else if(arg instanceof GdlFunction)
            {
                throw new RuntimeException("Don't know how to deal with functions within next/init.");
            }
        }
        GdlRelation toAdd = GdlPool.getRelation(baseConstant, body);
        baseRelations.add(toAdd);
    }
View Full Code Here

    void processDomain(Gdl gdl)
    {
        if(gdl instanceof GdlRelation)
        {
            GdlRelation relation = (GdlRelation) gdl;
            String name = relation.getName().toString();
            if(!name.equals("base"))
            {
                addDomain(relation);
            }
        }
        else if(gdl instanceof GdlRule)
        {
            GdlRule rule = (GdlRule)gdl;
            GdlSentence head = rule.getHead();
            if(head instanceof GdlRelation)
            {
                GdlRelation rel = (GdlRelation)head;

                int i=0;
                for(GdlTerm term : rel.getBody())
                {
                    addDomain2(term, rel.getName(), i, rule.getBody());
                    i++;
                }
            }
            else if(head instanceof GdlProposition)
            {
View Full Code Here

        Set<Domain> rval = new HashSet<Domain>();

        if(gdl instanceof GdlRelation)
        {
            GdlRelation relation = (GdlRelation) gdl;
            for(int i=0; i<relation.arity(); i++)
            {
                Location parent = new Location();
                parent.name = relation.getName();
                parent.idx = i;
                rval.addAll(findAllInstancesOf(var, relation.get(i), parent));
            }
        }
        else if(gdl instanceof GdlDistinct)
        {
//          GdlDistinct distinct = (GdlDistinct)gdl;
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.