Class Consultant<T extends Reference>

java.lang.Object
edu.tufts.hrilab.consultant.Consultant<T>
All Implemented Interfaces:
ConsultantInterface
Direct Known Subclasses:
ABBAreaConsultant, ABBLocationConsultant, AITVisionConsultant, CognexConsultant, CognexConsultant, ContextConsultant, ItemConsultant, MPoseConsultant, PoseConsultant, RWSPoseConsultant, SpotNavGraphLocationConsultant, TemiV3PoseConsultant, VisionConsultant

public abstract class Consultant<T extends Reference> extends Object implements ConsultantInterface
  • Field Details

    • log

      protected org.slf4j.Logger log
    • refNumber

      protected int refNumber
      Reference counter used to assign unique refIds.
    • propertiesHandled

      protected List<Term> propertiesHandled
      All properties that can be handled by this consultant, excluding the defaultProperties.
    • defaultProperties

      protected List<Term> defaultProperties
      These properties implicitly apply to every reference in this consultant, even though they will not appear as explicit properties in the reference.
    • references

      protected Map<Symbol,T extends Reference> references
      All References hashed refId.
    • kbName

      protected String kbName
      Knowledge base name.
    • refConstructor

      protected Constructor<T extends Reference> refConstructor
      Constructor for templated Reference class.
  • Constructor Details

    • Consultant

      public Consultant(Class<T> refClass, String kbName)
      Parameters:
      refClass - - Reference class. Used to construct new instances of Reference.
      kbName -
    • Consultant

      public Consultant(Class<T> refClass, String kbName, List<String> properties)
  • Method Details

    • getKBName

      public String getKBName()
      Description copied from interface: ConsultantInterface
      Returns name of things handles by this consultant (e.g., "objects", "locations", etc).
      Specified by:
      getKBName in interface ConsultantInterface
      Returns:
      knowledge base name
    • getPropertiesHandled

      public List<Term> getPropertiesHandled()
      Description copied from interface: ConsultantInterface
      Returns a list of Properties handled by this component.
      Specified by:
      getPropertiesHandled in interface ConsultantInterface
      Returns:
      list of Properties.
    • addPropertiesHandled

      public boolean addPropertiesHandled(List<Term> properties)
      Updates consultant and parser if any of the members of @properties are not already handled by the Consultant
      Parameters:
      properties - list of candidate properties
      Returns:
      true if propertiesHandled is modified
    • addReference

      public void addReference(T ref)
      Add new reference from some source (file or learning) to the consultant
      Parameters:
      ref - new reference to add
    • retractProperties

      public boolean retractProperties(Symbol refId, List<Term> properties)
    • getInitialDomain

      public List<Symbol> getInitialDomain(List<Term> query)
      Description copied from interface: ConsultantInterface
      Returns a list of currently known refIds (it takes a seq of Properties, to optionally do some pre-processing to return a list of relevant candidates).
      Specified by:
      getInitialDomain in interface ConsultantInterface
      Returns:
      list of currently known ids
    • process

      public Double process(Term constraint, Map<Variable,Symbol> bindings)
      Description copied from interface: ConsultantInterface
      Returns the probability that a property (aka constraint) holds for an entity (specified by a map of free-variable to refId bindings).

      TODO: rename method to something more descriptive. how about getProbability or checkProperty?

      Specified by:
      process in interface ConsultantInterface
      Parameters:
      constraint - Property to check
      bindings - Map of free variables to refIds
      Returns:
      probability value [0.0. 1.0]
    • getActivatedEntities

      public Map<Symbol,Double> getActivatedEntities()
      Description copied from interface: ConsultantInterface
      Get a list of currently highly salient entities that should be considered "activated."
      Specified by:
      getActivatedEntities in interface ConsultantInterface
      Returns:
      list of refIds and probability pairs
    • getAssertedProperties

      public List<Term> getAssertedProperties(Symbol refId)
      Description copied from interface: ConsultantInterface
      Get the list of properties that have been asserted for a given refId.
      Specified by:
      getAssertedProperties in interface ConsultantInterface
      Parameters:
      refId - reference resolution id
      Returns:
      list of Properties
    • createReference

      public T createReference(Variable var, List<Term> properties)
      A convenience method for creating references from with a DIARC component housing a Consultant instance.
      Parameters:
      var - Variable associated with new reference (only important if properties contain more than one Variable)
      properties - semantic properties of reference
      Returns:
    • createReferences

      public Map<Variable,Symbol> createReferences(List<Variable> vars)
      Description copied from interface: ConsultantInterface
      new representations are created for each free-variable and returned in the binding list.
      Specified by:
      createReferences in interface ConsultantInterface
      Parameters:
      vars - list of free-variables
      Returns:
      list of bindings
    • assertProperties

      public boolean assertProperties(Map<Variable,Symbol> bindings, Double prob, List<Term> properties)
      Description copied from interface: ConsultantInterface
      an attempt is made to bring the knowledge base in line with the provided bindings, list of properties, and probability value.
      Specified by:
      assertProperties in interface ConsultantInterface
      Parameters:
      bindings - list of bindings in tuple form (free-variable and refId pair)
      prob - probability value
      properties - list of Properties
      Returns:
      whether the updated was successful?
    • assertProperties

      public boolean assertProperties(Symbol refId, List<Term> properties)
      Description copied from interface: ConsultantInterface
      Add properties to already existing object ref. Each property should contain a connection to the existing ref either by refId or refId's variable.
      Specified by:
      assertProperties in interface ConsultantInterface
      Returns:
    • getNextReferenceId

      protected Symbol getNextReferenceId()
      Helper method to generate next unique reference ID (e.g., object_3).
      Returns:
    • getReferenceSummaries

      public String getReferenceSummaries()
    • getReference

      public T getReference(Symbol refId)
    • getReferencesWithAllProperties

      public List<Symbol> getReferencesWithAllProperties(List<Term> properties)
      Get all references that have all of the given properties
      Parameters:
      properties - property to search for
      Returns:
      list of references
    • getReferencesWithAnyProperties

      public List<Symbol> getReferencesWithAnyProperties(List<Term> properties)
      Get all references that have any of the given properties
      Parameters:
      properties - property to search for
      Returns:
      list of references
    • convertToType

      public final <U> U convertToType(Symbol refId, Class<U> type)
      Convert refId to target class using the specified constraints to filter the results. This is to map references onto Java-types. If it's not possible for a refId to be converted to the specified type, null is returned.
      Specified by:
      convertToType in interface ConsultantInterface
      Type Parameters:
      U -
      Parameters:
      refId -
      type -
      Returns:
    • convertToType

      public final <U> U convertToType(Symbol refId, Class<U> type, List<? extends Term> constraints)
      Convert refId to target class using the specified constraints for to filter the results. This is to map references onto Java-types. If it's not possible for a refId to be converted to the specified type, null is returned. First-order-logic constraints can be used in some cases to provide additional constraints on the reference.
      Specified by:
      convertToType in interface ConsultantInterface
      Type Parameters:
      U -
      Parameters:
      refId -
      type -
      constraints -
      Returns:
    • localConvertToType

      protected abstract <U> U localConvertToType(Symbol refId, Class<U> type)
    • localConvertToType

      protected abstract <U> U localConvertToType(Symbol refId, Class<U> type, List<? extends Term> constraints)
    • registerForNewPropertyNotification

      public void registerForNewPropertyNotification(ai.thinkingrobots.trade.TRADEServiceInfo callback)
      Specified by:
      registerForNewPropertyNotification in interface ConsultantInterface
    • unregisterForNewPropertyNotification

      public void unregisterForNewPropertyNotification(ai.thinkingrobots.trade.TRADEServiceInfo callback)
      Specified by:
      unregisterForNewPropertyNotification in interface ConsultantInterface
    • notifyNewPropertySubscribers

      public void notifyNewPropertySubscribers()
      Specified by:
      notifyNewPropertySubscribers in interface ConsultantInterface
    • stripQuotesFromMorpheme

      public String stripQuotesFromMorpheme(String input)