本文整理汇总了Java中nars.language.Term类的典型用法代码示例。如果您正苦于以下问题:Java Term类的具体用法?Java Term怎么用?Java Term使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Term类属于nars.language包,在下文中一共展示了Term类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseOutput
import nars.language.Term; //导入依赖的package包/类
public static Sentence parseOutput(String s) {
Term content = null;
char punc = 0;
TruthValue truth = null;
try {
StringBuffer buffer = new StringBuffer(s);
//String budgetString = getBudgetString(buffer);
String truthString = getTruthString(buffer);
String str = buffer.toString().trim();
int last = str.length() - 1;
punc = str.charAt(last);
//Stamp stamp = new Stamp(time);
truth = parseTruth(truthString, punc);
/*Term content = parseTerm(str.substring(0, last), memory);
if (content == null) throw new InvalidInputException("Content term missing");*/
}
catch (InvalidInputException e) {
System.err.println("TextInput.parseOutput: " + s + " : " + e.toString());
}
return new Sentence(content, punc, truth, null);
}
示例2: TermLink
import nars.language.Term; //导入依赖的package包/类
/**
* Constructor for TermLink template
* <p>
* called in CompoundTerm.prepareComponentLinks only
* @param t Target Term
* @param p Link type
* @param indices Component indices in compound, may be 1 to 4
*/
public TermLink(Term t, short p, int... indices) {
target = t;
type = p;
assert (type % 2 == 0); // template types all point to compound, though the target is component
if (type == TermLink.COMPOUND_CONDITION) { // the first index is 0 by default
index = new short[indices.length + 1];
index[0] = 0;
for (int i = 0; i < indices.length; i++) {
index[i + 1] = (short) indices[i];
}
} else {
index = new short[indices.length];
for (int i = 0; i < index.length; i++) {
index[i] = (short) indices[i];
}
}
}
示例3: linkToTask
import nars.language.Term; //导入依赖的package包/类
/**
* Link to a new task from all relevant concepts for continued processing in
* the near future for unspecified time.
* <p>
* The only method that calls the TaskLink constructor.
* @param task The task to be linked
* @param content The content of the task
*/
private void linkToTask(Task task) {
BudgetValue taskBudget = task.getBudget();
TaskLink taskLink = new TaskLink(task, null, taskBudget); // link type: SELF
insertTaskLink(taskLink);
if (term instanceof CompoundTerm) {
if (termLinkTemplates.size() > 0) {
BudgetValue subBudget = BudgetFunctions.distributeAmongLinks(taskBudget, termLinkTemplates.size());
if (subBudget.aboveThreshold()) {
Term componentTerm;
Concept componentConcept;
for (TermLink termLink : termLinkTemplates) {
// if (!(task.isStructural() && (termLink.getType() == TermLink.TRANSFORM))) { // avoid circular transform
taskLink = new TaskLink(task, termLink, subBudget);
componentTerm = termLink.getTarget();
componentConcept = memory.getConcept(componentTerm);
if (componentConcept != null) {
componentConcept.insertTaskLink(taskLink);
}
// }
}
buildTermLinks(taskBudget); // recursively insert TermLink
}
}
}
}
示例4: buildTermLinks
import nars.language.Term; //导入依赖的package包/类
/**
* 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(BudgetValue taskBudget) {
Term t;
Concept concept;
TermLink termLink1, termLink2;
if (termLinkTemplates.size() > 0) {
BudgetValue subBudget = BudgetFunctions.distributeAmongLinks(taskBudget, termLinkTemplates.size());
if (subBudget.aboveThreshold()) {
for (TermLink template : termLinkTemplates) {
if (template.getType() != TermLink.TRANSFORM) {
t = template.getTarget();
concept = memory.getConcept(t);
if (concept != null) {
termLink1 = new TermLink(t, template, subBudget);
insertTermLink(termLink1); // this termLink to that
termLink2 = new TermLink(term, template, subBudget);
concept.insertTermLink(termLink2); // that termLink to this
if (t instanceof CompoundTerm) {
concept.buildTermLinks(subBudget);
}
}
}
}
}
}
}
示例5: linkToTask
import nars.language.Term; //导入依赖的package包/类
/**
* Link to a new task from all relevant concepts for continued processing in
* the near future for unspecified time.
* <p>
* The only method that calls the TaskLink constructor.
*
* @param task The task to be linked
* @param content The content of the task
*/
private void linkToTask(final Task task) {
final BudgetValue taskBudget = task.getBudget();
insertTaskLink(new TaskLink(task, null, taskBudget)); // link type: SELF
if (term instanceof CompoundTerm) {
if (!termLinkTemplates.isEmpty()) {
final BudgetValue subBudget = BudgetFunctions.distributeAmongLinks(taskBudget, termLinkTemplates.size());
if (subBudget.aboveThreshold()) {
for (final TermLink termLink : termLinkTemplates) {
// if (!(task.isStructural() && (termLink.getType() == TermLink.TRANSFORM))) { // avoid circular transform
Term componentTerm = termLink.getTarget();
Concept componentConcept = memory.getConcept(componentTerm);
if (componentConcept != null) {
componentConcept.insertTaskLink(new TaskLink(task, termLink, subBudget));
}
// }
}
buildTermLinks(taskBudget); // recursively insert TermLink
}
}
}
}
示例6: buildTermLinks
import nars.language.Term; //导入依赖的package包/类
/**
* 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) {
BudgetValue subBudget = BudgetFunctions.distributeAmongLinks(taskBudget, termLinkTemplates.size());
if (subBudget.aboveThreshold()) {
for (final TermLink template : termLinkTemplates) {
if (template.getType() != TermLink.TRANSFORM) {
Term t = template.getTarget();
final Concept concept = memory.getConcept(t);
if (concept != null) {
TermLink termLink1 = new TermLink(t, template, subBudget);
insertTermLink(termLink1); // this termLink to that
TermLink termLink2 = new TermLink(term, template, subBudget);
concept.insertTermLink(termLink2); // that termLink to this
if (t instanceof CompoundTerm) {
concept.buildTermLinks(subBudget);
}
}
}
}
}
}
}
示例7: parseArguments
import nars.language.Term; //导入依赖的package包/类
/**
* Parse a String into the argument get of a CompoundTerm.
*
* @return the arguments in an ArrayList
* @param s0 The String to be parsed
* @throws nars.io.StringParser.InvalidInputException the String cannot be
* parsed into an argument get
*/
private static ArrayList<Term> parseArguments(String s0, Memory memory) throws InvalidInputException {
String s = s0.trim();
ArrayList<Term> list = new ArrayList<>();
int start = 0;
int end = 0;
Term t;
while (end < s.length() - 1) {
end = nextSeparator(s, start);
t = parseTerm(s.substring(start, end), memory); // recursive call
list.add(t);
start = end + 1;
}
if (list.isEmpty()) {
throw new InvalidInputException("null argument");
}
return list;
}
示例8: parseAtomicTerm
import nars.language.Term; //导入依赖的package包/类
/**
* Parse a Term that has no internal structure.
* <p>
* The Term can be a constant or a variable.
*
* @param s0 the String to be parsed
* @throws nars.io.StringParser.InvalidInputException the String cannot be
* parsed into a Term
* @return the Term generated from the String
*/
private static Term parseAtomicTerm(String s0) throws InvalidInputException {
String s = s0.trim();
if (s.length() == 0) {
throw new InvalidInputException("missing term");
}
if (s.contains(" ")) // invalid characters in a name
{
throw new InvalidInputException("invalid term");
}
if (Variable.containVar(s)) {
return new Variable(s);
} else {
return new Term(s);
}
}
示例9: parseStatement
import nars.language.Term; //导入依赖的package包/类
/**
* Parse a String to create a Statement.
*
* @return the Statement generated from the String
* @param s0 The input String to be parsed
* @throws nars.io.StringParser.InvalidInputException the String cannot be
* parsed into a Term
*/
private static Statement parseStatement(String s0, Memory memory) 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), memory);
Term predicate = parseTerm(s.substring(i + 3), memory);
Statement t = Statement.make(Statement.getRelation(relation), subject, predicate, memory);
if (t == null) {
throw new InvalidInputException("invalid statement: statement unable to create: " + Statement.getRelation(relation) + " " + subject + " " + predicate);
}
return t;
}
示例10: Obj
import nars.language.Term; //导入依赖的package包/类
public Obj(int index, int level, Term term, int type, long creationTime) {
if (mode == 1) {
this.y = -200 - (index * rowHeight);
this.x = 2600 - (level * colWidth);
}
else if (mode == 0) {
float LEVELRAD = maxNodeSize;
double radius = ((mem.concepts.levels - level)+1);
float angle = index; //TEMPORARY
this.x = (float)(Math.cos(angle/3.0) * radius) * LEVELRAD;
this.y = (float)(Math.sin(angle/3.0) * radius) * LEVELRAD;
}
this.name = term;
this.type = type;
this.creationTime = creationTime;
}
示例11: novel
import nars.language.Term; //导入依赖的package包/类
/**
* To check whether a TaskLink should use a TermLink, return false if they
* interacted recently
* <p>
* called in TermLinkBag only
* @param termLink The TermLink to be checked
* @param currentTime The current time
* @return Whether they are novel to each other
*/
public boolean novel(TermLink termLink, long currentTime) {
Term bTerm = termLink.getTarget();
if (bTerm.equals(targetTask.getSentence().getContent())) {
return false;
}
String linkKey = termLink.getKey();
int next = 0;
int i;
for (i = 0; i < counter; i++) {
next = i % Parameters.TERM_LINK_RECORD_LENGTH;
if (linkKey.equals(recordedLinks[next])) {
if (currentTime < recordingTime[next] + Parameters.TERM_LINK_RECORD_LENGTH) {
return false;
} else {
recordingTime[next] = currentTime;
return true;
}
}
}
next = i % Parameters.TERM_LINK_RECORD_LENGTH;
recordedLinks[next] = linkKey; // add knowledge reference to recordedLinks
recordingTime[next] = currentTime;
if (counter < Parameters.TERM_LINK_RECORD_LENGTH) { // keep a constant length
counter++;
}
return true;
}
示例12: clone
import nars.language.Term; //导入依赖的package包/类
/**
* Clone the Sentence
* @return The clone
*/
@Override
public Object clone() {
if (truth == null) {
return new Sentence((Term) content.clone(), punctuation, null, (Stamp) stamp.clone());
}
return new Sentence((Term) content.clone(), punctuation, new TruthValue(truth), (Stamp) stamp.clone(), revisible);
}
示例13: Concept
import nars.language.Term; //导入依赖的package包/类
/**
* Constructor, called in Memory.getConcept only
* @param tm A term corresponding to the concept
* @param memory A reference to the memory
*/
public Concept(Term tm, Memory memory) {
super(tm.getName());
term = tm;
this.memory = memory;
questions = new ArrayList<Task>();
beliefs = new ArrayList<Sentence>();
taskLinks = new TaskLinkBag(memory);
termLinks = new TermLinkBag(memory);
if (tm instanceof CompoundTerm) {
termLinkTemplates = ((CompoundTerm) tm).prepareComponentLinks();
}
}
示例14: nameToListedTerm
import nars.language.Term; //导入依赖的package包/类
/**
* Get a Term for a given name of a Concept or Operator
* <p>
* called in StringParser and the make methods of compound terms.
* @param name the name of a concept or operator
* @return a Term or null (if no Concept/Operator has this name)
*/
public Term nameToListedTerm(String name) {
Concept concept = concepts.get(name);
if (concept != null) {
return concept.getTerm();
}
return null;
}
示例15: doublePremiseTask
import nars.language.Term; //导入依赖的package包/类
/**
* Shared final operations by all double-premise rules, called from the rules except StructuralRules
* @param newContent The content of the sentence in task
* @param newTruth The truth value of the sentence in task
* @param newBudget The budget value in task
*/
public void doublePremiseTask(Term newContent, TruthValue newTruth, BudgetValue newBudget) {
if (newContent != null) {
Sentence newSentence = new Sentence(newContent, currentTask.getSentence().getPunctuation(), newTruth, newStamp);
Task newTask = new Task(newSentence, newBudget, currentTask, currentBelief);
derivedTask(newTask);
}
}