コード例 #1
0
ファイル: RuleTables.java プロジェクト: jnorthrup/open-nars
 /**
  * Syllogistic rules whose both premises are on the same symmetric relation
  *
  * @param belief The premise that comes from a belief
  * @param taskSentence The premise that comes from a task
  * @param figure The location of the shared term
  * @param memory Reference to the memory
  */
 private static void symmetricSymmetric(
     Sentence belief, Sentence taskSentence, int figure, Memory memory) {
   Statement s1 = (Statement) belief.cloneContent();
   Statement s2 = (Statement) taskSentence.cloneContent();
   switch (figure) {
     case 11:
       if (Variable.unify(Symbols.VAR_INDEPENDENT, s1.getSubject(), s2.getSubject(), s1, s2)) {
         SyllogisticRules.resemblance(
             s1.getPredicate(), s2.getPredicate(), belief, taskSentence, figure, memory);
       }
       break;
     case 12:
       if (Variable.unify(Symbols.VAR_INDEPENDENT, s1.getSubject(), s2.getPredicate(), s1, s2)) {
         SyllogisticRules.resemblance(
             s1.getPredicate(), s2.getSubject(), belief, taskSentence, figure, memory);
       }
       break;
     case 21:
       if (Variable.unify(Symbols.VAR_INDEPENDENT, s1.getPredicate(), s2.getSubject(), s1, s2)) {
         SyllogisticRules.resemblance(
             s1.getSubject(), s2.getPredicate(), belief, taskSentence, figure, memory);
       }
       break;
     case 22:
       if (Variable.unify(Symbols.VAR_INDEPENDENT, s1.getPredicate(), s2.getPredicate(), s1, s2)) {
         SyllogisticRules.resemblance(
             s1.getSubject(), s2.getSubject(), belief, taskSentence, figure, memory);
       }
       break;
   }
 }
コード例 #2
0
ファイル: RuleTables.java プロジェクト: jnorthrup/open-nars
 /**
  * Inference between a compound term and a statement
  *
  * @param compound The compound term
  * @param index The location of the current term in the compound
  * @param statement The statement
  * @param side The location of the current term in the statement
  * @param beliefTerm The content of the belief
  * @param memory Reference to the memory
  */
 private static void compoundAndStatement(
     CompoundTerm compound,
     short index,
     Statement statement,
     short side,
     Term beliefTerm,
     Memory memory) {
   Term component = compound.componentAt(index);
   Task task = memory.currentTask;
   if (component.getClass() == statement.getClass()) {
     if ((compound instanceof Conjunction) && (memory.currentBelief != null)) {
       if (Variable.unify(Symbols.VAR_DEPENDENT, component, statement, compound, statement)) {
         SyllogisticRules.elimiVarDep(compound, component, statement.equals(beliefTerm), memory);
       } else if (task.getSentence().isJudgment()) {
         CompositionalRules.introVarInner(statement, (Statement) component, compound, memory);
       }
     }
   } else {
     if (!task.isStructural() && task.getSentence().isJudgment()) {
       if (statement instanceof Inheritance) {
         StructuralRules.structuralCompose1(compound, index, statement, memory);
         //                    if (!(compound instanceof SetExt) && !(compound instanceof SetInt))
         // {
         if (!(compound instanceof SetExt
             || compound instanceof SetInt
             || compound instanceof Negation)) {
           StructuralRules.structuralCompose2(compound, index, statement, side, memory);
         } // {A --> B, A @ (A&C)} |- (A&C) --> (B&C)
       } else if ((statement instanceof Similarity) && !(compound instanceof Conjunction)) {
         StructuralRules.structuralCompose2(compound, index, statement, side, memory);
       } // {A <-> B, A @ (A&C)} |- (A&C) <-> (B&C)
     }
   }
 }
コード例 #3
0
ファイル: RuleTables.java プロジェクト: jnorthrup/open-nars
 /**
  * Syllogistic rules whose first premise is on an asymmetric relation, and the second on a
  * symmetric relation
  *
  * @param asym The asymmetric premise
  * @param sym The symmetric premise
  * @param figure The location of the shared term
  * @param memory Reference to the memory
  */
 private static void asymmetricSymmetric(Sentence asym, Sentence sym, int figure, Memory memory) {
   Statement asymSt = (Statement) asym.cloneContent();
   Statement symSt = (Statement) sym.cloneContent();
   Term t1, t2;
   switch (figure) {
     case 11:
       if (Variable.unify(
           Symbols.VAR_INDEPENDENT, asymSt.getSubject(), symSt.getSubject(), asymSt, symSt)) {
         t1 = asymSt.getPredicate();
         t2 = symSt.getPredicate();
         if (Variable.unify(Symbols.VAR_QUERY, t1, t2, asymSt, symSt)) {
           LocalRules.matchAsymSym(asym, sym, figure, memory);
         } else {
           SyllogisticRules.analogy(t2, t1, asym, sym, figure, memory);
         }
       }
       break;
     case 12:
       if (Variable.unify(
           Symbols.VAR_INDEPENDENT, asymSt.getSubject(), symSt.getPredicate(), asymSt, symSt)) {
         t1 = asymSt.getPredicate();
         t2 = symSt.getSubject();
         if (Variable.unify(Symbols.VAR_QUERY, t1, t2, asymSt, symSt)) {
           LocalRules.matchAsymSym(asym, sym, figure, memory);
         } else {
           SyllogisticRules.analogy(t2, t1, asym, sym, figure, memory);
         }
       }
       break;
     case 21:
       if (Variable.unify(
           Symbols.VAR_INDEPENDENT, asymSt.getPredicate(), symSt.getSubject(), asymSt, symSt)) {
         t1 = asymSt.getSubject();
         t2 = symSt.getPredicate();
         if (Variable.unify(Symbols.VAR_QUERY, t1, t2, asymSt, symSt)) {
           LocalRules.matchAsymSym(asym, sym, figure, memory);
         } else {
           SyllogisticRules.analogy(t1, t2, asym, sym, figure, memory);
         }
       }
       break;
     case 22:
       if (Variable.unify(
           Symbols.VAR_INDEPENDENT, asymSt.getPredicate(), symSt.getPredicate(), asymSt, symSt)) {
         t1 = asymSt.getSubject();
         t2 = symSt.getSubject();
         if (Variable.unify(Symbols.VAR_QUERY, t1, t2, asymSt, symSt)) {
           LocalRules.matchAsymSym(asym, sym, figure, memory);
         } else {
           SyllogisticRules.analogy(t1, t2, asym, sym, figure, memory);
         }
       }
       break;
   }
 }
コード例 #4
0
ファイル: RuleTables.java プロジェクト: jnorthrup/open-nars
 /**
  * Conditional deduction or induction, with variable unification
  *
  * @param conditional The premise that is an Implication with a Conjunction as condition
  * @param index The location of the shared term in the condition
  * @param statement The second premise that is a statement
  * @param side The location of the shared term in the statement
  * @param memory Reference to the memory
  */
 private static void conditionalDedIndWithVar(
     Implication conditional, short index, Statement statement, short side, Memory memory) {
   CompoundTerm condition = (CompoundTerm) conditional.getSubject();
   Term component = condition.componentAt(index);
   Term component2 = null;
   if (statement instanceof Inheritance) {
     component2 = statement;
     side = -1;
   } else if (statement instanceof Implication) {
     component2 = statement.componentAt(side);
   }
   if ((component2 != null)
       && Variable.unify(Symbols.VAR_INDEPENDENT, component, component2, conditional, statement)) {
     SyllogisticRules.conditionalDedInd(conditional, index, statement, side, memory);
   }
 }
コード例 #5
0
ファイル: RuleTables.java プロジェクト: jnorthrup/open-nars
 /**
  * The detachment rule, with variable unification
  *
  * @param originalMainSentence The premise that is an Implication or Equivalence
  * @param subSentence The premise that is the subject or predicate of the first one
  * @param index The location of the second premise in the first
  * @param memory Reference to the memory
  */
 private static void detachmentWithVar(
     Sentence originalMainSentence, Sentence subSentence, int index, Memory memory) {
   Sentence mainSentence = (Sentence) originalMainSentence.clone(); // for substitution
   Statement statement = (Statement) mainSentence.getContent();
   Term component = statement.componentAt(index);
   Term content = subSentence.getContent();
   if ((component instanceof Inheritance) && (memory.currentBelief != null)) {
     if (component.isConstant()) {
       SyllogisticRules.detachment(mainSentence, subSentence, index, memory);
     } else if (Variable.unify(Symbols.VAR_INDEPENDENT, component, content, statement, content)) {
       SyllogisticRules.detachment(mainSentence, subSentence, index, memory);
     } else if ((statement instanceof Implication)
         && (statement.getPredicate() instanceof Statement)
         && (memory.currentTask.getSentence().isJudgment())) {
       Statement s2 = (Statement) statement.getPredicate();
       if (s2.getSubject().equals(((Statement) content).getSubject())) {
         CompositionalRules.introVarInner((Statement) content, s2, statement, memory);
       }
     }
   }
 }
コード例 #6
0
ファイル: RuleTables.java プロジェクト: jnorthrup/open-nars
  /**
   * Syllogistic rules whose both premises are on the same asymmetric relation
   *
   * @param sentence The taskSentence in the task
   * @param belief The judgment in the belief
   * @param figure The location of the shared term
   * @param memory Reference to the memory
   */
  private static void asymmetricAsymmetric(
      Sentence sentence, Sentence belief, int figure, Memory memory) {
    Statement s1 = (Statement) sentence.cloneContent();
    Statement s2 = (Statement) belief.cloneContent();
    Term t1, t2;
    switch (figure) {
      case 11: // induction
        if (Variable.unify(Symbols.VAR_INDEPENDENT, s1.getSubject(), s2.getSubject(), s1, s2)) {
          if (s1.equals(s2)) {
            return;
          }
          t1 = s2.getPredicate();
          t2 = s1.getPredicate();
          SyllogisticRules.abdIndCom(t1, t2, sentence, belief, figure, memory);
          CompositionalRules.composeCompound(s1, s2, 0, memory);
        }

        break;
      case 12: // deduction
        if (Variable.unify(Symbols.VAR_INDEPENDENT, s1.getSubject(), s2.getPredicate(), s1, s2)) {
          if (s1.equals(s2)) {
            return;
          }
          t1 = s2.getSubject();
          t2 = s1.getPredicate();
          if (Variable.unify(Symbols.VAR_QUERY, t1, t2, s1, s2)) {
            LocalRules.matchReverse(memory);
          } else {
            SyllogisticRules.dedExe(t1, t2, sentence, belief, memory);
          }
        }
        break;
      case 21: // exemplification
        if (Variable.unify(Symbols.VAR_INDEPENDENT, s1.getPredicate(), s2.getSubject(), s1, s2)) {
          if (s1.equals(s2)) {
            return;
          }
          t1 = s1.getSubject();
          t2 = s2.getPredicate();
          if (Variable.unify(Symbols.VAR_QUERY, t1, t2, s1, s2)) {
            LocalRules.matchReverse(memory);
          } else {
            SyllogisticRules.dedExe(t1, t2, sentence, belief, memory);
          }
        }
        break;
      case 22: // abduction
        if (Variable.unify(Symbols.VAR_INDEPENDENT, s1.getPredicate(), s2.getPredicate(), s1, s2)) {
          if (s1.equals(s2)) {
            return;
          }
          t1 = s1.getSubject();
          t2 = s2.getSubject();
          if (!SyllogisticRules.conditionalAbd(
              t1, t2, s1, s2, memory)) { // if conditional abduction, skip the following
            SyllogisticRules.abdIndCom(t1, t2, sentence, belief, figure, memory);
            CompositionalRules.composeCompound(s1, s2, 1, memory);
          }
        }
        break;
      default:
    }
  }
コード例 #7
0
ファイル: SyllogisticRules.java プロジェクト: automenta/jcog
 /**
  * {<(&&, S1, S2, S3) ==> P>, S1} |- <(&&, S2, S3) ==> P> {<(&&, S2, S3) ==> P>, <S1 ==> S2>} |-
  * <(&&, S1, S3) ==> P> {<(&&, S1, S3) ==> P>, <S1 ==> S2>} |- <(&&, S2, S3) ==> P>
  *
  * @param premise1 The conditional premise
  * @param index The location of the shared term in the condition of premise1
  * @param premise2 The premise which, or part of which, appears in the condition of premise1
  * @param side The location of the shared term in premise2: 0 for subject, 1 for predicate, -1 for
  *     the whole term
  */
 static void conditionalDedInd(Implication premise1, short index, Term premise2, int side) {
   Task task = Memory.currentTask;
   Sentence taskSentence = task.getSentence();
   Judgment belief = Memory.currentBelief;
   boolean deduction = (side != 0);
   HashMap substitute =
       Variable.findSubstitute(Variable.VarType.ALL, premise2, belief.getContent());
   boolean conditionalTask = (substitute != null);
   TemporalValue tense1 = (conditionalTask ? taskSentence.getTense() : belief.getTense());
   TemporalValue tense2 = (conditionalTask ? belief.getTense() : taskSentence.getTense());
   TemporalValue order1 = premise1.getOrder();
   TemporalValue order2 = premise2.getOrder();
   if ((side == -1) && (tense2 != null) && (tense2.getDelta() > 0)) {
     return;
   }
   if ((side == 0) && (order2 != null) && (order2.getDelta() > 0)) {
     return;
   }
   if ((side == 1) && (order2 != null) && (order2.getDelta() < 0)) {
     return;
   }
   TemporalValue tense = TemporalRules.syllogistic(tense1, tense2);
   if (tense != null) {
     tense = new TemporalValue(0);
   }
   Term commonComponent;
   Term newComponent = null;
   if (side == 0) {
     commonComponent = ((RDFStatement) premise2).getSubject();
     newComponent = ((RDFStatement) premise2).getPredicate();
   } else if (side == 1) {
     commonComponent = ((RDFStatement) premise2).getPredicate();
     newComponent = ((RDFStatement) premise2).getSubject();
   } else {
     commonComponent = premise2;
   }
   Conjunction oldCondition = (Conjunction) premise1.getSubject();
   boolean match =
       Variable.unify(
           Variable.VarType.INDEPENDENT,
           oldCondition.componentAt(index),
           commonComponent,
           premise1,
           premise2);
   if (!match && (commonComponent.getClass() == oldCondition.getClass())) {
     match =
         Variable.unify(
             Variable.VarType.INDEPENDENT,
             oldCondition.componentAt(index),
             ((CompoundTerm) commonComponent).componentAt(index),
             premise1,
             premise2);
   }
   if (!match) {
     return;
   }
   Term newCondition;
   if (oldCondition.equals(commonComponent)) {
     newCondition = null;
   } else {
     newCondition = CompoundTerm.replaceComponent(oldCondition, index, newComponent);
     if ((newCondition instanceof Conjunction) && ((CompoundTerm) newCondition).size() == 1) {
       newCondition = ((CompoundTerm) newCondition).componentAt(0);
     }
   }
   Term content;
   if (newCondition != null) {
     content = RDFStatement.make(premise1, newCondition, premise1.getPredicate(), order1);
   } else {
     content = premise1.getPredicate();
   }
   if (content == null) {
     return;
   }
   TruthValue truth1 = taskSentence.getTruth();
   TruthValue truth2 = belief.getTruth();
   TruthValue truth = null;
   BudgetValue budget;
   if (taskSentence instanceof Question) {
     budget = BudgetFunctions.backwardWeak(truth2);
   } else {
     if (taskSentence instanceof Goal) {
       if (conditionalTask) {
         truth = TruthFunctions.desireWeak(truth1, truth2);
       } else if (deduction) {
         truth = TruthFunctions.desireInd(truth1, truth2);
       } else {
         truth = TruthFunctions.desireDed(truth1, truth2);
       }
       budget = BudgetFunctions.forward(truth);
     } else {
       if (deduction) {
         truth = TruthFunctions.deduction(truth1, truth2);
       } else if (conditionalTask) {
         truth = TruthFunctions.induction(truth2, truth1);
       } else {
         truth = TruthFunctions.induction(truth1, truth2);
       }
     }
     budget = BudgetFunctions.forward(truth);
   }
   Memory.currentTense = tense;
   Memory.doublePremiseTask(budget, content, truth);
 }