Search in sources :

Example 6 with SetExt

use of nars.language.SetExt in project opennars by opennars.

the class StructuralRules method structuralDecompose1.

/**
 * {<(S|T) --> P>, S@(S|T)} |- <S --> P> {<S --> (P&T)>, P@(P&T)} |- <S --> P>
 *
 * @param compound The compound term
 * @param index The location of the indicated term in the compound
 * @param statement The premise
 * @param nal Reference to the memory
 */
static void structuralDecompose1(CompoundTerm compound, short index, Statement statement, DerivationContext nal) {
    if (index >= compound.term.length) {
        return;
    }
    Term component = compound.term[index];
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    int order = sentence.getTemporalOrder();
    TruthValue truth = sentence.truth;
    if (truth == null) {
        return;
    }
    final float reliance = Parameters.reliance;
    TruthValue truthDed = TruthFunctions.deduction(truth, reliance);
    TruthValue truthNDed = TruthFunctions.negation(TruthFunctions.deduction(truth, reliance));
    Term subj = statement.getSubject();
    Term pred = statement.getPredicate();
    if (compound.equals(subj)) {
        if (compound instanceof IntersectionInt) {
            structuralStatement(component, pred, order, truthDed, nal);
        } else if ((compound instanceof SetExt) && (compound.size() > 1)) {
            Term[] t1 = new Term[] { component };
            structuralStatement(new SetExt(t1), pred, order, truthDed, nal);
        } else if (compound instanceof DifferenceInt) {
            if (index == 0) {
                structuralStatement(component, pred, order, truthDed, nal);
            } else {
                structuralStatement(component, pred, order, truthNDed, nal);
            }
        }
    } else if (compound.equals(pred)) {
        if (compound instanceof IntersectionExt) {
            structuralStatement(subj, component, order, truthDed, nal);
        } else if ((compound instanceof SetInt) && (compound.size() > 1)) {
            structuralStatement(subj, new SetInt(component), order, truthDed, nal);
        } else if (compound instanceof DifferenceExt) {
            if (index == 0) {
                structuralStatement(subj, component, order, truthDed, nal);
            } else {
                structuralStatement(subj, component, order, truthNDed, nal);
            }
        }
    }
}
Also used : Task(nars.entity.Task) IntersectionExt(nars.language.IntersectionExt) TruthValue(nars.entity.TruthValue) SetExt(nars.language.SetExt) SetInt(nars.language.SetInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) DifferenceExt(nars.language.DifferenceExt) Sentence(nars.entity.Sentence) IntersectionInt(nars.language.IntersectionInt) DifferenceInt(nars.language.DifferenceInt)

Example 7 with SetExt

use of nars.language.SetExt in project opennars by opennars.

the class StructuralRules method structuralDecompose2.

/**
 * {<(S*T) --> (P*T)>, S@(S*T)} |- <S --> P>
 *
 * @param statement The premise
 * @param nal Reference to the memory
 */
static void structuralDecompose2(Statement statement, int index, DerivationContext nal) {
    Term subj = statement.getSubject();
    Term pred = statement.getPredicate();
    if (subj.getClass() != pred.getClass()) {
        return;
    }
    if (!(subj instanceof Product) && !(subj instanceof SetExt) && !(subj instanceof SetInt)) {
        // no abduction on other compounds for now, but may change in the future
        return;
    }
    CompoundTerm sub = (CompoundTerm) subj;
    CompoundTerm pre = (CompoundTerm) pred;
    if (sub.size() != pre.size() || sub.size() <= index) {
        return;
    }
    Term t1 = sub.term[index];
    Term t2 = pre.term[index];
    Statement content;
    int order = statement.getTemporalOrder();
    if (switchOrder(sub, (short) index)) {
        content = Statement.make(statement, t2, t1, TemporalRules.reverseOrder(order));
    } else {
        content = Statement.make(statement, t1, t2, order);
    }
    if (content == null) {
        return;
    }
    Task task = nal.getCurrentTask();
    Sentence sentence = task.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);
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) SetExt(nars.language.SetExt) Product(nars.language.Product) SetInt(nars.language.SetInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Aggregations

SetExt (nars.language.SetExt)7 Term (nars.language.Term)7 Task (nars.entity.Task)6 CompoundTerm (nars.language.CompoundTerm)6 SetInt (nars.language.SetInt)6 Sentence (nars.entity.Sentence)5 TruthValue (nars.entity.TruthValue)5 BudgetValue (nars.entity.BudgetValue)4 Inheritance (nars.language.Inheritance)4 Statement (nars.language.Statement)4 Conjunction (nars.language.Conjunction)2 DifferenceExt (nars.language.DifferenceExt)2 DifferenceInt (nars.language.DifferenceInt)2 IntersectionExt (nars.language.IntersectionExt)2 IntersectionInt (nars.language.IntersectionInt)2 Product (nars.language.Product)2 Stamp (nars.entity.Stamp)1 TruthFunctions.reduceConjunction (nars.inference.TruthFunctions.reduceConjunction)1 TruthFunctions.reduceDisjunction (nars.inference.TruthFunctions.reduceDisjunction)1 EventObserver (nars.io.events.EventEmitter.EventObserver)1