Package edu.tufts.hrilab.belief
Class BeliefComponent
java.lang.Object
edu.tufts.hrilab.diarc.DiarcComponent
edu.tufts.hrilab.belief.BeliefComponent
- All Implemented Interfaces:
BeliefInterface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected MemoryLevel
protected Prover
protected String
SQL path.protected Map<MemoryLevel,
List<String>> Files to initialize prover.protected final Object
protected Prover.Engine
Specify prover type (prolog, asp, etc).Fields inherited from class edu.tufts.hrilab.diarc.DiarcComponent
executionLoopCycleTime, log, shouldRunExecutionLoop
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionList<org.apache.commons.cli.Option>
Command line options available in sub-class.boolean
addNotifications
(Predicate queryTerm, List<Symbol> callbackTerm) void
assertBelief
(Term belief) void
assertBelief
(Term belief, MemoryLevel memoryLevel) Adds a single belief to the Belief State of the agent.void
assertBelief
(Term belief, MemoryLevel memoryLevel, boolean checkOperator) Special method for use by the OperatorCheck class, so that (fluent_)equals(...) beliefs can be asserted without performing an operator check and resulting in an infinite loop.void
assertBelief
(Term belief, MemoryLevel memoryLevel, Predicate source) void
assertBelief
(Term belief, MemoryLevel memoryLevel, Predicate source, boolean checkOperator) Special method for use by the OperatorCheck class, so that (fluent_)equals(...) beliefs can be asserted without performing an operator check and resulting in an infinite loop.void
assertBeliefs
(Set<Term> beliefs) void
assertBeliefs
(Set<Term> beliefs, MemoryLevel memoryLevel) Adds the beliefs in the argument to the Belief State of the agent.void
assertBeliefs
(Set<Term> beliefs, MemoryLevel memoryLevel, boolean checkOperator) Special method for use by the OperatorCheck class, so that (fluent_)equals(...) beliefs can be asserted without performing an operator check and resulting in an infinite loop.void
assertBeliefs
(Set<Term> beliefs, MemoryLevel memoryLevel, Predicate source, boolean checkOperator) void
assertRule
(Term head, List<Term> body) void
assertRule
(Term head, List<Term> body, MemoryLevel memoryLevel) Asserts a rule with one premise and a set of conclusions into the Belief State of the agent.void
clear()
void
clear
(MemoryLevel memoryLevel) Clear beliefs at specified memory level only.Copy the prover and sql state to a new BeliefComponent instance and return it.Get a map from team names to the set of diarcAgents which make up that team.getAllDiarcAgentsForActor
(Symbol actor, boolean groupFormat) Queries belief for all of the agents corresponding to the given actor e.g.getFacts()
Returns list of current facts in predicate form.getFacts
(MemoryLevel memoryLevel) Returns list of current facts in predicate form.getHistory
(MemoryLevel memoryLevel) Returns list of past facts in predicate form, paired with their assertion and retraction times.This exposes the notification prover to the BeliefGUI, and should not be used by anything else.getRules()
getRules
(MemoryLevel memoryLevel) Returns list of current rules in predicate form, head first (conclusion) and then body (premises).protected void
init()
Perform any component initialization.protected void
initializeFromFiles
(Map<MemoryLevel, List<String>> filenames) Initialize SQL and notification prover from files.void
parseArgs
(org.apache.commons.cli.CommandLine cmdLine) Called directly after construction to pass runtime values that will override default values.queryAtTime
(Term query, Long time) Make query using all facts that were true at time t.queryBelief
(Term query) queryBelief
(Term query, MemoryLevel memoryLevel) Queries the Belief State about the term in the argument, and a set of bindings corresponding to all of the found answers.queryBelief
(Term query, MemoryLevel memoryLevel, boolean checkOperator) queryBelief
(List<Term> queries) queryBelief
(List<Term> queries, MemoryLevel memoryLevel) Queries the Belief State with N independent queries, and returns N binding lists.int
queryCount
(Term query) queryFactsInTimeframe
(Term query, Long start, Long end) Make query using facts which were true from start to end of timeframe.long
queryLastSource
(Term query) queryLastTime
(Term query) queryRecency
(Term query) Query for how long ago a belief was asserted and retracted.queryRecentFacts
(Term query, int n) Make query using last n facts most recently asserted to the database (out of all facts, not necessarily currently true ones).querySupport
(Term query) querySupport
(Term query, MemoryLevel memoryLevel) Make query and return if query has support (is true).querySupport
(Term query, MemoryLevel memoryLevel, boolean checkOperator) querySupportWithExplanation
(Term query) querySupportWithExplanation
(Term query, MemoryLevel memoryLevel) Queries true or falsevoid
registerForNotification
(Term queryTerm, ai.thinkingrobots.trade.TRADEServiceInfo callback) Register to be notified by Belief whenever the query term is true.void
retractBelief
(Term belief) void
retractBelief
(Term belief, MemoryLevel memoryLevel) Removes a single belief from the Belief State of the agent.void
retractBeliefs
(Set<Term> beliefs) void
retractBeliefs
(Set<Term> beliefs, MemoryLevel memoryLevel) Removes the beliefs in the argument from the Belief State of the agent.void
retractRule
(Term head) Retracts a rule by its head.void
retractRule
(Term head, List<Term> body) void
retractRule
(Term head, List<Term> body, MemoryLevel memoryLevel) Retracts a rule containing any number of premises and any number of conclusions.protected void
protected void
Any component that needs particular shutdown logic needs to override this method andvoid
unregisterForNotification
(Term queryTerm, ai.thinkingrobots.trade.TRADEServiceInfo callback) Unregister to be notified by Belief for a particular query term.Methods inherited from class edu.tufts.hrilab.diarc.DiarcComponent
createInstance, createInstance, createInstance, createInstance, executionLoop, getMyGroupConstraints, getMyGroups, getMyService, getMyServices, main, shutdown
-
Field Details
-
agentNames
-
notificationRequests
-
notificationsLock
-
proverType
Specify prover type (prolog, asp, etc). -
initializationFiles
Files to initialize prover. -
dbpath
SQL path. -
currProver
-
currLevel
-
-
Constructor Details
-
BeliefComponent
public BeliefComponent()
-
-
Method Details
-
init
protected void init()Description copied from class:DiarcComponent
Perform any component initialization. This should not be used for setting local fields to default values as was the case in DIARC. This method is called after the constructor, and after parseArgs. Setting default values should be done in field declaration or in the constructor.- Overrides:
init
in classDiarcComponent
-
shutdownComponent
protected void shutdownComponent()Description copied from class:DiarcComponent
Any component that needs particular shutdown logic needs to override this method and- Overrides:
shutdownComponent
in classDiarcComponent
-
additionalUsageInfo
Description copied from class:DiarcComponent
Command line options available in sub-class. This should be paired with a parseArgs implementation.- Overrides:
additionalUsageInfo
in classDiarcComponent
- Returns:
-
parseArgs
public void parseArgs(org.apache.commons.cli.CommandLine cmdLine) Description copied from class:DiarcComponent
Called directly after construction to pass runtime values that will override default values. This should parse all the options that additionalUsageInfo provides.zs- Overrides:
parseArgs
in classDiarcComponent
-
initializeFromFiles
Initialize SQL and notification prover from files.- Parameters:
filenames
-
-
addNotifications
-
registerForNotification
public void registerForNotification(Term queryTerm, ai.thinkingrobots.trade.TRADEServiceInfo callback) Description copied from interface:BeliefInterface
Register to be notified by Belief whenever the query term is true. The callback method must have the following method signature to receive callbacks:callbackMethod(Term queryTerm, List<Map<Variable, List<Symbol>>> bindings)
If the query contains no variables, a list containing one empty map will be returned for true queries.- Specified by:
registerForNotification
in interfaceBeliefInterface
-
unregisterForNotification
public void unregisterForNotification(Term queryTerm, ai.thinkingrobots.trade.TRADEServiceInfo callback) Description copied from interface:BeliefInterface
Unregister to be notified by Belief for a particular query term.- Specified by:
unregisterForNotification
in interfaceBeliefInterface
-
sendNotifications
protected void sendNotifications() -
clear
public void clear()- Specified by:
clear
in interfaceBeliefInterface
-
clear
Description copied from interface:BeliefInterface
Clear beliefs at specified memory level only.- Specified by:
clear
in interfaceBeliefInterface
-
assertBeliefs
- Specified by:
assertBeliefs
in interfaceBeliefInterface
-
assertBeliefs
Description copied from interface:BeliefInterface
Adds the beliefs in the argument to the Belief State of the agent. Note: new beliefs are added such that they take priority in unification to old beliefs. queryBelief() will still return all asserted and inferred bindings.- Specified by:
assertBeliefs
in interfaceBeliefInterface
- Parameters:
beliefs
- : set of beliefs to add to the Belief State.
-
assertBeliefs
Special method for use by the OperatorCheck class, so that (fluent_)equals(...) beliefs can be asserted without performing an operator check and resulting in an infinite loop. This method should NOT be exposed as a service.- Parameters:
beliefs
-memoryLevel
-checkOperator
-
-
assertBeliefs
public void assertBeliefs(Set<Term> beliefs, MemoryLevel memoryLevel, Predicate source, boolean checkOperator) -
assertBelief
- Specified by:
assertBelief
in interfaceBeliefInterface
-
assertBelief
Description copied from interface:BeliefInterface
Adds a single belief to the Belief State of the agent. Note: new beliefs are added such that they take priority in unification to old beliefs. queryBelief() will still return all asserted and inferred bindings.- Specified by:
assertBelief
in interfaceBeliefInterface
-
assertBelief
-
assertBelief
public void assertBelief(Term belief, MemoryLevel memoryLevel, Predicate source, boolean checkOperator) Special method for use by the OperatorCheck class, so that (fluent_)equals(...) beliefs can be asserted without performing an operator check and resulting in an infinite loop. This method should NOT be exposed as a service.- Parameters:
belief
-memoryLevel
-checkOperator
-
-
assertBelief
Special method for use by the OperatorCheck class, so that (fluent_)equals(...) beliefs can be asserted without performing an operator check and resulting in an infinite loop. This method should NOT be exposed as a service.- Parameters:
belief
-memoryLevel
-checkOperator
-
-
retractBeliefs
Description copied from interface:BeliefInterface
Removes the beliefs in the argument from the Belief State of the agent.- Specified by:
retractBeliefs
in interfaceBeliefInterface
- Parameters:
beliefs
- : set of beliefs to be removed
-
retractBeliefs
- Specified by:
retractBeliefs
in interfaceBeliefInterface
-
retractBelief
Description copied from interface:BeliefInterface
Removes a single belief from the Belief State of the agent.- Specified by:
retractBelief
in interfaceBeliefInterface
-
retractBelief
- Specified by:
retractBelief
in interfaceBeliefInterface
-
assertRule
Description copied from interface:BeliefInterface
Asserts a rule with one premise and a set of conclusions into the Belief State of the agent.- Specified by:
assertRule
in interfaceBeliefInterface
-
assertRule
- Specified by:
assertRule
in interfaceBeliefInterface
-
retractRule
Description copied from interface:BeliefInterface
Retracts a rule containing any number of premises and any number of conclusions.- Specified by:
retractRule
in interfaceBeliefInterface
-
retractRule
Description copied from interface:BeliefInterface
Retracts a rule by its head.- Specified by:
retractRule
in interfaceBeliefInterface
-
retractRule
- Specified by:
retractRule
in interfaceBeliefInterface
-
createClone
Description copied from interface:BeliefInterface
Copy the prover and sql state to a new BeliefComponent instance and return it. This should not automatically register the new component with TRADE, and is up to the caller to register if desired.- Specified by:
createClone
in interfaceBeliefInterface
- Returns:
-
getFacts
Description copied from interface:BeliefInterface
Returns list of current facts in predicate form. This returns facts that are explicitly true, and facts that are true as a result of inference.- Specified by:
getFacts
in interfaceBeliefInterface
- Returns:
- Facts
-
getFacts
Description copied from interface:BeliefInterface
Returns list of current facts in predicate form. This returns facts that are explicitly true, and facts that are true as a result of inference, using facts and rules from specified MemoryLevel.- Specified by:
getFacts
in interfaceBeliefInterface
- Returns:
- Facts
-
getRules
- Specified by:
getRules
in interfaceBeliefInterface
-
getRules
Description copied from interface:BeliefInterface
Returns list of current rules in predicate form, head first (conclusion) and then body (premises).- Specified by:
getRules
in interfaceBeliefInterface
- Returns:
- List of pairs of rulehead and rulebody.
-
getHistory
public List<org.apache.commons.lang3.tuple.Pair<Term,org.apache.commons.lang3.tuple.Pair<Symbol, getHistory()Symbol>>> - Specified by:
getHistory
in interfaceBeliefInterface
-
getHistory
public List<org.apache.commons.lang3.tuple.Pair<Term,org.apache.commons.lang3.tuple.Pair<Symbol, getHistorySymbol>>> (MemoryLevel memoryLevel) Description copied from interface:BeliefInterface
Returns list of past facts in predicate form, paired with their assertion and retraction times.- Specified by:
getHistory
in interfaceBeliefInterface
- Returns:
- List of pairs of facts and start/end times.
-
queryLastSource
-
queryLastTime
-
queryCount
-
queryBelief
- Specified by:
queryBelief
in interfaceBeliefInterface
-
queryBelief
Description copied from interface:BeliefInterface
Queries the Belief State about the term in the argument, and a set of bindings corresponding to all of the found answers.- Specified by:
queryBelief
in interfaceBeliefInterface
- Parameters:
query
- : a query in Term format- Returns:
- an ArrayList of bindings: here represented as a HashMap from Variables to Symbols
-
queryBelief
-
queryBelief
- Specified by:
queryBelief
in interfaceBeliefInterface
-
queryBelief
Description copied from interface:BeliefInterface
Queries the Belief State with N independent queries, and returns N binding lists.- Specified by:
queryBelief
in interfaceBeliefInterface
- Parameters:
queries
- : a list of N queries in Term format- Returns:
- an List of N lists of bindings: here represented as a HashMap from Variables to Symbols
-
querySupport
- Specified by:
querySupport
in interfaceBeliefInterface
-
querySupport
Description copied from interface:BeliefInterface
Make query and return if query has support (is true).- Specified by:
querySupport
in interfaceBeliefInterface
-
querySupport
-
querySupportWithExplanation
public org.apache.commons.lang3.tuple.Pair<Boolean,Map<Term, querySupportWithExplanationBoolean>> (Term query) - Specified by:
querySupportWithExplanation
in interfaceBeliefInterface
-
querySupportWithExplanation
public org.apache.commons.lang3.tuple.Pair<Boolean,Map<Term, querySupportWithExplanationBoolean>> (Term query, MemoryLevel memoryLevel) Description copied from interface:BeliefInterface
Queries true or false- Specified by:
querySupportWithExplanation
in interfaceBeliefInterface
- Returns:
- True or false, paired with a map of facts and booleans which lead to the original query being true or false.
-
queryAtTime
Description copied from interface:BeliefInterface
Make query using all facts that were true at time t.- Specified by:
queryAtTime
in interfaceBeliefInterface
- Returns:
- Query results
-
queryRecentFacts
Description copied from interface:BeliefInterface
Make query using last n facts most recently asserted to the database (out of all facts, not necessarily currently true ones).- Specified by:
queryRecentFacts
in interfaceBeliefInterface
- Returns:
- Query results
-
queryFactsInTimeframe
Description copied from interface:BeliefInterface
Make query using facts which were true from start to end of timeframe.- Specified by:
queryFactsInTimeframe
in interfaceBeliefInterface
- Returns:
- Query results
-
queryRecency
Description copied from interface:BeliefInterface
Query for how long ago a belief was asserted and retracted.- Specified by:
queryRecency
in interfaceBeliefInterface
- Returns:
- Query results
-
getNotificationProver
This exposes the notification prover to the BeliefGUI, and should not be used by anything else.- Returns:
-
getAllDiarcAgentsForActor
Queries belief for all of the agents corresponding to the given actor e.g. a single diarcAgent, or a collection of diarcAgents which are members of a team. Queries for all valid actor names if null passed as argument.- Parameters:
actor
- for which to return all descendants in the team tree (can be name or name:type)groupFormat
- true if agent:name:type form desired. false if name:type desired.- Returns:
- a set of agent group strings which correspond to the leaves of the team hierarchy underneath the given "actor".
-
getAllAgentTeams
Get a map from team names to the set of diarcAgents which make up that team.- Returns:
- a mapping from team names to the diarcAgents within the team.
-