public interface PrologTerm extends Comparable<PrologTerm>, PrologElement
Ancestor prolog data type. All Prolog data types PrologAtom
,
PrologNumber
, PrologList
, PrologStructure
and
PrologVariable
are derived from this class. All before mentioned
classes extends from this class the commons responsibilities. Extends from
Comparable
to compare the current term with another term based on
Standard Order.
The Prolog Provider is the mechanism to create a new Prolog terms invoking
the correspondent methods. PrologProvider.newAtom(String)
for atoms,
PrologProvider.newStructure(String, PrologTerm...)
for structures,
PrologProvider.newVariable(String, int)
for variables and so on.
With getType()
the term type can be retrieve. Every term have a type
defined in PrologTermType
. The prolog type have by definition one
order (Standard Order) where Variables < Atoms < Numbers <
Compounds. This order is usable to compare two terms.
Prolog terms have two specials properties, the functor and the arity. Functor
is the compound term or atom name and arity is the number of arguments
present in the compound terms. Variable and Number don't have this
properties. This properties are accessible from getArity()
and
getFunctor()
methods. Variable and Number raise an
ArityError
and FunctorError
respectively. Based on functor
and arity atoms and compound terms have a predicate indicator that is the
signature for the term. The term indicator is an string formed by the
concatenation of getFunctor()
and getArity()
separated by
slash.
The methods getArguments()
and getArgument(int)
allow
retrieve the arguments and the some specific arguments for compounds terms
respectively. For atomics terms getArguments()
return an empty term
array and getArgument(int)
raise a
ArrayIndexOutOfBoundsException
because don't have arguments. For this
cases is a good practice check compound terms before invoke this methods.
if (t.isCompound()) { PrologTerm x = t.getArgument(i); System.out.println(x); }Prolog unification is the process that involves one or more variables such that they are instantiated with the necessary terms in order to make two terms are identical. The prolog term interface provide
unify(PrologTerm)
method to check that the current term unify with
the given term. Prolog unification algorithm is based on three principals
rules:
PrologAtom atom = provider.newAtom("smith"); PrologAtom atom1 = provider.newAtom("doe"); // true because the atoms are equals assertTrue(atom.unify(atom)); // false because the atoms are different assertFalse(atom.unify(atom1)); PrologVariable variable = provider.newVariable("X", 0); // true because atom and variable unify assertTrue(atom.unify(variable));
Modifier and Type | Method and Description |
---|---|
<T extends PrologTerm> |
cast()
Casts the current PrologTerm to the class or interface represented by this
Class object. |
PrologTerm |
getArgument(int index)
Term located at some given index position in the current term arguments if
current term is a compound term.
|
PrologTerm[] |
getArguments()
Term arguments if the current term is a compound term.
|
int |
getArity()
Term arity.
|
String |
getFunctor()
Term functor.The functor of a term is a name for compound terms.
|
String |
getIndicator()
Gets the term indicator represented by one string with the format
functor/arity.
|
Object |
getObject()
For references terms return the referenced object.
|
PrologProvider |
getProvider()
Prolog provider associated to the current term.
|
PrologTerm |
getTerm()
Return current term instance if current term is not a variable or is a free
variable term.
|
int |
getType()
Get the term type.
|
boolean |
hasIndicator(String functor,
int arity)
True if term has an indicator with the format functor/arity that match with
the given functor and arity.
|
boolean |
isAtom()
True if this term is an atom
|
boolean |
isAtomic()
True if this Term is a atomic term, false in other case
|
boolean |
isClass()
Deprecated.
|
boolean |
isCompound()
True if this Term is a compound term, false in other case
|
boolean |
isDouble()
True if this Term is a double precision floating point number, false in other
case
|
boolean |
isEmptyList()
True if this Term is a empty list term ([]), false in other case
|
boolean |
isEntry()
True if this Term is a Entry, false in other case
|
boolean |
isEvaluable()
Check if the current term is a compound term and have like functor an
operator.
|
boolean |
isFalseType()
Check if the current term is a reference term and the referenced object is an
instance of java false value.
|
boolean |
isField()
Deprecated.
|
boolean |
isFloat()
True if this Term is a single precision floating point number, false in other
case
|
boolean |
isInteger()
True if this Term is an integer number, false in other case
|
boolean |
isList()
True if this Term is a list, false in other case
|
boolean |
isLong()
True if this Term is a large integer number, false in other case
|
boolean |
isMap()
True if this Term is a Map, false in other case
|
boolean |
isMixin()
Deprecated.
|
boolean |
isNil()
True if this Term is a nil term (null term for prolog), false in other case
|
boolean |
isNullType()
Check if the current term is a reference term and the referenced object is a
java null value.
|
boolean |
isNumber()
True if this term is an number
|
boolean |
isObjectType()
Check if the current term is a reference term for some java object instance.
|
boolean |
isParameter()
Deprecated.
|
boolean |
isReference()
Check if the current term is a reference term for some java object instance
or is a reference term and the referenced object is a java null value.
|
boolean |
isResult()
Deprecated.
|
boolean |
isStructure()
True if this Term is a structured term, false in other case
|
boolean |
isTrueType()
Check if the current term is a reference term and the referenced object is an
instance of java true value.
|
boolean |
isVariable()
True if this Term is a variable, false in other case
|
boolean |
isVariableBound()
True if this Term is a instanced variable, false in other case
|
boolean |
isVariableNotBound()
True if this Term is a not instanced variable, false in other case
|
boolean |
isVoidType()
Check if the current term is a reference term for java void type.
|
Map<String,PrologTerm> |
match(PrologTerm term)
Match to other term returning list of substitutions.
|
boolean |
unify(PrologTerm term)
Check that the current term unify with the given term.
|
compareTo
isClause, isTerm
String getIndicator()
getFunctor()
and getArity()
separated by
slash.boolean hasIndicator(String functor, int arity)
functor
- term functorarity
- term arityint getType()
boolean isAtom()
boolean isNumber()
boolean isFloat()
boolean isInteger()
boolean isDouble()
boolean isLong()
boolean isVariable()
boolean isVariableBound()
boolean isVariableNotBound()
boolean isList()
boolean isStructure()
boolean isNil()
boolean isEmptyList()
boolean isAtomic()
boolean isCompound()
boolean isEvaluable()
boolean isTrueType()
boolean isFalseType()
boolean isNullType()
boolean isVoidType()
boolean isObjectType()
boolean isReference()
boolean isEntry()
boolean isMap()
@Deprecated boolean isField()
@Deprecated boolean isResult()
@Deprecated boolean isParameter()
@Deprecated boolean isMixin()
@Deprecated boolean isClass()
Object getObject()
PrologTerm getTerm()
int getArity()
String getFunctor()
PrologTerm[] getArguments()
PrologTerm getArgument(int index)
ArrayIndexOutOfBoundsException
exception is raised.index
- position to retrieve the correspondent term.ArrayIndexOutOfBoundsException
- if the index value is out of term
array bound.boolean unify(PrologTerm term)
term
- the term to unify with the current termMap<String,PrologTerm> match(PrologTerm term)
term
- - term to match checkPrologProvider getProvider()
<T extends PrologTerm> T cast()
Class
object.ClassCastException
- if the object is not null and is not assignable to
the type T.Copyright © 2020–2024 Prolobjectlink Project. All rights reserved.