use of nars.language.Equivalence in project opennars by opennars.
the class RuleTables method syllogisms.
/* ----- syllogistic inferences ----- */
/**
* Meta-table of syllogistic rules, indexed by the content classes of the
* taskSentence and the belief
*
* @param tLink The link to task
* @param bLink The link to belief
* @param taskTerm The content of task
* @param beliefTerm The content of belief
* @param nal Reference to the memory
*/
private static void syllogisms(TaskLink tLink, TermLink bLink, Term taskTerm, Term beliefTerm, DerivationContext nal) {
Sentence taskSentence = nal.getCurrentTask().sentence;
Sentence belief = nal.getCurrentBelief();
int figure;
if (taskTerm instanceof Inheritance) {
if (beliefTerm instanceof Inheritance) {
figure = indexToFigure(tLink, bLink);
asymmetricAsymmetric(taskSentence, belief, figure, nal);
} else if (beliefTerm instanceof Similarity) {
figure = indexToFigure(tLink, bLink);
asymmetricSymmetric(taskSentence, belief, figure, nal);
} else {
detachmentWithVar(belief, taskSentence, bLink.getIndex(0), nal);
}
} else if (taskTerm instanceof Similarity) {
if (beliefTerm instanceof Inheritance) {
figure = indexToFigure(bLink, tLink);
asymmetricSymmetric(belief, taskSentence, figure, nal);
} else if (beliefTerm instanceof Similarity) {
figure = indexToFigure(bLink, tLink);
symmetricSymmetric(belief, taskSentence, figure, nal);
} else if (beliefTerm instanceof Implication) {
// Bridge to higher order statements:
figure = indexToFigure(tLink, bLink);
asymmetricSymmetric(belief, taskSentence, figure, nal);
} else if (beliefTerm instanceof Equivalence) {
// Bridge to higher order statements:
figure = indexToFigure(tLink, bLink);
symmetricSymmetric(belief, taskSentence, figure, nal);
}
} else if (taskTerm instanceof Implication) {
if (beliefTerm instanceof Implication) {
figure = indexToFigure(tLink, bLink);
asymmetricAsymmetric(taskSentence, belief, figure, nal);
} else if (beliefTerm instanceof Equivalence) {
figure = indexToFigure(tLink, bLink);
asymmetricSymmetric(taskSentence, belief, figure, nal);
} else if (beliefTerm instanceof Inheritance) {
detachmentWithVar(taskSentence, belief, tLink.getIndex(0), nal);
} else if (beliefTerm instanceof Similarity) {
// Bridge to higher order statements:
figure = indexToFigure(tLink, bLink);
asymmetricSymmetric(taskSentence, belief, figure, nal);
}
} else if (taskTerm instanceof Equivalence) {
if (beliefTerm instanceof Implication) {
figure = indexToFigure(bLink, tLink);
asymmetricSymmetric(belief, taskSentence, figure, nal);
} else if (beliefTerm instanceof Equivalence) {
figure = indexToFigure(bLink, tLink);
symmetricSymmetric(belief, taskSentence, figure, nal);
} else if (beliefTerm instanceof Inheritance) {
detachmentWithVar(taskSentence, belief, tLink.getIndex(0), nal);
} else if (beliefTerm instanceof Similarity) {
// Bridge to higher order statements:
figure = indexToFigure(tLink, bLink);
symmetricSymmetric(belief, taskSentence, figure, nal);
}
}
}
use of nars.language.Equivalence in project opennars by opennars.
the class RuleTables method transformTask.
/* ----- inference with one TaskLink only ----- */
/**
* The TaskLink is of type TRANSFORM, and the conclusion is an equivalent
* transformation
*
* @param tLink The task link
* @param nal Reference to the memory
*/
public static void transformTask(TaskLink tLink, DerivationContext nal) {
CompoundTerm content = (CompoundTerm) nal.getCurrentTask().getTerm();
short[] indices = tLink.index;
Term inh = null;
if ((indices.length == 2) || (content instanceof Inheritance)) {
// <(*, term, #) --> #>
inh = content;
} else if (indices.length == 3) {
// <<(*, term, #) --> #> ==> #>
inh = content.term[indices[0]];
} else if (indices.length == 4) {
// <(&&, <(*, term, #) --> #>, #) ==> #>
Term component = content.term[indices[0]];
if ((component instanceof Conjunction) && (((content instanceof Implication) && (indices[0] == 0)) || (content instanceof Equivalence))) {
Term[] cterms = ((CompoundTerm) component).term;
if (indices[1] < cterms.length - 1) {
inh = cterms[indices[1]];
} else {
return;
}
} else {
return;
}
}
if (inh instanceof Inheritance) {
StructuralRules.transformProductImage((Inheritance) inh, content, indices, nal);
}
}
use of nars.language.Equivalence in project opennars by opennars.
the class RuleTables method goalFromQuestion.
private static void goalFromQuestion(final Task task, final Term taskTerm, final DerivationContext nal) {
if (task.sentence.punctuation == Symbols.QUESTION_MARK && (taskTerm instanceof Implication || taskTerm instanceof Equivalence)) {
// <a =/> b>? |- a!
Term goalterm = null;
Term goalterm2 = null;
if (taskTerm instanceof Implication) {
Implication imp = (Implication) taskTerm;
if (imp.getTemporalOrder() != TemporalRules.ORDER_BACKWARD || imp.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT) {
if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getSubject() instanceof Operation) {
goalterm = imp.getSubject();
}
if (goalterm instanceof Variable && goalterm.hasVarQuery() && (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getPredicate() instanceof Operation)) {
// overwrite, it is a how question, in case of <?how =/> b> it is b! which is desired
goalterm = imp.getPredicate();
}
} else if (imp.getTemporalOrder() == TemporalRules.ORDER_BACKWARD) {
if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getPredicate() instanceof Operation) {
goalterm = imp.getPredicate();
}
if (goalterm instanceof Variable && goalterm.hasVarQuery() && (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getSubject() instanceof Operation)) {
// overwrite, it is a how question, in case of <?how =/> b> it is b! which is desired
goalterm = imp.getSubject();
}
}
} else if (taskTerm instanceof Equivalence) {
Equivalence qu = (Equivalence) taskTerm;
if (qu.getTemporalOrder() == TemporalRules.ORDER_FORWARD || qu.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT) {
if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || qu.getSubject() instanceof Operation) {
goalterm = qu.getSubject();
}
if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || qu.getPredicate() instanceof Operation) {
goalterm2 = qu.getPredicate();
}
}
}
TruthValue truth = new TruthValue(1.0f, Parameters.DEFAULT_GOAL_CONFIDENCE * Parameters.CURIOSITY_DESIRE_CONFIDENCE_MUL);
if (goalterm != null && !(goalterm instanceof Variable) && goalterm instanceof CompoundTerm) {
goalterm = ((CompoundTerm) goalterm).transformIndependentVariableToDependentVar((CompoundTerm) goalterm);
Sentence sent = new Sentence(goalterm, Symbols.GOAL_MARK, truth, new Stamp(task.sentence.stamp, nal.memory.time()));
nal.singlePremiseTask(sent, new BudgetValue(task.getPriority() * Parameters.CURIOSITY_DESIRE_PRIORITY_MUL, task.getDurability() * Parameters.CURIOSITY_DESIRE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)));
}
if (goalterm2 != null && !(goalterm2 instanceof Variable) && goalterm2 instanceof CompoundTerm) {
goalterm2 = ((CompoundTerm) goalterm).transformIndependentVariableToDependentVar((CompoundTerm) goalterm2);
Sentence sent = new Sentence(goalterm2, Symbols.GOAL_MARK, truth.clone(), new Stamp(task.sentence.stamp, nal.memory.time()));
nal.singlePremiseTask(sent, new BudgetValue(task.getPriority() * Parameters.CURIOSITY_DESIRE_PRIORITY_MUL, task.getDurability() * Parameters.CURIOSITY_DESIRE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)));
}
}
}
use of nars.language.Equivalence in project opennars by opennars.
the class StructuralRules method transformProductImage.
/* -------------------- products and images transform -------------------- */
/**
* Equivalent transformation between products and images {<(*, S, M) --> P>,
* S@(*, S, M)} |- <S --> (/, P, _, M)> {<S --> (/, P, _, M)>, P@(/, P, _,
* M)} |- <(*, S, M) --> P> {<S --> (/, P, _, M)>, M@(/, P, _, M)} |- <M -->
* (/, P, S, _)>
*
* @param inh An Inheritance statement
* @param oldContent The whole content
* @param indices The indices of the TaskLink
* @param task The task
* @param memory Reference to the memory
*/
static void transformProductImage(Inheritance inh, CompoundTerm oldContent, short[] indices, DerivationContext nal) {
final Memory memory = nal.mem();
Term subject = inh.getSubject();
Term predicate = inh.getPredicate();
short index = indices[indices.length - 1];
short side = indices[indices.length - 2];
if (inh.equals(oldContent)) {
if (subject instanceof CompoundTerm) {
transformSubjectPI(index, (CompoundTerm) subject, predicate, nal);
}
if (predicate instanceof CompoundTerm) {
transformPredicatePI(index, subject, (CompoundTerm) predicate, nal);
}
return;
}
Term compT = inh.term[side];
if (!(compT instanceof CompoundTerm))
return;
CompoundTerm comp = (CompoundTerm) compT;
if (comp instanceof Product) {
if (side == 0) {
subject = comp.term[index];
predicate = ImageExt.make((Product) comp, inh.getPredicate(), index);
} else {
subject = ImageInt.make((Product) comp, inh.getSubject(), index);
predicate = comp.term[index];
}
} else if ((comp instanceof ImageExt) && (side == 1)) {
if (index == ((ImageExt) comp).relationIndex) {
subject = Product.make(comp, inh.getSubject(), index);
predicate = comp.term[index];
} else {
subject = comp.term[index];
predicate = ImageExt.make((ImageExt) comp, inh.getSubject(), index);
}
} else if ((comp instanceof ImageInt) && (side == 0)) {
if (index == ((ImageInt) comp).relationIndex) {
subject = comp.term[index];
predicate = Product.make(comp, inh.getPredicate(), index);
} else {
subject = ImageInt.make((ImageInt) comp, inh.getPredicate(), index);
predicate = comp.term[index];
}
} else {
return;
}
CompoundTerm newInh = null;
if (predicate.equals(Term.SEQ_SPATIAL)) {
newInh = (CompoundTerm) Conjunction.make(((CompoundTerm) subject).term, TemporalRules.ORDER_FORWARD, true);
} else if (predicate.equals(Term.SEQ_TEMPORAL)) {
newInh = (CompoundTerm) Conjunction.make(((CompoundTerm) subject).term, TemporalRules.ORDER_FORWARD, false);
} else {
newInh = Inheritance.make(subject, predicate);
}
if (newInh == null)
return;
CompoundTerm content = null;
if (indices.length == 2) {
content = newInh;
} else if ((oldContent instanceof Statement) && (indices[0] == 1)) {
content = Statement.make((Statement) oldContent, oldContent.term[0], newInh, oldContent.getTemporalOrder());
} else {
Term[] componentList;
Term condition = oldContent.term[0];
if (((oldContent instanceof Implication) || (oldContent instanceof Equivalence)) && (condition instanceof Conjunction)) {
componentList = ((CompoundTerm) condition).cloneTerms();
componentList[indices[1]] = newInh;
Term newCond = Terms.term((CompoundTerm) condition, componentList);
content = Statement.make((Statement) oldContent, newCond, ((Statement) oldContent).getPredicate(), oldContent.getTemporalOrder());
} else {
componentList = oldContent.cloneTerms();
componentList[indices[0]] = newInh;
if (oldContent instanceof Conjunction) {
Term newContent = Terms.term(oldContent, componentList);
if (!(newContent instanceof CompoundTerm))
return;
content = (CompoundTerm) newContent;
} else if ((oldContent instanceof Implication) || (oldContent instanceof Equivalence)) {
content = Statement.make((Statement) oldContent, componentList[0], componentList[1], oldContent.getTemporalOrder());
}
}
}
if (content == null)
return;
Sentence sentence = nal.getCurrentTask().sentence;
TruthValue truth = sentence.truth;
BudgetValue budget;
if (sentence.isQuestion() || sentence.isQuest()) {
budget = BudgetFunctions.compoundBackward(content, nal);
} else {
budget = BudgetFunctions.compoundForward(truth, content, nal);
}
nal.singlePremiseTask(content, truth, budget);
}
Aggregations