Class BeliefComponent

java.lang.Object
edu.tufts.hrilab.diarc.DiarcComponent
edu.tufts.hrilab.belief.BeliefComponent
All Implemented Interfaces:
BeliefInterface

public class BeliefComponent extends DiarcComponent implements BeliefInterface
  • Field Details

    • agentNames

      protected List<String> agentNames
    • notificationRequests

      protected final Map<Term,List<edu.tufts.hrilab.belief.BeliefComponent.NotificationRequest>> notificationRequests
    • notificationsLock

      protected final Object notificationsLock
    • proverType

      protected Prover.Engine proverType
      Specify prover type (prolog, asp, etc).
    • initializationFiles

      protected Map<MemoryLevel,List<String>> initializationFiles
      Files to initialize prover.
    • dbpath

      protected String dbpath
      SQL path.
    • currProver

      protected Prover currProver
    • currLevel

      protected MemoryLevel 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 class DiarcComponent
    • 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 class DiarcComponent
    • additionalUsageInfo

      public List<org.apache.commons.cli.Option> additionalUsageInfo()
      Description copied from class: DiarcComponent
      Command line options available in sub-class. This should be paired with a parseArgs implementation.
      Overrides:
      additionalUsageInfo in class DiarcComponent
      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 class DiarcComponent
    • initializeFromFiles

      protected void initializeFromFiles(Map<MemoryLevel,List<String>> filenames)
      Initialize SQL and notification prover from files.
      Parameters:
      filenames -
    • addNotifications

      public boolean addNotifications(Predicate queryTerm, List<Symbol> callbackTerm)
    • 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 interface BeliefInterface
    • 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 interface BeliefInterface
    • sendNotifications

      protected void sendNotifications()
    • clear

      public void clear()
      Specified by:
      clear in interface BeliefInterface
    • clear

      public void clear(MemoryLevel memoryLevel)
      Description copied from interface: BeliefInterface
      Clear beliefs at specified memory level only.
      Specified by:
      clear in interface BeliefInterface
    • assertBeliefs

      public void assertBeliefs(Set<Term> beliefs)
      Specified by:
      assertBeliefs in interface BeliefInterface
    • assertBeliefs

      public void assertBeliefs(Set<Term> beliefs, MemoryLevel memoryLevel)
      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 interface BeliefInterface
      Parameters:
      beliefs - : set of beliefs to add to the Belief State.
    • assertBeliefs

      public 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. 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

      public void assertBelief(Term belief)
      Specified by:
      assertBelief in interface BeliefInterface
    • assertBelief

      public void assertBelief(Term belief, MemoryLevel memoryLevel)
      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 interface BeliefInterface
    • assertBelief

      public void assertBelief(Term belief, MemoryLevel memoryLevel, Predicate source)
    • 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

      public 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. This method should NOT be exposed as a service.
      Parameters:
      belief -
      memoryLevel -
      checkOperator -
    • retractBeliefs

      public void retractBeliefs(Set<Term> beliefs, MemoryLevel memoryLevel)
      Description copied from interface: BeliefInterface
      Removes the beliefs in the argument from the Belief State of the agent.
      Specified by:
      retractBeliefs in interface BeliefInterface
      Parameters:
      beliefs - : set of beliefs to be removed
    • retractBeliefs

      public void retractBeliefs(Set<Term> beliefs)
      Specified by:
      retractBeliefs in interface BeliefInterface
    • retractBelief

      public void retractBelief(Term belief, MemoryLevel memoryLevel)
      Description copied from interface: BeliefInterface
      Removes a single belief from the Belief State of the agent.
      Specified by:
      retractBelief in interface BeliefInterface
    • retractBelief

      public void retractBelief(Term belief)
      Specified by:
      retractBelief in interface BeliefInterface
    • assertRule

      public void assertRule(Term head, List<Term> body, MemoryLevel memoryLevel)
      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 interface BeliefInterface
    • assertRule

      public void assertRule(Term head, List<Term> body)
      Specified by:
      assertRule in interface BeliefInterface
    • retractRule

      public void retractRule(Term head, List<Term> body, MemoryLevel memoryLevel)
      Description copied from interface: BeliefInterface
      Retracts a rule containing any number of premises and any number of conclusions.
      Specified by:
      retractRule in interface BeliefInterface
    • retractRule

      public void retractRule(Term head)
      Description copied from interface: BeliefInterface
      Retracts a rule by its head.
      Specified by:
      retractRule in interface BeliefInterface
    • retractRule

      public void retractRule(Term head, List<Term> body)
      Specified by:
      retractRule in interface BeliefInterface
    • createClone

      public BeliefComponent 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 interface BeliefInterface
      Returns:
    • getFacts

      public List<Term> 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 interface BeliefInterface
      Returns:
      Facts
    • getFacts

      public List<Term> getFacts(MemoryLevel memoryLevel)
      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 interface BeliefInterface
      Returns:
      Facts
    • getRules

      public List<org.apache.commons.lang3.tuple.Pair<Term,List<Term>>> getRules()
      Specified by:
      getRules in interface BeliefInterface
    • getRules

      public List<org.apache.commons.lang3.tuple.Pair<Term,List<Term>>> getRules(MemoryLevel memoryLevel)
      Description copied from interface: BeliefInterface
      Returns list of current rules in predicate form, head first (conclusion) and then body (premises).
      Specified by:
      getRules in interface BeliefInterface
      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,Symbol>>> getHistory()
      Specified by:
      getHistory in interface BeliefInterface
    • getHistory

      public List<org.apache.commons.lang3.tuple.Pair<Term,org.apache.commons.lang3.tuple.Pair<Symbol,Symbol>>> getHistory(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 interface BeliefInterface
      Returns:
      List of pairs of facts and start/end times.
    • queryLastSource

      public long queryLastSource(Term query)
    • queryLastTime

      public Symbol queryLastTime(Term query)
    • queryCount

      public int queryCount(Term query)
    • queryBelief

      public List<Map<Variable,Symbol>> queryBelief(Term query)
      Specified by:
      queryBelief in interface BeliefInterface
    • queryBelief

      public List<Map<Variable,Symbol>> queryBelief(Term query, MemoryLevel memoryLevel)
      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 interface BeliefInterface
      Parameters:
      query - : a query in Term format
      Returns:
      an ArrayList of bindings: here represented as a HashMap from Variables to Symbols
    • queryBelief

      public List<Map<Variable,Symbol>> queryBelief(Term query, MemoryLevel memoryLevel, boolean checkOperator)
    • queryBelief

      public List<List<Map<Variable,Symbol>>> queryBelief(List<Term> queries)
      Specified by:
      queryBelief in interface BeliefInterface
    • queryBelief

      public List<List<Map<Variable,Symbol>>> queryBelief(List<Term> queries, MemoryLevel memoryLevel)
      Description copied from interface: BeliefInterface
      Queries the Belief State with N independent queries, and returns N binding lists.
      Specified by:
      queryBelief in interface BeliefInterface
      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

      public Boolean querySupport(Term query)
      Specified by:
      querySupport in interface BeliefInterface
    • querySupport

      public Boolean querySupport(Term query, MemoryLevel memoryLevel)
      Description copied from interface: BeliefInterface
      Make query and return if query has support (is true).
      Specified by:
      querySupport in interface BeliefInterface
    • querySupport

      public Boolean querySupport(Term query, MemoryLevel memoryLevel, boolean checkOperator)
    • querySupportWithExplanation

      public org.apache.commons.lang3.tuple.Pair<Boolean,Map<Term,Boolean>> querySupportWithExplanation(Term query)
      Specified by:
      querySupportWithExplanation in interface BeliefInterface
    • querySupportWithExplanation

      public org.apache.commons.lang3.tuple.Pair<Boolean,Map<Term,Boolean>> querySupportWithExplanation(Term query, MemoryLevel memoryLevel)
      Description copied from interface: BeliefInterface
      Queries true or false
      Specified by:
      querySupportWithExplanation in interface BeliefInterface
      Returns:
      True or false, paired with a map of facts and booleans which lead to the original query being true or false.
    • queryAtTime

      public List<Map<Variable,Symbol>> queryAtTime(Term query, Long time)
      Description copied from interface: BeliefInterface
      Make query using all facts that were true at time t.
      Specified by:
      queryAtTime in interface BeliefInterface
      Returns:
      Query results
    • queryRecentFacts

      public List<Map<Variable,Symbol>> queryRecentFacts(Term query, int n)
      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 interface BeliefInterface
      Returns:
      Query results
    • queryFactsInTimeframe

      public List<Map<Variable,Symbol>> queryFactsInTimeframe(Term query, Long start, Long end)
      Description copied from interface: BeliefInterface
      Make query using facts which were true from start to end of timeframe.
      Specified by:
      queryFactsInTimeframe in interface BeliefInterface
      Returns:
      Query results
    • queryRecency

      public Map<Term,List<org.apache.commons.lang3.tuple.Pair<Long,Long>>> queryRecency(Term query)
      Description copied from interface: BeliefInterface
      Query for how long ago a belief was asserted and retracted.
      Specified by:
      queryRecency in interface BeliefInterface
      Returns:
      Query results
    • getNotificationProver

      public Prover getNotificationProver()
      This exposes the notification prover to the BeliefGUI, and should not be used by anything else.
      Returns:
    • getAllDiarcAgentsForActor

      public Set<String> getAllDiarcAgentsForActor(Symbol actor, boolean groupFormat)
      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

      public Map<Symbol,Set<Symbol>> 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.