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

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


    try {
      StateMachine sm = new ProverStateMachine();
      sm.initialize(theGame.getRules());

      AimaProver prover = new AimaProver(theGame.getRules());
      GdlSentence basesQuery = GdlPool.getRelation(BASE, new GdlTerm[] {X});
      Set<GdlSentence> bases = prover.askAll(basesQuery, Collections.<GdlSentence>emptySet());
      GdlSentence inputsQuery = GdlPool.getRelation(INPUT, new GdlTerm[] {X, Y});
      Set<GdlSentence> inputs = prover.askAll(inputsQuery, Collections.<GdlSentence>emptySet());

      if (bases.size() == 0) {
        throw new ValidatorException("Could not find base propositions.");
      } else if (inputs.size() == 0) {
View Full Code Here


    }
  }

  private static GdlRule substituteRule(GdlRule rule, Substitution theta)
  {
    GdlSentence head = substitute(rule.getHead(), theta);

    List<GdlLiteral> body = new ArrayList<GdlLiteral>();
    for ( GdlLiteral literal : rule.getBody() )
    {
      body.add(substituteLiteral(literal, theta));
View Full Code Here

          allSatisfied = false;
          break;
        }
      }
      if (allSatisfied) {
        GdlSentence head = rule.getHead();
        sentencesToAdd.put(headForm, CommonTransforms.replaceVariables(head, assignment));
        asnItr.changeOneInNext(GdlUtils.getVariables(head), assignment);
      }
    }
    return sentencesToAdd;
View Full Code Here

              allSatisfied = false;
              break;
            }
          }
          if (allSatisfied) {
            GdlSentence head = rule.getHead();
            GdlSentence newHead = CommonTransforms.replaceVariables(head, assignment);
            if (!allSentences.containsSentence(headForm, newHead)) {
              sentencesToAdd.put(headForm, newHead);
            }
            asnItr.changeOneInNext(GdlUtils.getVariables(head), assignment);
          }
View Full Code Here

    return GdlPool.getRelation(name, body);
  }

  private static GdlRule createRule(SymbolList list)
  {
    GdlSentence head = createSentence(list.get(1));

    List<GdlLiteral> body = new ArrayList<GdlLiteral>();
    for (int i = 2; i < list.size(); i++)
    {
      body.add(createLiteral(list.get(i)));
View Full Code Here

  private static void addSentencesTrueByRules(
      Multimap<SentenceForm, GdlSentence> sentencesByForm,
      SentenceFormModel model) throws InterruptedException {
    AimaProver prover = new AimaProver(model.getDescription());
    for (SentenceForm form : model.getConstantSentenceForms()) {
      GdlSentence query = form.getSentenceFromTuple(getVariablesTuple(form.getTupleSize()));
      for (GdlSentence result : prover.askAll(query, ImmutableSet.<GdlSentence>of())) {
        ConcurrencyUtils.checkForInterruption();
        //Variables may end up being replaced with functions, which is not
        //what we want here, so we have to double-check that the form is correct.
        if (form.matches(result)) {
View Full Code Here

    //Use "init" values
    Set<GdlSentence> trueFlowSentences = new HashSet<GdlSentence>();
    for(SentenceForm form : constantForms) {
      if(form.getName().equals(INIT)) {
          for (GdlSentence initSentence : constantChecker.getTrueSentences(form)) {
          GdlSentence trueSentence = GdlPool.getRelation(TRUE, initSentence.getBody());
          trueFlowSentences.add(trueSentence);
        }
      }
    }
    //Go through ordering, adding to trueFlowSentences
    addSentenceForms(ordering, trueFlowSentences, model, functionInfoMap);
    sentencesTrueByTurn.add(trueFlowSentences);

    outer : while(true) {
      //Now we use the "next" values from the previous turn
      Set<GdlSentence> sentencesPreviouslyTrue = trueFlowSentences;
      trueFlowSentences = new HashSet<GdlSentence>();
      for(GdlSentence sentence : sentencesPreviouslyTrue) {
        if(sentence.getName().equals(NEXT)) {
          GdlSentence trueSentence = GdlPool.getRelation(TRUE, sentence.getBody());
          trueFlowSentences.add(trueSentence);
        }
      }

      addSentenceForms(ordering, trueFlowSentences, model, functionInfoMap);
View Full Code Here

      //Use basic Assignments class, of course

      for(GdlSentence alwaysTrueSentences : model.getSentencesListedAsTrue(curForm))
        trueFlowSentences.add(alwaysTrueSentences);
      for(GdlRule rule : model.getRules(curForm)) {
        GdlSentence head = rule.getHead();
        List<GdlVariable> varsInHead = GdlUtils.getVariables(head);
        Assignments assignments = AssignmentsFactory.getAssignmentsForRule(rule, model, functionInfoMap, Collections.EMPTY_MAP);

        AssignmentIterator asnItr = assignments.getIterator();
        while(asnItr.hasNext()) {
          Map<GdlVariable, GdlConstant> assignment = asnItr.next();
          boolean isGoodAssignment = true;

          GdlSentence transformedHead = CommonTransforms.replaceVariables(head, assignment);
          if(trueFlowSentences.contains(transformedHead))
            asnItr.changeOneInNext(varsInHead, assignment);

          //Go through the conjuncts
          for(GdlLiteral literal : rule.getBody()) {
            if(literal instanceof GdlSentence) {
              if(curForm.matches((GdlSentence) literal))
                throw new RuntimeException("Haven't implemented recursion in the game flow");
              GdlSentence transformed = CommonTransforms.replaceVariables((GdlSentence) literal, assignment);
              SentenceForm conjForm = model.getSentenceForm(transformed);
              if(constantForms.contains(conjForm)) {
                if(!constantChecker.isTrueConstant(transformed)) {
                  isGoodAssignment = false;
                  asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
                }
              } else {
                if(!trueFlowSentences.contains(transformed)) {
                  //False sentence
                  isGoodAssignment = false;
                  asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment);
                }
              }
            } else if(literal instanceof GdlNot) {
              GdlSentence internal = (GdlSentence) ((GdlNot) literal).getBody();
              GdlSentence transformed = CommonTransforms.replaceVariables(internal, assignment);
              SentenceForm conjForm = model.getSentenceForm(transformed);

              if(constantForms.contains(conjForm)) {
                if(constantChecker.isTrueConstant(transformed)) {
                  isGoodAssignment = false;
View Full Code Here

    //We want to identify the conjuncts that are used by the
    //game flow.
    List<GdlLiteral> relevantLiterals = new ArrayList<GdlLiteral>();
    for(GdlLiteral literal : body) {
      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 each positive definition of sentences in the rule, intersect their
    // domains everywhere the variables show up
    Multimap<GdlVariable, Set<GdlConstant>> varDomainsByVar = ArrayListMultimap.create();
    for (GdlLiteral literal : getSentences(rule, includeHead)) {
      if (literal instanceof GdlSentence) {
        GdlSentence sentence = (GdlSentence) literal;
        SentenceForm form = SimpleSentenceForm.create(sentence);
        SentenceFormDomain formWithDomain = domainModel.getDomain(form);

        List<GdlTerm> tuple = GdlUtils.getTupleFromSentence(sentence);
        for (int i = 0; i < tuple.size(); i++) {
View Full Code Here

TOP

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

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.