|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnars.language.Term
nars.language.CompoundTerm
public abstract class CompoundTerm
A CompoundTerm is a Term with internal (syntactic) structure
A CompoundTerm consists of a term operator with one or more component Terms.
This abstract class contains default methods for all CompoundTerms.
Field Summary | |
---|---|
protected short |
complexity
syntactic complexity of the compound, the sum of those of its components plus 1 |
protected java.util.ArrayList<Term> |
components
list of (direct) components |
protected java.util.ArrayList<Variable> |
openVariables
list of open variables in the compound |
Fields inherited from class nars.language.Term |
---|
name |
Constructor Summary | |
---|---|
protected |
CompoundTerm()
Default constructor |
protected |
CompoundTerm(java.lang.String n,
java.util.ArrayList<Term> arg)
Constructor called from subclasses constructors to initialize the fields |
protected |
CompoundTerm(java.lang.String n,
java.util.ArrayList<Term> cs,
java.util.ArrayList<Variable> open,
short i)
Constructor called from subclasses constructors to clone the fields |
Method Summary | |
---|---|
static Term |
addComponents(CompoundTerm t1,
Term t2)
Try to add a component into a compound |
protected static java.util.ArrayList<Term> |
argumentsToList(Term t1,
Term t2)
build a component list from two terms |
private void |
calcComplexity()
The complexity of the term is the sum of those of the components plus 1 |
abstract java.lang.Object |
clone()
Abstract clone method |
java.util.ArrayList<Term> |
cloneComponents()
Clone the component list |
static java.util.ArrayList |
cloneList(java.util.ArrayList original)
Deep clone an array list of terms |
Term |
componentAt(int i)
get a component by index |
boolean |
containAllComponents(Term t)
Check whether the compound contains all components of another term, or that term as a whole |
boolean |
containComponent(Term t)
Check whether the compound contains a certain component |
int |
getComplexity()
report the term's syntactic complexity |
java.util.ArrayList<Term> |
getComponents()
Get the component list |
java.lang.String |
getConstantName()
skip all variable names to produce stable sorting order among components, not for display |
java.util.ArrayList<Variable> |
getOpenVariables()
get the OpenVariables list |
private static boolean |
isBuiltInOperator(java.lang.String s)
Check built-in operator name |
boolean |
isCommutative()
Check if the order of the components matters |
boolean |
isConstant()
check if the term contains free variable |
static boolean |
isOperator(java.lang.String s)
Check CompoundTerm operator symbol |
static Term |
make(CompoundTerm compound,
java.util.ArrayList<Term> components)
Try to make a compound term from a template and a list of components |
static Term |
make(java.lang.String op,
java.util.ArrayList<Term> arg)
Try to make a compound term from an operator and a list of components |
protected static java.lang.String |
makeCompoundName(java.lang.String op,
java.util.ArrayList<Term> arg)
default method to make the name of a compound term from given fields |
protected static java.lang.String |
makeImageName(java.lang.String op,
java.util.ArrayList<Term> arg,
int relationIndex)
default method to make the name of an image term from given fields |
protected java.lang.String |
makeName()
default method to make the name of the current term from existing fields |
protected static java.lang.String |
makeSetName(char opener,
java.util.ArrayList<Term> arg,
char closer)
make the name of an ExtensionSet or IntensionSet |
private java.lang.String |
makeVarName(int size,
Variable v)
Sequentially generate new variable names |
private void |
markVariables()
Register open and closed variables in a CompoundTerm |
abstract java.lang.String |
operator()
Abstract method to get the operator of the compound |
java.util.ArrayList<TermLink> |
prepareComponentLinks()
Build TermLink templates to constant components and subcomponents |
private void |
prepareComponentLinks(java.util.ArrayList<TermLink> componentLinks,
short type,
CompoundTerm term)
Collect TermLink templates into a list, go down one level except in special cases |
static Term |
reduceComponents(CompoundTerm t1,
Term t2)
Try to remove a component from a compound |
void |
renameVariables()
Rename variables in input sentence |
protected void |
renameVariables(java.util.HashMap<java.lang.String,java.lang.String> varMap)
Recursively rename variables by their appearing order in the CompoundTerm |
static Term |
replaceComponent(CompoundTerm compound,
int index,
Term t)
Try to replace a component in a compound at a given index by another one |
static Term |
replaceComponent(CompoundTerm compound,
Term oldComponent,
Term newComponent)
Try to replace a given component in a compound by another one |
int |
size()
get the number of components |
void |
substituteComponent(java.util.HashMap<java.lang.String,Term> subs,
boolean first)
Substitute a variable component according to a given substitution |
Methods inherited from class nars.language.Term |
---|
compareTo, equals, getName, getOrder, hashCode, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.ArrayList<Term> components
protected java.util.ArrayList<Variable> openVariables
protected short complexity
Constructor Detail |
---|
protected CompoundTerm()
protected CompoundTerm(java.lang.String n, java.util.ArrayList<Term> cs, java.util.ArrayList<Variable> open, short i)
n
- Namecs
- Component listopen
- Open variable listi
- Complexityprotected CompoundTerm(java.lang.String n, java.util.ArrayList<Term> arg)
n
- Name, to be re-builtarg
- Component listMethod Detail |
---|
public abstract java.lang.Object clone()
clone
in class Term
public abstract java.lang.String operator()
private void calcComplexity()
public static Term make(CompoundTerm compound, java.util.ArrayList<Term> components)
compound
- The templatecomponents
- The components
public static Term make(java.lang.String op, java.util.ArrayList<Term> arg)
Called from StringParser
op
- Term operatorarg
- Component list
private static boolean isBuiltInOperator(java.lang.String s)
s
- The String to be checked
public static boolean isOperator(java.lang.String s)
s
- The String to be checked
protected static java.util.ArrayList<Term> argumentsToList(Term t1, Term t2)
t1
- the first componentt2
- the second component
protected java.lang.String makeName()
protected static java.lang.String makeCompoundName(java.lang.String op, java.util.ArrayList<Term> arg)
op
- the term operatorarg
- the list of components
protected static java.lang.String makeSetName(char opener, java.util.ArrayList<Term> arg, char closer)
opener
- the set openercloser
- the set closerarg
- the list of components
protected static java.lang.String makeImageName(java.lang.String op, java.util.ArrayList<Term> arg, int relationIndex)
op
- the term operatorarg
- the list of componentsrelationIndex
- the location of the place holder
public java.lang.String getConstantName()
getConstantName
in class Term
public int getComplexity()
getComplexity
in class Term
public boolean isConstant()
isConstant
in class Term
public boolean isCommutative()
commutative CompoundTerms: Sets, Intersections; communative Statements: Similarity, Equivalence, EquivalenceWhen; communative CompoundStatements: Disjunction, Conjunction, ConjunctionParallel
public int size()
public Term componentAt(int i)
i
- index of the component
public java.util.ArrayList<Term> getComponents()
public java.util.ArrayList<Term> cloneComponents()
public static java.util.ArrayList cloneList(java.util.ArrayList original)
original
- The original component list
public boolean containComponent(Term t)
t
- The component to be checked
public boolean containAllComponents(Term t)
t
- The other term
public static Term addComponents(CompoundTerm t1, Term t2)
t1
- The compoundt2
- The component
public static Term reduceComponents(CompoundTerm t1, Term t2)
t1
- The compoundt2
- The component
public static Term replaceComponent(CompoundTerm compound, int index, Term t)
compound
- The compoundindex
- The location of replacementt
- The new component
public static Term replaceComponent(CompoundTerm compound, Term oldComponent, Term newComponent)
compound
- The compoundoldComponent
- The component to removenewComponent
- The component to add
public java.util.ArrayList<Variable> getOpenVariables()
private void markVariables()
An open variable only appears in one components, while a closed variable appears in multiple components
May need further testing and revising on various situations
public void renameVariables()
only called from Sentence
protected void renameVariables(java.util.HashMap<java.lang.String,java.lang.String> varMap)
Since each occurance of a variable is processed exactly once, there will be no confusion between new names and old names.
varMap
- the mapping built so farprivate java.lang.String makeVarName(int size, Variable v)
size
- The current size of the variable listv
- The variable to be renamed
public void substituteComponent(java.util.HashMap<java.lang.String,Term> subs, boolean first)
subs
- The substitutionfirst
- Whether it is the first term in the mappingpublic java.util.ArrayList<TermLink> prepareComponentLinks()
The compound type determines the link type; the component type determines whether to build the link.
private void prepareComponentLinks(java.util.ArrayList<TermLink> componentLinks, short type, CompoundTerm term)
componentLinks
- The list of TermLink templates built so fartype
- The type of TermLink to be builtterm
- The CompoundTerm for which the links are built
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |