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 MemoryLevelprotected Proverprotected StringSQL path.protected Map<MemoryLevel,List<String>> Files to initialize prover.protected final Objectprotected Prover.EngineSpecify 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.booleanaddNotifications(Predicate queryTerm, List<Symbol> callbackTerm) voidassertBelief(Term belief) voidassertBelief(Term belief, MemoryLevel memoryLevel) Adds a single belief to the Belief State of the agent.voidassertBelief(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.voidassertBelief(Term belief, MemoryLevel memoryLevel, Predicate source) voidassertBelief(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.voidassertBeliefs(Set<Term> beliefs) voidassertBeliefs(Set<Term> beliefs, MemoryLevel memoryLevel) Adds the beliefs in the argument to the Belief State of the agent.voidassertBeliefs(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.voidassertBeliefs(Set<Term> beliefs, MemoryLevel memoryLevel, Predicate source, boolean checkOperator) voidassertRule(Term head, List<Term> body) voidassertRule(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.voidclear()voidclear(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 voidinit()Perform any component initialization.protected voidinitializeFromFiles(Map<MemoryLevel, List<String>> filenames) Initialize SQL and notification prover from files.voidparseArgs(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.intqueryCount(Term query) queryFactsInTimeframe(Term query, Long start, Long end) Make query using facts which were true from start to end of timeframe.longqueryLastSource(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 falsevoidregisterForNotification(Term queryTerm, ai.thinkingrobots.trade.TRADEServiceInfo callback) Register to be notified by Belief whenever the query term is true.voidretractBelief(Term belief) voidretractBelief(Term belief, MemoryLevel memoryLevel) Removes a single belief from the Belief State of the agent.voidretractBeliefs(Set<Term> beliefs) voidretractBeliefs(Set<Term> beliefs, MemoryLevel memoryLevel) Removes the beliefs in the argument from the Belief State of the agent.voidretractRule(Term head) Retracts a rule by its head.voidretractRule(Term head, List<Term> body) voidretractRule(Term head, List<Term> body, MemoryLevel memoryLevel) Retracts a rule containing any number of premises and any number of conclusions.protected voidprotected voidAny component that needs particular shutdown logic needs to override this method andvoidunregisterForNotification(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:DiarcComponentPerform 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:
initin classDiarcComponent
-
shutdownComponent
protected void shutdownComponent()Description copied from class:DiarcComponentAny component that needs particular shutdown logic needs to override this method and- Overrides:
shutdownComponentin classDiarcComponent
-
additionalUsageInfo
Description copied from class:DiarcComponentCommand line options available in sub-class. This should be paired with a parseArgs implementation.- Overrides:
additionalUsageInfoin classDiarcComponent- Returns:
-
parseArgs
public void parseArgs(org.apache.commons.cli.CommandLine cmdLine) Description copied from class:DiarcComponentCalled directly after construction to pass runtime values that will override default values. This should parse all the options that additionalUsageInfo provides.zs- Overrides:
parseArgsin 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:BeliefInterfaceRegister 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:
registerForNotificationin interfaceBeliefInterface
-
unregisterForNotification
public void unregisterForNotification(Term queryTerm, ai.thinkingrobots.trade.TRADEServiceInfo callback) Description copied from interface:BeliefInterfaceUnregister to be notified by Belief for a particular query term.- Specified by:
unregisterForNotificationin interfaceBeliefInterface
-
sendNotifications
protected void sendNotifications() -
clear
public void clear()- Specified by:
clearin interfaceBeliefInterface
-
clear
Description copied from interface:BeliefInterfaceClear beliefs at specified memory level only.- Specified by:
clearin interfaceBeliefInterface
-
assertBeliefs
- Specified by:
assertBeliefsin interfaceBeliefInterface
-
assertBeliefs
Description copied from interface:BeliefInterfaceAdds 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:
assertBeliefsin 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:
assertBeliefin interfaceBeliefInterface
-
assertBelief
Description copied from interface:BeliefInterfaceAdds 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:
assertBeliefin 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:BeliefInterfaceRemoves the beliefs in the argument from the Belief State of the agent.- Specified by:
retractBeliefsin interfaceBeliefInterface- Parameters:
beliefs- : set of beliefs to be removed
-
retractBeliefs
- Specified by:
retractBeliefsin interfaceBeliefInterface
-
retractBelief
Description copied from interface:BeliefInterfaceRemoves a single belief from the Belief State of the agent.- Specified by:
retractBeliefin interfaceBeliefInterface
-
retractBelief
- Specified by:
retractBeliefin interfaceBeliefInterface
-
assertRule
Description copied from interface:BeliefInterfaceAsserts a rule with one premise and a set of conclusions into the Belief State of the agent.- Specified by:
assertRulein interfaceBeliefInterface
-
assertRule
- Specified by:
assertRulein interfaceBeliefInterface
-
retractRule
Description copied from interface:BeliefInterfaceRetracts a rule containing any number of premises and any number of conclusions.- Specified by:
retractRulein interfaceBeliefInterface
-
retractRule
Description copied from interface:BeliefInterfaceRetracts a rule by its head.- Specified by:
retractRulein interfaceBeliefInterface
-
retractRule
- Specified by:
retractRulein interfaceBeliefInterface
-
createClone
Description copied from interface:BeliefInterfaceCopy 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:
createClonein interfaceBeliefInterface- Returns:
-
getFacts
Description copied from interface:BeliefInterfaceReturns 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:
getFactsin interfaceBeliefInterface- Returns:
- Facts
-
getFacts
Description copied from interface:BeliefInterfaceReturns 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:
getFactsin interfaceBeliefInterface- Returns:
- Facts
-
getRules
- Specified by:
getRulesin interfaceBeliefInterface
-
getRules
Description copied from interface:BeliefInterfaceReturns list of current rules in predicate form, head first (conclusion) and then body (premises).- Specified by:
getRulesin 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:
getHistoryin 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:BeliefInterfaceReturns list of past facts in predicate form, paired with their assertion and retraction times.- Specified by:
getHistoryin interfaceBeliefInterface- Returns:
- List of pairs of facts and start/end times.
-
queryLastSource
-
queryLastTime
-
queryCount
-
queryBelief
- Specified by:
queryBeliefin interfaceBeliefInterface
-
queryBelief
Description copied from interface:BeliefInterfaceQueries the Belief State about the term in the argument, and a set of bindings corresponding to all of the found answers.- Specified by:
queryBeliefin 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:
queryBeliefin interfaceBeliefInterface
-
queryBelief
Description copied from interface:BeliefInterfaceQueries the Belief State with N independent queries, and returns N binding lists.- Specified by:
queryBeliefin 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:
querySupportin interfaceBeliefInterface
-
querySupport
Description copied from interface:BeliefInterfaceMake query and return if query has support (is true).- Specified by:
querySupportin interfaceBeliefInterface
-
querySupport
-
querySupportWithExplanation
public org.apache.commons.lang3.tuple.Pair<Boolean,Map<Term, querySupportWithExplanationBoolean>> (Term query) - Specified by:
querySupportWithExplanationin interfaceBeliefInterface
-
querySupportWithExplanation
public org.apache.commons.lang3.tuple.Pair<Boolean,Map<Term, querySupportWithExplanationBoolean>> (Term query, MemoryLevel memoryLevel) Description copied from interface:BeliefInterfaceQueries true or false- Specified by:
querySupportWithExplanationin 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:BeliefInterfaceMake query using all facts that were true at time t.- Specified by:
queryAtTimein interfaceBeliefInterface- Returns:
- Query results
-
queryRecentFacts
Description copied from interface:BeliefInterfaceMake query using last n facts most recently asserted to the database (out of all facts, not necessarily currently true ones).- Specified by:
queryRecentFactsin interfaceBeliefInterface- Returns:
- Query results
-
queryFactsInTimeframe
Description copied from interface:BeliefInterfaceMake query using facts which were true from start to end of timeframe.- Specified by:
queryFactsInTimeframein interfaceBeliefInterface- Returns:
- Query results
-
queryRecency
Description copied from interface:BeliefInterfaceQuery for how long ago a belief was asserted and retracted.- Specified by:
queryRecencyin 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.
-