public class KBaseDecorator extends Object implements KBase
Modifier and Type | Field and Description |
---|---|
protected KBase |
decorated
The decorated KBase
|
Modifier | Constructor and Description |
---|---|
protected |
KBaseDecorator(KBase decorated)
Build a KBase decorator
|
Modifier and Type | Method and Description |
---|---|
void |
addClosedPredicate(Formula pattern)
Define a new pattern of closed formula.
|
void |
addObserver(Observer o)
Add an observer to this
KBase instance (at the end of the list of
observers). |
void |
assertFormula(Formula formula)
Assert a fact (given as a FIPA-SL formula) believed by the owning agent
into this belief base.
|
Term |
eval(Term expression) |
Term |
getAgentName()
Get the name of the agent (given as a FIPA-SL term representing his AID)
owning this
KBase instance. |
KBase |
getDecorated()
Return the decorated kbase
|
KBase |
getWrappingKBase()
The
KBase mechanism follows the decoration design pattern. |
boolean |
isClosed(Formula pattern,
QueryResult values)
Return
true if a given pattern of formula is closed on a
given domain of values, and false otherwise. |
QueryResult |
query(Formula formula)
Check wether a given fact is believed by the agent owning this
KBase
instance. |
QueryResult |
query(Formula formula,
ArrayList reasons) |
ListOfTerm |
queryRef(IdentifyingExpression expression)
Return a list of objects satisfying a given logical description (expressed
as an Identifying Referential Expression), which is believed by the agent
owning this
KBase instance. |
Term |
queryRef(IdentifyingExpression expression,
ArrayList falsityReasons) |
Term |
queryRefSingleTerm(IdentifyingExpression expression)
Return a term satisfying a given logical description (expressed
as an Identifying Referential Expression), which is believed by the agent
owning this
KBase instance. |
void |
removeClosedPredicate(Finder finder)
Remove the definition of a pattern of closed formula.
|
void |
removeFormula(Finder finder)
Removes from the belief base all formulas recognized by a given finder.
|
void |
removeObserver(Finder finder)
Remove from this
KBase instance all the observers that are
identified by a given finder. |
void |
removeObserver(Observer obs)
Remove from this
KBase instance a given observer. |
void |
retractFormula(Formula formula)
Retract a fact from the belief base.
|
void |
setAgentName(Term agent)
Modify the agent (given as a FIPA-SL term representing his AID) the
beliefs stored in this
KBase instance belong to. |
void |
setWrappingKBase(KBase kbase)
Set the most enclosing
KBase . |
ArrayList |
toStrings()
|
void |
updateObservers(Formula formula)
Update the status of all observers concerned by a given formula.
|
protected KBase decorated
protected KBaseDecorator(KBase decorated)
decorated
- the decorated KBasepublic KBase getDecorated()
public void addClosedPredicate(Formula pattern)
KBase
If there is no instance of this pattern, which is already believed by
the agent owning the belief base, this is equivalent to assert
(= (all ??VARS ??pattern) (set))
, where ??VAR
is a sequence of all meta-references occurring in the pattern.
addClosedPredicate
in interface KBase
pattern
- the pattern of formula to declare as closed.KBase.isClosed(Formula, QueryResult)
public void addObserver(Observer o)
KBase
KBase
instance (at the end of the list of
observers). Observers make it possible to monitor the truth value of a
given fact and trigger some action each time this fact becomes believed
by the agent owning the belief base. For example, this mechanism is used
by the SIPs that manage the interpretation of the SUBSCRIBE
or REQUEST-WHEN*
messages.addObserver
in interface KBase
o
- the observer to addpublic void assertFormula(Formula formula)
KBase
Asserting p
actually means that (B ??myself p)
is true (where ??myself
represents the agent owning the belief
base), while asserting (not p)
actually means that
(B ??myself (not p))
is true.
Consequently, asserting p
is equivalent to asserting
(B ??myself p)
(because in the underlying formal model -
see the FIPA SL specifications,
(B i (B i p))
is logically equivalent to (B i p)
).
The KBase
implementations are expected to maintain a logically
consistent set of beliefs. When a fact, which is inconsistent with an
already stored belief, is asserted, the implementation must explicitly
choose an option that ensures the global consistency (for example, keeping
the most recently asserted fact in the base).
Depending on their sophistication, the KBase
implementations may
not be able to actually store all asserted facts. In this case, the reasoning
(or "intellectual") capabilities of the owning agent will simply be
considered as limited, which is a very common case. In any case, the
asserted facts that cannot be dealt with should not create any inconsistency
in the belief base. For example, the implementation provided with the
JSA framework does not deal with uncertainty modal operators, so that
asserting (U ??myself p)
has no effect.
assertFormula
in interface KBase
formula
- the formula to assert.public Term getAgentName()
KBase
KBase
instance. Note that a KBase
instance
stores the beliefs of only one agent, even if these beliefs may
concern beliefs on other agents.getAgentName
in interface KBase
KBase
object.public KBase getWrappingKBase()
KBase
KBase
mechanism follows the decoration design pattern.
A KBase
instance can be enclosed within another KBase
instance, wich can in turn be enclosed in another KBase
instance
and so on.getWrappingKBase
in interface KBase
KBase
instance, on which to proceed
assertion and query operations. This also corresonds to the
KBase
instance attached to the semantic capabilities of
an agent. It can be this KBase
object.public boolean isClosed(Formula pattern, QueryResult values)
KBase
true
if a given pattern of formula is closed on a
given domain of values, and false
otherwise.
A pattern of formula is considered as closed on a set of values if and only if:
iota
and the all
IRE quantifiers. For example, the belief
(B ??myself (= (all ?x (age ?x 25)) (set john mary)))
is actually stored in the belief base as the formula
(age ??x 25)
closed on the domain (john
,
mary
). This makes it possible to retrieve implicit entailments
such as (B ??myself (not (age peter 25)))
(without the closed
formula mechanism, one could only entail
(not (B ??myself (age peter 25)))
).
Consequent to the formal definition of the underlying logical model for
agents' beliefs, all patterns of mental attitudes of the agent owning
the belief base (that is all patterns logically equivalent to a formula
of the form (B ??myself ??PHI)
) are necessarily closed. In
other words, agents know exactly what are all their mental attitudes, they
cannot not be aware of them.
Closed formulas can be defined and undefined using the
KBase.addClosedPredicate(Formula)
and KBase.removeClosedPredicate(Finder)
methods.
isClosed
in interface KBase
pattern
- the pattern of closed formula to check.values
- the domain of values to used to check the closure.
null
value does not check the values, only
the registration of the pattern as a closed formula.true
if the pattern is closed on the given domain,
false
otherwise.public QueryResult query(Formula formula)
KBase
KBase
instance.
If the fact is not believed by the agent, the method returns null
.
The queried fact may include meta-references. In this case, the
method returns all bindings of these meta-references, for which the
corresponding instantiated fact is believed by the agent.
These bindings are returned using a QueryResult
instance.
If the queried fact include no meta-reference and is actually believed,
the returned QueryResult
object is an empty list equal
to QueryResult.KNOWN.
(age john 25)
, (age mary 25)
and
(age peter 20)
are believed by the agent, querying for
(age ??who 25)
will return a list of two
MatchResult
objects containing
respectively the bindings (??who
=john
) and
(??who
=mary
).query
in interface KBase
formula
- a fact to retrieve in the belief base (may include meta-
references)null
(QueryResult.UNKNOWN) if the agent doesn't
know about this fact,
public QueryResult query(Formula formula, ArrayList reasons)
public ListOfTerm queryRef(IdentifyingExpression expression)
KBase
KBase
instance.
Formally, given an IRE ??IRE
quantified by either
iota
or any
, the method returns a list of one
single term ??o such that: (B ??myself (= ??IRE ??o))
is true.
Given an IRE ??IRE
quantified by either all
or
some
, the method returns a set ??set of zero or more terms
(given as a ListOfTerm
object) such that:
(B ??myself (= ??IRE ??set))
is true.
null
(which actually means that either the agent does not
know the specified objects or there is no such objects).queryRef
in interface KBase
expression
- an Identifying Referential Expression describing one or
more objects to find within the agent's beliefs.null
if
there is no such object in the agent's beliefs.public Term queryRef(IdentifyingExpression expression, ArrayList falsityReasons)
public Term queryRefSingleTerm(IdentifyingExpression expression)
KBase
KBase
instance.
Formally, given an IRE ??IRE
quantified by either
iota
or any
, the method returns either a term
??o such that (B ??myself (= ??IRE ??o))
is true
or null if (not (exists ?o (B ??myself (= ??IRE ?o))))
.
Given an IRE ??IRE
quantified by either all
or
some
, the method returns a set ??set of zero or more terms
such that:
(B ??myself (= ??IRE ??set))
is true.
queryRefSingleTerm
in interface KBase
expression
- an Identifying Referential Expression describing one or
more objects to find within the agent's beliefs.null
if
there is no such object according to the agent's beliefs.KBase.queryRef(IdentifyingExpression)
public void removeClosedPredicate(Finder finder)
KBase
Finder
object.removeClosedPredicate
in interface KBase
finder
- a finder identifying the pattern of closed formula to remove.KBase.isClosed(Formula, QueryResult)
public void removeFormula(Finder finder)
KBase
removeFormula
in interface KBase
finder
- a finder to identify formulas to remove from the belief base.public void removeObserver(Finder finder)
KBase
KBase
instance all the observers that are
identified by a given finder.removeObserver
in interface KBase
finder
- a finder that identifies the observers to remove.public void removeObserver(Observer obs)
KBase
KBase
instance a given observer.removeObserver
in interface KBase
obs
- the observer to remove.public void retractFormula(Formula formula)
KBase
(not (B ??myself formula))
.
In other words, retracting p
actually means that
(not (B ??myself p))
is true.
The retracted formula may include meta-references, in this case, all
stored facts that match the input formula are retracted. For example,
if (age john 25)
, (age mary 25)
and
(age peter 20)
are believed by the agent, retracting
(age ??person 25)
will result in dropping the first two facts
from the belief base.
retractFormula
in interface KBase
formula
- the formula to retract.public void setAgentName(Term agent)
KBase
KBase
instance belong to.setAgentName
in interface KBase
agent
- the agent the beliefs of this KBase
object belong to.public void setWrappingKBase(KBase kbase)
KBase
KBase
. This method is for internal use
only, and should never be called by the JSA programmer.setWrappingKBase
in interface KBase
public void updateObservers(Formula formula)
KBase
A null
formula forces all observers to be updated.
This operation is needed to trigger the observers even when an assertion does not lead to an actual assertion in the belief base.
updateObservers
in interface KBase
formula
- a formula that has just been asserted.Observer