nars.language
Class Variable

java.lang.Object
  extended by nars.language.Term
      extended by nars.language.Variable
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Term>

public class Variable
extends Term

A variable term, which does not correspond to a concept


Nested Class Summary
static class Variable.VarType
          Four variable types plus a wild card
 
Field Summary
private  CompoundTerm scope
          The minimum CompoundTerm what contains all occurences of this variable
private  Variable.VarType type
          Type of the variable
 
Fields inherited from class nars.language.Term
name
 
Constructor Summary
  Variable(java.lang.String s)
          Constructor, from a given variable name
private Variable(java.lang.String n, Variable.VarType t, CompoundTerm s)
          Constructor, with all fields
 
Method Summary
 java.lang.Object clone()
          Clone a Variable
 boolean equals(java.lang.Object that)
          Whether this variable equals another one
static java.util.HashMap<java.lang.String,Term> findSubstitute(Variable.VarType type, Term term1, Term term2)
          To find a substitution that can unify two Terms without changing them
private static java.util.HashMap<java.lang.String,Term> findSubstitute(Variable.VarType type, Term term1, Term term2, java.util.HashMap<java.lang.String,Term> subs)
          To recursively find a substitution that can unify two Terms without changing them
private static java.util.HashMap<java.lang.String,Term> findSubstituteVar(Variable.VarType type, Variable var, Term term, java.util.HashMap<java.lang.String,Term> subs, boolean first)
          To find a substitution that can unify a Vriable and a Term
 java.lang.String getConstantName()
          Variable name is omitted in sorting
 java.lang.String getName()
          Get variable name with dependency list (if any)
 java.lang.String getStoredName()
          Get variable name without dependency list (if any)
 Variable.VarType getType()
          Get the type of the variable
 java.lang.String getVarName(boolean first)
          Rename a variable temporally to distinguish it from variables in other Terms
 int hashCode()
          Get a hash code for the variable
 boolean isConstant()
          A variable is constant
static boolean match(Variable.VarType type1, Variable.VarType type2)
          Whether two variable types can match each other in unification
 void setName(java.lang.String n)
          Rename the variable
 void setScope(CompoundTerm t)
          Set the scope of the variable
static boolean unify(Variable.VarType type, Term t1, Term t2, Term compound1, Term compound2)
          To unify two Terms, then apply the substitution to the two compounds
 
Methods inherited from class nars.language.Term
compareTo, getComplexity, getOrder, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

type

private Variable.VarType type
Type of the variable


scope

private CompoundTerm scope
The minimum CompoundTerm what contains all occurences of this variable

Constructor Detail

Variable

public Variable(java.lang.String s)
Constructor, from a given variable name

Parameters:
s - A String read from input

Variable

private Variable(java.lang.String n,
                 Variable.VarType t,
                 CompoundTerm s)
Constructor, with all fields

Parameters:
n - Variable name
s - Variable scope
t - Variable type
Method Detail

clone

public java.lang.Object clone()
Clone a Variable

Overrides:
clone in class Term
Returns:
The cloned Variable

getConstantName

public java.lang.String getConstantName()
Variable name is omitted in sorting

Overrides:
getConstantName in class Term
Returns:
The Variable prefix

getVarName

public java.lang.String getVarName(boolean first)
Rename a variable temporally to distinguish it from variables in other Terms

Parameters:
first - Whether it is the first term
Returns:
The new name

setName

public void setName(java.lang.String n)
Rename the variable

Parameters:
n - The new name

getType

public Variable.VarType getType()
Get the type of the variable

Returns:
The variable type

setScope

public void setScope(CompoundTerm t)
Set the scope of the variable

Parameters:
t - The new scope

equals

public boolean equals(java.lang.Object that)
Whether this variable equals another one

Overrides:
equals in class Term
Parameters:
that - The other variable
Returns:
Whether the two are equal

hashCode

public int hashCode()
Get a hash code for the variable

Overrides:
hashCode in class Term
Returns:
The hash code

getStoredName

public java.lang.String getStoredName()
Get variable name without dependency list (if any)

Returns:
The stored name

getName

public java.lang.String getName()
Get variable name with dependency list (if any)

Overrides:
getName in class Term
Returns:
The generated name

isConstant

public boolean isConstant()
A variable is constant

Overrides:
isConstant in class Term
Returns:
false

match

public static boolean match(Variable.VarType type1,
                            Variable.VarType type2)
Whether two variable types can match each other in unification

Parameters:
type1 - Type of the first variable
type2 - Type of the second variable
Returns:
The matching result

unify

public static boolean unify(Variable.VarType type,
                            Term t1,
                            Term t2,
                            Term compound1,
                            Term compound2)
To unify two Terms, then apply the substitution to the two compounds

Parameters:
type - The type of Variable to be unified
t1 - The first Term to be unified
t2 - The second Term to be unified
compound1 - The first compound to be substituted
compound2 - The second compound to be substituted
Returns:
Whether a unification has been succeeded

findSubstitute

public static java.util.HashMap<java.lang.String,Term> findSubstitute(Variable.VarType type,
                                                                      Term term1,
                                                                      Term term2)
To find a substitution that can unify two Terms without changing them

Parameters:
type - The type of Variable to be substituted
term1 - The first Term to be unified
term2 - The second Term to be unified
Returns:
The substitution that unifies the two Terms

findSubstitute

private static java.util.HashMap<java.lang.String,Term> findSubstitute(Variable.VarType type,
                                                                       Term term1,
                                                                       Term term2,
                                                                       java.util.HashMap<java.lang.String,Term> subs)
To recursively find a substitution that can unify two Terms without changing them

Parameters:
type - The type of Variable to be substituted
term1 - The first Term to be unified
term2 - The second Term to be unified
subs - The substitution formed so far
Returns:
The substitution that unifies the two Terms

findSubstituteVar

private static java.util.HashMap<java.lang.String,Term> findSubstituteVar(Variable.VarType type,
                                                                          Variable var,
                                                                          Term term,
                                                                          java.util.HashMap<java.lang.String,Term> subs,
                                                                          boolean first)
To find a substitution that can unify a Vriable and a Term

Parameters:
type - The type of Variable to be substituted
var - The Variable to be unified
term - The Term to be unified
subs - The substitution formed so far
first - If it is the first Term in unify
Returns:
The substitution that unifies the two Terms, as "name-term" pairs