Examples of SentenceForm


Examples of org.ggp.base.util.gdl.model.SentenceForm

  @Override
  public GdlSentenceSet getRuleResults(GdlRule rule,
      SentenceDomainModel domainModel,
      GdlSentenceSet sentencesSoFar) throws InterruptedException {
    ConcurrencyUtils.checkForInterruption();
    SentenceForm headForm = model.getSentenceForm(rule.getHead());
    Map<GdlVariable, Set<GdlConstant>> varDomains = SentenceDomainModels.getVarDomains(rule, domainModel, VarDomainOpts.INCLUDE_HEAD);
    Map<SentenceForm, ? extends FunctionInfo> functionInfoMap = sentencesSoFar.getFunctionInfo();
    Map<SentenceForm, ? extends Collection<GdlSentence>> completedSentenceFormValues = sentencesSoFar.getSentences().asMap();

    AssignmentsImpl assignments = new AssignmentsImpl(rule, varDomains, functionInfoMap, completedSentenceFormValues);
View Full Code Here

Examples of org.ggp.base.util.gdl.model.SentenceForm

  private boolean satisfiesSentence(Map<GdlVariable, GdlConstant> assignment,
      GdlSentence sentence,
      SetMultimap<SentenceForm, GdlSentence> sentencesSoFar) {
    sentence = CommonTransforms.replaceVariables(sentence, assignment);
    SentenceForm form = model.getSentenceForm(sentence);
    return sentencesSoFar.get(form).contains(sentence);
  }
View Full Code Here

Examples of org.ggp.base.util.gdl.model.SentenceForm

      GdlSentenceSet newSentences) throws InterruptedException {
    GdlSentenceSet results = GdlSentenceSet.create();
    for (GdlLiteral literal : rule.getBody()) {
      ConcurrencyUtils.checkForInterruption();
      if (literal instanceof GdlSentence) {
        SentenceForm literalForm = domainModel.getSentenceForm((GdlSentence) literal);
        addRuleResultsForChosenLiteral(
            rule,
            (GdlSentence) literal,
            newSentences.getSentences().get(literalForm),
            domainModel,
View Full Code Here

Examples of org.ggp.base.util.gdl.model.SentenceForm

  private void addRuleResultsForChosenLiteral(GdlRule rule,
      GdlSentence chosenLiteral, Set<GdlSentence> chosenNewSentences,
      SentenceDomainModel domainModel,
      GdlSentenceSet allSentences,
      GdlSentenceSet sentencesToAdd) {
    SentenceForm headForm = model.getSentenceForm(rule.getHead());
    Map<GdlVariable, Set<GdlConstant>> varDomains = SentenceDomainModels.getVarDomains(rule, domainModel, VarDomainOpts.INCLUDE_HEAD);
    Map<SentenceForm, AddibleFunctionInfo> functionInfoMap = allSentences.getFunctionInfo();
    Map<SentenceForm, ? extends Collection<GdlSentence>> completedSentenceFormValues = allSentences.getSentences().asMap();

    for (GdlSentence chosenNewSentence : chosenNewSentences) {
View Full Code Here

Examples of org.ggp.base.util.gdl.model.SentenceForm

        List<GdlRule> results = Lists.newArrayList(rule);
        UnusedVariableGenerator varGen = getVariableGenerator(rule);

        if (literal instanceof GdlSentence) {
            GdlSentence sentence = (GdlSentence) literal;
            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);
View Full Code Here

Examples of org.ggp.base.util.gdl.model.SentenceForm

                // 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) {
                        SentenceForm form = model.getSentenceForm(sentence);
                        if (!model.getSentenceForms().contains(form)) {
                            shouldRemove.set(true);
                        }
                    }
                });
View Full Code Here

Examples of org.ggp.base.util.gdl.model.SentenceForm

    //follow all the forms in the dependency graph, except maybe itself
    Queue<SentenceForm> queue = new LinkedList<SentenceForm>(forms);
    List<SentenceForm> ordering = new ArrayList<SentenceForm>(forms.size());
    Set<SentenceForm> alreadyOrdered = new HashSet<SentenceForm>();
    while(!queue.isEmpty()) {
      SentenceForm curForm = queue.remove();
      boolean readyToAdd = true;
      //Don't add if there are dependencies
      for(SentenceForm dependency : dependencyGraph.get(curForm)) {
        if(!dependency.equals(curForm) && !alreadyOrdered.contains(dependency)) {
          readyToAdd = false;
          break;
        }
      }
      //Don't add if it's true/next/legal/does and we're waiting for base/input
      if(usingBase && (curForm.getName().equals(TRUE) || curForm.getName().equals(NEXT) || curForm.getName().equals(INIT))) {
        //Have we added the corresponding base sf yet?
        SentenceForm baseForm = curForm.withName(BASE);
        if(!alreadyOrdered.contains(baseForm)) {
          readyToAdd = false;
        }
      }
      if(usingInput && (curForm.getName().equals(DOES) || curForm.getName().equals(LEGAL))) {
        SentenceForm inputForm = curForm.withName(INPUT);
        if(!alreadyOrdered.contains(inputForm)) {
          readyToAdd = false;
        }
      }
      //Add it
View Full Code Here

Examples of org.ggp.base.util.gdl.model.SentenceForm

    }

    //For does/true, make nodes based on input/base, if available
    if(usingInput && form.getName().equals(DOES)) {
      //Add only those propositions for which there is a corresponding INPUT
      SentenceForm inputForm = form.withName(INPUT);
      for (GdlSentence inputSentence : constantChecker.getTrueSentences(inputForm)) {
        GdlSentence doesSentence = GdlPool.getRelation(DOES, inputSentence.getBody());
        Proposition prop = new Proposition(doesSentence);
        components.put(doesSentence, prop);
      }
      return;
    }
    if(usingBase && form.getName().equals(TRUE)) {
      SentenceForm baseForm = form.withName(BASE);
      for (GdlSentence baseSentence : constantChecker.getTrueSentences(baseForm)) {
        GdlSentence trueSentence = GdlPool.getRelation(TRUE, baseSentence.getBody());
        Proposition prop = new Proposition(trueSentence);
        components.put(trueSentence, prop);
      }
      return;
    }

    Map<GdlSentence, Set<Component>> inputsToOr = new HashMap<GdlSentence, Set<Component>>();
    for(GdlRule rule : rules) {
      Assignments assignments = AssignmentsFactory.getAssignmentsForRule(rule, model, functionInfoMap, completedSentenceFormValues);

      //Calculate vars in live (non-constant, non-distinct) conjuncts
      Set<GdlVariable> varsInLiveConjuncts = getVarsInLiveConjuncts(rule, constantChecker.getConstantSentenceForms());
      varsInLiveConjuncts.addAll(GdlUtils.getVariables(rule.getHead()));
      Set<GdlVariable> varsInRule = new HashSet<GdlVariable>(GdlUtils.getVariables(rule));
      boolean preventDuplicatesFromConstants =
        (varsInRule.size() > varsInLiveConjuncts.size());

      //Do we just pass those to the Assignments class in that case?
      for(AssignmentIterator asnItr = assignments.getIterator(); asnItr.hasNext(); ) {
        Map<GdlVariable, GdlConstant> assignment = asnItr.next();
        if(assignment == null) continue; //Not sure if this will ever happen

        ConcurrencyUtils.checkForInterruption();

        GdlSentence sentence = CommonTransforms.replaceVariables(rule.getHead(), assignment);

        //Now we go through the conjuncts as before, but we wait to hook them up.
        List<Component> componentsToConnect = new ArrayList<Component>(rule.arity());
        for(GdlLiteral literal : rule.getBody()) {
          if(literal instanceof GdlSentence) {
            //Get the sentence post-substitutions
            GdlSentence transformed = CommonTransforms.replaceVariables((GdlSentence) literal, assignment);

            //Check for constant-ness
            SentenceForm conjunctForm = model.getSentenceForm(transformed);
            if(constantChecker.isConstantForm(conjunctForm)) {
              if(!constantChecker.isTrueConstant(transformed)) {
                List<GdlVariable> varsToChange = getVarsInConjunct(literal);
                asnItr.changeOneInNext(varsToChange, assignment);
                componentsToConnect.add(null);
              }
              continue;
            }

            Component conj = components.get(transformed);
            //If conj is null and this is a sentence form we're still handling,
            //hook up to a temporary sentence form
            if(conj == null) {
              conj = temporaryComponents.get(transformed);
            }
            if(conj == null && SentenceModelUtils.inSentenceFormGroup(transformed, recursionForms)) {
              //Set up a temporary component
              Proposition tempProp = new Proposition(transformed);
              temporaryComponents.put(transformed, tempProp);
              conj = tempProp;
            }
            //Let's say this is false; we want to backtrack and change the right variable
            if(conj == null || isThisConstant(conj, falseComponent)) {
              List<GdlVariable> varsInConjunct = getVarsInConjunct(literal);
              asnItr.changeOneInNext(varsInConjunct, assignment);
              //These last steps just speed up the process
              //telling the factory to ignore this rule
              componentsToConnect.add(null);
              continue; //look at all the other restrictions we'll face
            }

            componentsToConnect.add(conj);
          } else if(literal instanceof GdlNot) {
            //Add a "not" if necessary
            //Look up the negation
            GdlSentence internal = (GdlSentence) ((GdlNot) literal).getBody();
            GdlSentence transformed = CommonTransforms.replaceVariables(internal, assignment);

            //Add constant-checking here...
            SentenceForm conjunctForm = model.getSentenceForm(transformed);
            if(constantChecker.isConstantForm(conjunctForm)) {
              if(constantChecker.isTrueConstant(transformed)) {
                List<GdlVariable> varsToChange = getVarsInConjunct(literal);
                asnItr.changeOneInNext(varsToChange, assignment);
                componentsToConnect.add(null);
View Full Code Here

Examples of org.ggp.base.util.gdl.model.SentenceForm

  }

  @Override
  public boolean isTrueConstant(GdlSentence sentence) {
    //TODO: This could be even more efficient; we don't need to bucket by form
    SentenceForm form = sentenceModel.getSentenceForm(sentence);
    return sentencesByForm.get(form).contains(sentence);
  }
View Full Code Here

Examples of org.ggp.base.util.gdl.model.SentenceForm

          //Persistence rule: Exactly one literal, the "true" form of the sentence
          if(rule.arity() == 1) {
            GdlLiteral literal = rule.get(0);
            if(literal instanceof GdlRelation) {
              //Check that it really is the true form
              SentenceForm trueForm = nextForm.withName(GdlPool.getConstant("true"));
              if(trueForm.matches((GdlRelation) literal)) {
                GdlSentence head = rule.getHead();
                GdlSentence body = (GdlSentence) literal;
                //Check that the tuples are the same, and that they
                //consist of distinct variables
                List<GdlTerm> headTuple = GdlUtils.getTupleFromSentence(head);
                List<GdlTerm> bodyTuple = GdlUtils.getTupleFromSentence(body);
                if(headTuple.equals(bodyTuple)) {
                  //Distinct variables?
                  Set<GdlTerm> vars = new HashSet<GdlTerm>(headTuple);
                  if(vars.size() == headTuple.size()) {
                    nextFormsToReplace.add(nextForm);
                  }
                }
              }
            }
          }
        }
      }
    }

    List<Gdl> newDescription = new ArrayList<Gdl>(description);
    //Now, replace the next forms
    for(SentenceForm nextForm : nextFormsToReplace) {
      SentenceForm initForm = nextForm.withName(GdlPool.getConstant("init"));
      SentenceForm trueForm = nextForm.withName(GdlPool.getConstant("true"));

      //Go through the rules and relations, making replacements as needed
      for(int i = 0; i < newDescription.size(); i++) {
        Gdl gdl = newDescription.get(i);
        if(gdl instanceof GdlRelation) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.