use of nars.language.Inheritance 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.Inheritance 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.Inheritance in project opennars by opennars.
the class StructuralRules method transformSetRelation.
/* -------------------- set transform -------------------- */
/**
* {<S --> {P}>} |- <S <-> {P}>
*
* @param compound The set compound
* @param statement The premise
* @param side The location of the indicated term in the premise
* @param nal Reference to the memory
*/
static void transformSetRelation(CompoundTerm compound, Statement statement, short side, DerivationContext nal) {
if (compound.size() > 1) {
return;
}
if (statement instanceof Inheritance) {
if (((compound instanceof SetExt) && (side == 0)) || ((compound instanceof SetInt) && (side == 1))) {
return;
}
}
Term sub = statement.getSubject();
Term pre = statement.getPredicate();
Statement content;
if (statement instanceof Inheritance) {
content = Similarity.make(sub, pre);
} else {
if (((compound instanceof SetExt) && (side == 0)) || ((compound instanceof SetInt) && (side == 1))) {
content = Inheritance.make(pre, sub);
} else {
content = Inheritance.make(sub, pre);
}
}
if (content == null) {
return;
}
Task task = nal.getCurrentTask();
Sentence sentence = task.sentence;
TruthValue truth = sentence.truth;
BudgetValue budget;
if (sentence.isJudgment()) {
budget = BudgetFunctions.compoundForward(truth, content, nal);
} else {
budget = BudgetFunctions.compoundBackward(content, nal);
}
nal.singlePremiseTask(content, truth, budget);
}
use of nars.language.Inheritance in project opennars by opennars.
the class StructuralRules method transformPredicatePI.
/**
* Equivalent transformation between products and images when the predicate
* is a compound {<(*, 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 subject The subject term
* @param predicate The predicate term
* @param nal Reference to the memory
*/
private static void transformPredicatePI(short index, Term subject, CompoundTerm predicate, DerivationContext nal) {
TruthValue truth = nal.getCurrentTask().sentence.truth;
BudgetValue budget;
Inheritance inheritance;
Term newSubj, newPred;
if (predicate instanceof Product) {
Product product = (Product) predicate;
short i = index;
/*for (short i = 0; i < product.size(); i++)*/
{
newSubj = ImageInt.make(product, subject, i);
newPred = product.term[i];
inheritance = Inheritance.make(newSubj, newPred);
if (inheritance != null) {
if (truth == null) {
budget = BudgetFunctions.compoundBackward(inheritance, nal);
} else {
budget = BudgetFunctions.compoundForward(truth, inheritance, nal);
}
nal.singlePremiseTask(inheritance, truth, budget);
}
}
} else if (predicate instanceof ImageExt) {
ImageExt image = (ImageExt) predicate;
int relationIndex = image.relationIndex;
for (short i = 0; i < image.size(); i++) {
if (i == relationIndex) {
newSubj = Product.make(image, subject, relationIndex);
newPred = image.term[relationIndex];
} else {
newSubj = image.term[i];
newPred = ImageExt.make(image, subject, i);
}
if (newSubj instanceof CompoundTerm && (newPred.equals(Term.SEQ_TEMPORAL) || newPred.equals(Term.SEQ_SPATIAL))) {
Term seq = Conjunction.make(((CompoundTerm) newSubj).term, TemporalRules.ORDER_FORWARD, newPred.equals(Term.SEQ_SPATIAL));
if (truth == null) {
budget = BudgetFunctions.compoundBackward(seq, nal);
} else {
budget = BudgetFunctions.compoundForward(truth, seq, nal);
}
nal.singlePremiseTask(seq, truth, budget);
return;
}
inheritance = Inheritance.make(newSubj, newPred);
if (inheritance != null) {
// jmv <<<<<
if (truth == null) {
budget = BudgetFunctions.compoundBackward(inheritance, nal);
} else {
budget = BudgetFunctions.compoundForward(truth, inheritance, nal);
}
nal.singlePremiseTask(inheritance, truth, budget);
}
}
}
}
Aggregations