Package org.ggp.base.util.gdl.model

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


  }

  private static void addSentencesTrueByRulesDifferentially(
      GdlSentenceSet sentencesByForm,
      SentenceDomainModel domainModel, GdlChainingReasoner reasoner) throws InterruptedException {
    SentenceFormModel model = domainModel;
    Set<SentenceForm> constantForms = model.getConstantSentenceForms();
    //Find the part of the dependency graph dealing only with the constant forms.
    Multimap<SentenceForm, SentenceForm> dependencySubgraph =
        Multimaps.filterKeys(model.getDependencyGraph(), Predicates.in(constantForms));
    dependencySubgraph = Multimaps.filterValues(model.getDependencyGraph(), Predicates.in(constantForms));
    dependencySubgraph = ImmutableMultimap.copyOf(dependencySubgraph);
    List<Set<SentenceForm>> ordering = DependencyGraphs.toposortSafe(constantForms, dependencySubgraph);

    for (Set<SentenceForm> stratum : ordering) {
      // One non-differential pass, collecting the changes
      GdlSentenceSet newlyTrueSentences = GdlSentenceSet.create();
      for (SentenceForm form : stratum) {
        for (GdlRule rule : model.getRules(form)) {
          GdlSentenceSet ruleResults =
              reasoner.getRuleResults(rule, domainModel, sentencesByForm);
          if (!reasoner.isSubsetOf(sentencesByForm, ruleResults)) {
            sentencesByForm = reasoner.getUnion(sentencesByForm, ruleResults);
            newlyTrueSentences = reasoner.getUnion(newlyTrueSentences, ruleResults);
          }
        }
      }

      // Now a lot of differential passes to deal with recursion efficiently
      boolean somethingChanged = true;
      while (somethingChanged) {
        somethingChanged = false;
        GdlSentenceSet newStuffInThisPass = GdlSentenceSet.create();
        for (SentenceForm form : stratum) {
          for (GdlRule rule : model.getRules(form)) {
            GdlSentenceSet ruleResults =
                reasoner.getRuleResultsForNewSentences(rule, domainModel, sentencesByForm,
                    newlyTrueSentences);
            if (!reasoner.isSubsetOf(sentencesByForm, ruleResults)) {
              somethingChanged = true;
View Full Code Here


     * @return A modified version of the same game.
     */
    public static List<Gdl> replaceFunctionValuedVariables(List<Gdl> description) throws InterruptedException {
        description = GdlCleaner.run(description);
        description = DeORer.run(description);
        SentenceFormModel model = SentenceFormModelFactory.create(description);

        // Find "ambiguities" between sentence rules: "If we have sentence form X
        // with variables in slots [...], it could be aliased to sentence form Y instead"
        ListMultimap<SentenceForm, Ambiguity> ambiguitiesByOriginalForm = getAmbiguitiesByOriginalForm(model);
        if (ambiguitiesByOriginalForm.isEmpty()) {
View Full Code Here

  public static ImmutableConstantChecker copyOf(ConstantChecker other) {
    if (other instanceof ImmutableConstantChecker) {
      return (ImmutableConstantChecker) other;
    }

    SentenceFormModel model = other.getSentenceFormModel();
    SetMultimap<SentenceForm, GdlSentence> sentencesByForm = HashMultimap.create();
    for (SentenceForm form : other.getConstantSentenceForms()) {
      sentencesByForm.putAll(form, other.getTrueSentences(form));
    }
    return new ImmutableConstantChecker(ImmutableSentenceFormModel.copyOf(model),
View Full Code Here

   * and can reduce the costs in time and memory of processing the game if
   * these statements are instead transformed into sentences.
   * @throws InterruptedException
   */
  public static List<Gdl> run(List<Gdl> description) throws InterruptedException {
    SentenceFormModel model = SentenceFormModelFactory.create(description);
    GdlConstant NEXT = GdlPool.getConstant("next");

    List<SentenceForm> nextFormsToReplace = new ArrayList<SentenceForm>();
    //Find the update rules for each "true" statement
    for(SentenceForm nextForm : model.getSentenceForms()) {
      if(nextForm.getName().equals(NEXT)) {
        //See if there is exactly one update rule, and it is the persistence rule
        Set<GdlRule> rules = model.getRules(nextForm);
        if(rules.size() == 1) {
          GdlRule rule = rules.iterator().next();
          //Persistence rule: Exactly one literal, the "true" form of the sentence
          if(rule.arity() == 1) {
            GdlLiteral literal = rule.get(0);
View Full Code Here

TOP

Related Classes of org.ggp.base.util.gdl.model.SentenceFormModel

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.