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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations