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