public interface KBase
This interface provides three main kinds of operations:
KBase
interface was primarily intended to be implemented by third
parties. However, as it is quite a difficult and very technical task, the
JSA frameworks provides a default filter-based implementation, which offers a good trade-off between efficiency
and expressiveness.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 |
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)
Deprecated.
use
retractFormula(Formula) instead. |
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.
|
KBase getWrappingKBase()
void setWrappingKBase(KBase kbase)
KBase
. This method is for internal use
only, and should never be called by the JSA programmer.Term getAgentName()
KBase
instance. Note that a KBase
instance
stores the beliefs of only one agent, even if these beliefs may
concern beliefs on other agents.KBase
object.void setAgentName(Term agent)
KBase
instance belong to.agent
- the agent the beliefs of this KBase
object belong to.void assertFormula(Formula formula)
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.
formula
- the formula to assert.void retractFormula(Formula formula)
(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.
formula
- the formula to retract.@Deprecated void removeFormula(Finder finder)
retractFormula(Formula)
instead.finder
- a finder to identify formulas to remove from the belief base.ListOfTerm queryRef(IdentifyingExpression expression)
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).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.Term queryRefSingleTerm(IdentifyingExpression expression)
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.
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.queryRef(IdentifyingExpression)
Term queryRef(IdentifyingExpression expression, ArrayList falsityReasons)
QueryResult query(Formula formula)
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
).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,
QueryResult query(Formula formula, ArrayList reasons)
Term eval(Term expression)
expression
- a term to evaluatevoid addObserver(Observer o)
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.o
- the observer to addvoid removeObserver(Finder finder)
KBase
instance all the observers that are
identified by a given finder.finder
- a finder that identifies the observers to remove.void removeObserver(Observer obs)
KBase
instance a given observer.obs
- the observer to remove.void updateObservers(Formula formula)
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.
formula
- a formula that has just been asserted.Observer
boolean isClosed(Formula pattern, QueryResult values)
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
addClosedPredicate(Formula)
and removeClosedPredicate(Finder)
methods.
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.void addClosedPredicate(Formula pattern)
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.
pattern
- the pattern of formula to declare as closed.isClosed(Formula, QueryResult)
void removeClosedPredicate(Finder finder)
Finder
object.finder
- a finder identifying the pattern of closed formula to remove.isClosed(Formula, QueryResult)