Class Variable
java.lang.Object
org.projog.core.term.Variable
- All Implemented Interfaces:
Term
Represents an unspecified
Term.
A Variable can be either instantiated (representing another single Term) or uninstantiated (not
representing any other Term). Variables are not constants. What Term, if any, a
Variable is instantiated with can vary during its life time. A Variable becomes instantiated by calls
to unify(Term) and becomes uninstantiated again by calls to backtrack().
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprivate final Map<VariableAttribute, Term> A collection of attributes associated with the variable.private final StringThe value by which the variable can be identifiedprivate TermTheTermthis object is currently instantiated with (ornullif it is currently uninstantiated) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidReverts this variable to an uninstantiated state.Returns a copy of this term.Term[]getArgs()CallsTerm.getArgs()on theTermthis variable is instantiated with.getArgument(int index) CallsTerm.getArgument(int)on theTermthis variable is instantiated with.getAttributeOrDefault(VariableAttribute attributeKey, Term defaultValue) getBound()Returns the term this object is bound to.getId()getName()CallsTerm.getName()on theTermthis variable is instantiated with.intCallsTerm.getNumberOfArguments()on theTermthis variable is instantiated with.getTerm()Returns the current instantiated state of this term.getType()private TermgetValue()booleanbooleanAlways returnsfalseeven if instantiated with an immutableTerm.private booleanvoidputAttribute(VariableAttribute attributeKey, Term attributeValue) voidremoveAttribute(VariableAttribute attributeKey) toString()booleanAttempts to unify this term to the specified term.private static booleanUnify two variables that both have attributes.
-
Field Details
-
ANONYMOUS_VARIABLE_ID
- See Also:
-
id
The value by which the variable can be identified -
value
-
attributes
A collection of attributes associated with the variable.
-
-
Constructor Details
-
Variable
public Variable()Creates an anonymous variable. The ID of the variable will be an underscore. -
Variable
- Parameters:
id- value by which this variable can be identified
-
Variable
-
-
Method Details
-
getAttributeOrDefault
-
putAttribute
-
removeAttribute
-
getName
CallsTerm.getName()on theTermthis variable is instantiated with.- Specified by:
getNamein interfaceTerm- Returns:
- a string representation of this term
- Throws:
NullPointerException- if theVariableis currently uninstantiated
-
getId
- Returns:
- value provided in constructor by which this variable can be identified
-
isAnonymous
public boolean isAnonymous() -
getArgs
CallsTerm.getArgs()on theTermthis variable is instantiated with.- Specified by:
getArgsin interfaceTerm- Returns:
- array of this terms's arguments
- Throws:
NullPointerException- if theVariableis currently uninstantiated- See Also:
-
getNumberOfArguments
public int getNumberOfArguments()CallsTerm.getNumberOfArguments()on theTermthis variable is instantiated with.- Specified by:
getNumberOfArgumentsin interfaceTerm- Returns:
- number of arguments in this term
- Throws:
NullPointerException- if theVariableis currently uninstantiated
-
getArgument
CallsTerm.getArgument(int)on theTermthis variable is instantiated with.- Specified by:
getArgumentin interfaceTerm- Parameters:
index- index of the argument to return- Returns:
- the term at the specified position in this term's arguments
- Throws:
NullPointerException- if theVariableis currently uninstantiated
-
unify
Description copied from interface:TermAttempts to unify this term to the specified term.The rules for deciding if two terms are unifiable are as follows:
- An uninstantiated
Variablewill unify with any term. As a result theVariablewill become instantiated to the other term. The instantiaton will be undone whenTerm.backtrack()is next called on theVariable - Non-variable terms will unify with other terms that are of the same
TermTypeand have the same value. The exact meaning of "having the same value" will vary between term types but will include that the two terms being unified have the same number of arguments and that all of their corresponding arguments unify.
- An uninstantiated
-
unifyVariablesWithAttributes
-
postUnify
private boolean postUnify() -
getType
- Specified by:
getTypein interfaceTerm- Returns:
TermType.VARIABLEif this variable is uninstantiated else callsTerm.getType()on theTermthis variable is instantiated with.
-
isImmutable
public boolean isImmutable()Always returnsfalseeven if instantiated with an immutableTerm.- Specified by:
isImmutablein interfaceTerm- Returns:
false
-
copy
Description copied from interface:Term -
getBound
-
getTerm
Description copied from interface:TermReturns the current instantiated state of this term.Returns a representation of this term with all instantiated
Variables replaced with the terms they are instantiated with.- Specified by:
getTermin interfaceTerm- Returns:
- itself if this variable is uninstantiated else calls
Term.getType()on theTermthis variable is instantiated with.
-
getValue
-
backtrack
-
toString
-