Search in sources :

Example 26 with CompoundTerm

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

the class Concept method buildTermLinks.

/**
 * Recursively build TermLinks between a compound and its components
 * <p>
 * called only from Memory.continuedProcess
 *
 * @param taskBudget The BudgetValue of the task
 */
public void buildTermLinks(final BudgetValue taskBudget) {
    if (termLinkTemplates.size() == 0) {
        return;
    }
    BudgetValue subBudget = distributeAmongLinks(taskBudget, termLinkTemplates.size());
    if (!subBudget.aboveThreshold()) {
        return;
    }
    for (final TermLink template : termLinkTemplates) {
        if (template.type == TermLink.TRANSFORM) {
            continue;
        }
        Term target = template.target;
        final Concept concept = memory.conceptualize(taskBudget, target);
        if (concept == null) {
            continue;
        }
        // this termLink to that and vice versa
        insertTermLink(new TermLink(target, template, subBudget));
        concept.insertTermLink(new TermLink(term, template, subBudget));
        if (target instanceof CompoundTerm && template.type != TermLink.TEMPORAL) {
            concept.buildTermLinks(subBudget);
        }
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 27 with CompoundTerm

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

the class FunctionOperator method execute.

// abstract protected int getMinArity();
// abstract protected int getMaxArity();
@Override
protected ArrayList<Task> execute(Operation operation, Term[] args, Memory m) {
    // TODO make memory access optional by constructor argument
    // TODO allow access to NAR instance?
    int numArgs = args.length - 1;
    if (numArgs < 1) {
        throw new RuntimeException("Requires at least 1 arguments");
    }
    if (numArgs < 2) /*&& !(this instanceof Javascript)*/
    {
        throw new RuntimeException("Requires at least 2 arguments");
    }
    // last argument a variable?
    Term lastTerm = args[numArgs];
    boolean variable = lastTerm instanceof Variable;
    if (!variable) /*&& !(this instanceof Javascript)*/
    {
        throw new RuntimeException("output can not be specified");
    }
    int numParam = numArgs - 1;
    /*if(this instanceof Javascript && !variable) {
            numParam++;
        }*/
    Term[] x = new Term[numParam];
    System.arraycopy(args, 1, x, 0, numParam);
    Term y;
    // try {
    y = function(m, x);
    if (y == null) {
        return null;
    }
    /*if(!variable && this instanceof Javascript) {
                return null;
            }*/
    // m.emit(SynchronousFunctionOperator.class, Arrays.toString(x) + " | " + y);
    /*}
        catch (Exception e) {
            throw e;
        }*/
    Variable var = new Variable("$1");
    // Term actual_part = Similarity.make(var, y);
    // Variable vardep=new Variable("#1");
    // Term actual_dep_part = Similarity.make(vardep, y);
    operation = (Operation) operation.setComponent(0, ((CompoundTerm) operation.getSubject()).setComponent(numArgs, y, m), m);
    float confidence = Parameters.DEFAULT_JUDGMENT_CONFIDENCE;
    if (variable) {
        Sentence s = new Sentence(operation, Symbols.JUDGMENT_MARK, new TruthValue(1.0f, Parameters.DEFAULT_JUDGMENT_CONFIDENCE), new Stamp(m));
        return Lists.newArrayList(new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, Parameters.DEFAULT_FEEDBACK_DURABILITY, truthToQuality(s.getTruth())), true));
    } else {
        return null;
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Variable(nars.language.Variable) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 28 with CompoundTerm

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

the class ImplicationGraph method add.

@Override
public boolean add(Sentence s, CompoundTerm ct, Item c) {
    if (ct instanceof Statement) {
        Statement st = (Statement) ct;
        Term subject = st.getSubject();
        Term predicate = st.getPredicate();
        addVertex(subject);
        addVertex(predicate);
        System.out.println(subject.toString().trim() + " " + predicate.toString().trim() + " " + s.truth.getExpectation() + s.truth.getFrequency() + " " + s.truth.getConfidence() + " " + " Implication");
        addEdge(subject, predicate, s);
        return true;
    }
    return false;
}
Also used : Statement(nars.language.Statement) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 29 with CompoundTerm

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

the class TermTest method testUnconceptualizedTermInstancing.

@Test
public void testUnconceptualizedTermInstancing() throws Narsese.InvalidInputException {
    NAR n = new NAR();
    String term1String = "<a --> b>";
    Term term1 = np.parseTerm(term1String);
    Term term2 = np.parseTerm(term1String);
    assertTrue(term1.equals(term2));
    assertTrue(term1.hashCode() == term2.hashCode());
    CompoundTerm cterm1 = ((CompoundTerm) term1);
    CompoundTerm cterm2 = ((CompoundTerm) term2);
    // test subterms
    // 'a'
    assertTrue(cterm1.term[0].equals(cterm2.term[0]));
}
Also used : CompoundTerm(nars.language.CompoundTerm) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) NAR(nars.main.NAR) Test(org.junit.Test)

Example 30 with CompoundTerm

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

the class TermSyntaxVis method addSyntax.

public static Term addSyntax(NARGraph g, Term t) {
    if (t instanceof CompoundTerm) {
        CompoundTerm ct = (CompoundTerm) t;
        g.addVertex(ct);
        int n = 0;
        for (Term s : ct.term) {
            Term v = addSyntax(g, s);
            g.addEdge(ct, v, new UniqueEdge(ct.operator() + ":" + n));
            n++;
        }
        return ct;
    } else {
        g.addVertex(t);
        return t;
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) UniqueEdge(nars.gui.util.NARGraph.UniqueEdge) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Aggregations

CompoundTerm (nars.language.CompoundTerm)46 Term (nars.language.Term)43 TruthValue (nars.entity.TruthValue)30 BudgetValue (nars.entity.BudgetValue)27 Sentence (nars.entity.Sentence)20 Statement (nars.language.Statement)19 Conjunction (nars.language.Conjunction)18 Task (nars.entity.Task)17 Inheritance (nars.language.Inheritance)13 Implication (nars.language.Implication)8 HashMap (java.util.HashMap)7 Variable (nars.language.Variable)7 Interval (nars.language.Interval)6 SetExt (nars.language.SetExt)6 SetInt (nars.language.SetInt)6 Product (nars.language.Product)5 TruthFunctions.reduceConjunction (nars.inference.TruthFunctions.reduceConjunction)4 Equivalence (nars.language.Equivalence)4 ImageExt (nars.language.ImageExt)4 ImageInt (nars.language.ImageInt)4