public class CasaKB extends FilterKBaseImpl implements Comparable<CasaKB>
Modifier and Type | Field and Description |
---|---|
(package private) TransientAgent |
agent |
(package private) String |
name |
(package private) TreeMap<String,CasaKB> |
OtherAgents |
assertFilterList, queryFilterList
decorated
END, FRONT
Constructor and Description |
---|
CasaKB(String agentName,
TransientAgent agent) |
Modifier and Type | Method and Description |
---|---|
void |
addClosedPredicate(Formula pattern)
Define a new pattern of closed formula.
|
void |
addFiltersDefinition(FiltersDefinition filtersDefinition)
METHODS TO ADD NEW FILTERS *
|
void |
addKBAssertFilter(KBAssertFilter filter)
Adds an assert filter to the belief base
|
void |
addKBAssertFilter(KBAssertFilter filter,
int index)
Adds an assert filter to the belief base at the specified index.
|
void |
addKBQueryFilter(KBQueryFilter filter)
Adds a query filter to the belief base
|
void |
addKBQueryFilter(KBQueryFilter filter,
int index)
Adds a query filter to the belief base at the specified index.
|
void |
addObserver(Observer obs)
Do not forget to initialise observers once added to the KBase
by using
observer.update(null);
Only observers added in the setupKBase method are
automatically initialised. |
void |
agentAssert(String agentName,
Formula formula) |
QueryResult |
agentQuery(String agentName,
Formula formula) |
MatchResult |
agentQueryRef(String agentName,
IdentifyingExpression exp) |
void |
assertFormula(Formula formula)
METHODS TO ACCESS KBASE *
|
int |
compareTo(CasaKB o) |
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
|
private static KBase |
getDecorated(String agent) |
void |
getObserverTriggerPatterns(Formula formula,
Set result)
Calls the getObserverTriggerPatterns method of each query filters.
|
TreeMap<String,CasaKB> |
getOtherAgentKBs() |
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 |
removeKBAssertFilter(Finder filterIdentifier)
METHODS TO REMOVE FILTERS *
|
void |
removeKBQueryFilter(Finder filterIdentifier)
Removes the query filters that are identified by
the specified 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 . |
String |
toString() |
String |
toString(int indent) |
String |
toStringAssertFilters() |
protected String |
toStringAssertFilters(int indent) |
String |
toStringFacts() |
protected String |
toStringFacts(int indent) |
private String |
toStringHelper(Iterator i,
int indent) |
private void |
toStringHelperFields(StringBuilder b,
Class<?> cls,
Object o,
int indent) |
String |
toStringQueryFilters() |
protected String |
toStringQueryFilters(int indent) |
ArrayList |
toStrings()
DISPLAY METHODS *
|
void |
updateObservers(Formula formula)
Update the status of all observers concerned by a given formula.
|
void |
viewFilterQuery()
For debugging purpose only
|
String name
TransientAgent agent
public CasaKB(String agentName, TransientAgent agent)
agent
- TODOdecorated
- loader
- public int compareTo(CasaKB o)
compareTo
in interface Comparable<CasaKB>
public QueryResult agentQuery(String agentName, Formula formula)
public MatchResult agentQueryRef(String agentName, IdentifyingExpression exp)
public String toString(int indent)
public String toStringFacts()
protected String toStringFacts(int indent)
public String toStringQueryFilters()
protected String toStringQueryFilters(int indent)
public String toStringAssertFilters()
protected String toStringAssertFilters(int indent)
private void toStringHelperFields(StringBuilder b, Class<?> cls, Object o, int indent)
public void assertFormula(Formula formula)
FilterKBaseImpl
assertFormula
in interface KBase
assertFormula
in class FilterKBaseImpl
formula
- the formula to assert.public QueryResult query(Formula formula, ArrayList reasons)
query
in interface KBase
query
in class FilterKBaseImpl
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
query
in class KBaseDecorator
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 void addFiltersDefinition(FiltersDefinition filtersDefinition)
FilterKBaseImpl
addFiltersDefinition
in interface FilterKBase
addFiltersDefinition
in class FilterKBaseImpl
filtersDefinition
- the list of filterspublic void addKBAssertFilter(KBAssertFilter filter)
FilterKBase
addKBAssertFilter
in interface FilterKBase
addKBAssertFilter
in class FilterKBaseImpl
filter
- an assert filterpublic void addKBAssertFilter(KBAssertFilter filter, int index)
FilterKBase
FRONT
or END
constants to put
the filter at the beginning of the lits or at the end of the list.addKBAssertFilter
in interface FilterKBase
addKBAssertFilter
in class FilterKBaseImpl
filter
- an assert filterindex
- the index in the list of filters to add a new filterpublic void addKBQueryFilter(KBQueryFilter filter)
FilterKBase
addKBQueryFilter
in interface FilterKBase
addKBQueryFilter
in class FilterKBaseImpl
filter
- a queryFilterpublic void addKBQueryFilter(KBQueryFilter filter, int index)
FilterKBase
FRONT
or END
constants to put
the filter at the beginning of the lits or at the end of the list.addKBQueryFilter
in interface FilterKBase
addKBQueryFilter
in class FilterKBaseImpl
filter
- a queryFilterindex
- the index in the list of filters to add a new filterpublic void removeKBAssertFilter(Finder filterIdentifier)
FilterKBaseImpl
removeKBAssertFilter
in interface FilterKBase
removeKBAssertFilter
in class FilterKBaseImpl
filterIdentifier
- a finderpublic void removeKBQueryFilter(Finder filterIdentifier)
FilterKBase
removeKBQueryFilter
in interface FilterKBase
removeKBQueryFilter
in class FilterKBaseImpl
filterIdentifier
- a finderpublic void addObserver(Observer obs)
FilterKBaseImpl
observer.update(null);
Only observers added in the setupKBase
method are
automatically initialised.addObserver
in interface KBase
addObserver
in class FilterKBaseImpl
obs
- the observer to addpublic void getObserverTriggerPatterns(Formula formula, Set result)
FilterKBase
getObserverTriggerPatterns
in interface FilterKBase
getObserverTriggerPatterns
in class FilterKBaseImpl
formula
- an observed formulapublic ArrayList toStrings()
FilterKBaseImpl
toStrings
in interface KBase
toStrings
in class FilterKBaseImpl
public void viewFilterQuery()
FilterKBaseImpl
viewFilterQuery
in class FilterKBaseImpl
public KBase getDecorated()
KBaseDecorator
getDecorated
in class KBaseDecorator
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
addClosedPredicate
in class KBaseDecorator
pattern
- the pattern of formula to declare as closed.KBase.isClosed(Formula, QueryResult)
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
getAgentName
in class KBaseDecorator
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
getWrappingKBase
in class KBaseDecorator
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
isClosed
in class KBaseDecorator
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 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
queryRef
in class KBaseDecorator
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)
queryRef
in interface KBase
queryRef
in class KBaseDecorator
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
queryRefSingleTerm
in class KBaseDecorator
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 Term eval(Term expression)
eval
in interface KBase
eval
in class KBaseDecorator
expression
- a term to evaluatepublic void removeClosedPredicate(Finder finder)
KBase
Finder
object.removeClosedPredicate
in interface KBase
removeClosedPredicate
in class KBaseDecorator
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
removeFormula
in class KBaseDecorator
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
removeObserver
in class KBaseDecorator
finder
- a finder that identifies the observers to remove.public void removeObserver(Observer obs)
KBase
KBase
instance a given observer.removeObserver
in interface KBase
removeObserver
in class KBaseDecorator
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
retractFormula
in class KBaseDecorator
formula
- the formula to retract.public void setAgentName(Term agent)
KBase
KBase
instance belong to.setAgentName
in interface KBase
setAgentName
in class KBaseDecorator
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
setWrappingKBase
in class KBaseDecorator
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
updateObservers
in class KBaseDecorator
formula
- a formula that has just been asserted.Observer