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

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


            SentenceForm form = model.getSentenceForm(sentence);
            for (Ambiguity ambiguity : ambiguitiesByOriginalForm.get(form)) {
                ConcurrencyUtils.checkForInterruption();
                if (ambiguity.applies(sentence)) {
                    Map<GdlVariable, GdlTerm> replacementAssignment = ambiguity.getReplacementAssignment(sentence, varGen);
                    GdlRule newRule = CommonTransforms.replaceVariables(rule, replacementAssignment);
                    results.add(newRule);
                }
            }
        } else if (literal instanceof GdlNot) {
            // Do nothing. Variables must appear in a positive literal in the
View Full Code Here


            public boolean apply(Gdl input) {
                if (!(input instanceof GdlRule)) {
                    // If it's not a rule, leave it in
                    return true;
                }
                GdlRule rule = (GdlRule) input;
                // Used just as a boolean we can change from the inner class
                final AtomicBoolean shouldRemove = new AtomicBoolean(false);
                GdlVisitors.visitAll(rule, new GdlVisitor() {
                    @Override
                    public void visitSentence(GdlSentence sentence) {
View Full Code Here

                    processGdl(gdl2, relation.getName());
            }
        }
        else if(gdl instanceof GdlRule)
        {
            GdlRule rule = (GdlRule) gdl;
            for(Gdl gdl2 : rule.getBody())
                processGdl(gdl2, null);
        }
        else if(gdl instanceof GdlConstant)
        {
            universe.add((GdlConstant)gdl);
View Full Code Here

                }
            }
        }
        else if(gdl instanceof GdlRule)
        {
            GdlRule rule = (GdlRule) gdl;
            String name = rule.getHead().getName().toString();
            if(name.equals("next"))
            {
                GdlSentence head = rule.getHead();
                if(head.arity()!=1)
                    throw new RuntimeException("Can't next more than one thing as far as I know.");
                if(head.get(0) instanceof GdlVariable)
                {   //weird case where you have rule like (next ?q)
                    Location l = new Location();
                    l.idx = 0;
                    l.name = head.getName();
                    Domain dom = domains.get(l);
                    for(GdlConstant c : dom.values)
                    {
                        List<GdlTerm> body = new ArrayList<GdlTerm>();
                        body.add(c);
                        baseRelations.add(GdlPool.getRelation(baseConstant, body));
                    }
                }
                else
                    instantiateBasePropsWithRHS(head.get(0).toSentence(), rule.getBody());
            }
        }
    }
View Full Code Here

                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

    List<Gdl> newDescription = new ArrayList<Gdl>();

    //First: Clean up all rules with zero-element bodies
    for(Gdl gdl : description) {
      if(gdl instanceof GdlRule) {
        GdlRule rule = (GdlRule) gdl;
        if(rule.getBody().size() == 0) {
          newDescription.add(rule.getHead());
        } else {
          newDescription.add(gdl);
        }
      } else {
        newDescription.add(gdl);
      }
    }

    //TODO: Add (role ?player) where appropriate, i.e. in rules for
    //"legal" or "input" where the first argument is an undefined
    //variable
    //Get rid of "extra parentheses", i.e. zero-arity functions
    description = newDescription;
    newDescription = new ArrayList<Gdl>();
    for(Gdl gdl : description) {
      if(gdl instanceof GdlRelation) {
        newDescription.add(cleanParentheses((GdlRelation)gdl));
      } else if(gdl instanceof GdlRule) {
        newDescription.add(cleanParentheses((GdlRule)gdl));
      } else {
        newDescription.add(gdl);
      }
    }
    //TODO: Get rid of GdlPropositions in the description

    //TODO: Get rid of (not (or ...))

    //Get rid of (not (distinct _ _)) literals in rules
    //TODO: Expand to functions
    description = newDescription;
    newDescription = new ArrayList<Gdl>();
    for(Gdl gdl : description) {
        if(gdl instanceof GdlRule) {
            GdlRule cleaned = removeNotDistinctLiterals((GdlRule)gdl);
            if(cleaned != null)
                newDescription.add(cleaned);
        } else {
            newDescription.add(gdl);
        }
View Full Code Here

      ImmutableSet<SentenceForm> sentenceForms,
      ImmutableSetMultimap<SentenceForm, GdlRule> rulesByForm) {
    SetMultimap<SentenceForm, SentenceForm> dependencyGraph = HashMultimap.create();
    for(Entry<SentenceForm, GdlRule> entry : rulesByForm.entries()) {
      SentenceForm head = entry.getKey();
      GdlRule rule = entry.getValue();
      for(GdlLiteral bodyLiteral : rule.getBody()) {
        dependencyGraph.putAll(head, getSentenceFormsInBody(bodyLiteral, sentenceForms));
      }
    }
    return ImmutableSetMultimap.copyOf(dependencyGraph);
  }
View Full Code Here

    ImmutableSetMultimap.Builder<SentenceForm, GdlRule> builder =
        ImmutableSetMultimap.builder();

    for(Gdl gdl : gameRules) {
      if(gdl instanceof GdlRule) {
        GdlRule rule = (GdlRule) gdl;
        for (SentenceForm form : sentenceForms) {
          if(form.matches(rule.getHead())) {
            builder.put(form, rule);
            break;
          }
        }
      }
View Full Code Here

            {
                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++)
            {
                rval.add((GdlLiteral) replaceVariableInternal(rule.get(i), toSubstitute, theReplacement));
            }
            return GdlPool.getRule((GdlSentence) replaceVariableInternal(rule.getHead(), toSubstitute, theReplacement), rval);
        } else if(gdl instanceof GdlConstant) {
            return gdl;
        } else if(gdl instanceof GdlFunction) {
            GdlFunction func = (GdlFunction)gdl;
            List<GdlTerm> rval = new ArrayList<GdlTerm>();
View Full Code Here

      for (int i = 0; i < or.arity(); i++) {
        newInternals.add(replaceVariables(or.get(i), assignment));
      }
      return GdlPool.getOr(newInternals);
    } else if (gdl instanceof GdlRule) {
      GdlRule rule = (GdlRule) gdl;
      GdlSentence newHead = replaceVariables(rule.getHead(), assignment);
      List<GdlLiteral> newBody = Lists.newArrayList();
      for (GdlLiteral conjunct : rule.getBody()) {
        newBody.add(replaceVariables(conjunct, assignment));
      }
      return GdlPool.getRule(newHead, newBody);
    } else {
      throw new RuntimeException("Unforeseen Gdl subtype " + gdl.getClass().getSimpleName());
View Full Code Here

TOP

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

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.