Search in sources :

Example 61 with Term

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

the class Narsese method parseStatement.

/**
 * Parse a String to create a Statement.
 *
 * @return the Statement generated from the String
 * @param s0 The addInput String to be parsed
 * @throws nars.io.StringParser.InvalidInputException the String cannot be
 * parsed into a Term
 */
private Statement parseStatement(String s0) throws InvalidInputException {
    String s = s0.trim();
    int i = topRelation(s);
    if (i < 0) {
        throw new InvalidInputException("invalid statement: topRelation(s) < 0");
    }
    String relation = s.substring(i, i + 3);
    Term subject = parseTerm(s.substring(0, i));
    Term predicate = parseTerm(s.substring(i + 3));
    Statement t = make(getRelation(relation), subject, predicate, false, 0);
    if (t == null) {
        throw new InvalidInputException("invalid statement: statement unable to create: " + getOperator(relation) + " " + subject + " " + predicate);
    }
    return t;
}
Also used : Statement(nars.language.Statement) Term(nars.language.Term)

Example 62 with Term

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

the class TaskLink method novel.

public boolean novel(final TermLink termLink, final long currentTime, boolean transformTask) {
    final Term bTerm = termLink.target;
    if (!transformTask && bTerm.equals(targetTask.sentence.term)) {
        return false;
    }
    TermLink linkKey = termLink.name();
    int next, i;
    // iterating the FIFO deque from oldest (first) to newest (last)
    Iterator<Recording> ir = records.iterator();
    while (ir.hasNext()) {
        Recording r = ir.next();
        if (linkKey.equals(r.link)) {
            if (currentTime < r.getTime() + Parameters.NOVELTY_HORIZON) {
                // too recent, not novel
                return false;
            } else {
                // happened long enough ago that we have forgotten it somewhat, making it seem more novel
                r.setTime(currentTime);
                ir.remove();
                records.addLast(r);
                return true;
            }
        }
    }
    // keep recordedLinks queue a maximum finite size
    while (records.size() + 1 >= recordLength) records.removeFirst();
    // add knowledge reference to recordedLinks
    records.addLast(new Recording(linkKey, currentTime));
    return true;
}
Also used : Term(nars.language.Term)

Example 63 with Term

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

the class TermLink method equals.

@Override
public boolean equals(final Object obj) {
    if (obj == this)
        return true;
    if (hashCode() != obj.hashCode())
        return false;
    if (obj instanceof TermLink) {
        TermLink t = (TermLink) obj;
        if (type != t.type)
            return false;
        if (!Arrays.equals(t.index, index))
            return false;
        final Term tt = t.target;
        if (target == null) {
            if (tt != null)
                return false;
        } else if (tt == null) {
            if (target != null)
                return false;
        } else if (!target.equals(t.target))
            return false;
        return true;
    }
    return false;
}
Also used : Term(nars.language.Term)

Example 64 with Term

use of nars.language.Term 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 65 with Term

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

the class SentenceGraph method remove.

public boolean remove(final E s) {
    if (!containsEdge(s))
        return false;
    Term from = getEdgeSource(s);
    Term to = getEdgeTarget(s);
    boolean r = removeEdge(s);
    ensureTermConnected(from);
    ensureTermConnected(to);
    if (r)
        event.emit(GraphChange.class, null, s);
    return true;
}
Also used : CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Aggregations

Term (nars.language.Term)109 CompoundTerm (nars.language.CompoundTerm)66 BudgetValue (nars.entity.BudgetValue)48 TruthValue (nars.entity.TruthValue)46 Sentence (nars.entity.Sentence)40 Task (nars.entity.Task)37 Statement (nars.language.Statement)28 Conjunction (nars.language.Conjunction)20 Inheritance (nars.language.Inheritance)19 Stamp (nars.entity.Stamp)17 Concept (nars.entity.Concept)14 Implication (nars.language.Implication)13 Product (nars.language.Product)11 NAR (nars.main.NAR)9 Interval (nars.language.Interval)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 SetExt (nars.language.SetExt)7 SetInt (nars.language.SetInt)7 Variable (nars.language.Variable)7