Class OntologySolverBase

  • All Implemented Interfaces:
    java.lang.Cloneable, Changeable, Configurable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
    Direct Known Subclasses:
    OntologySolver

    public abstract class OntologySolverBase
    extends MoMLModelAttribute
    The base abstract class for an ontology solver.

    The base class provides the core functionality for ontology solver resolution. It provides a method to create an OntologyAdapter for any given model component. The model component can be an object of any Ptolemy class (e.g. ASTPtRootNode, Sink, Entity, and FSMActor). A model component, in turn, may have one or multiple objects to which ontology concepts can be attached.

    Subclasses needs to implement resolveConcepts() to specify exactly how to perform the ontology concept resolution. For example, one may gather all the constraints from the OntologyAdapters and feed them into a constraint solver.

    Every OntologySolver is linked together by the SharedParameter called "ontologySolverUtilitiesWrapper", which contains the shared utility object. This allows every OntologySolver to find other solvers in the model.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Man-Kit Leung
    Pt.AcceptedRating:
    Red (mankit)
    Pt.ProposedRating:
    Red (mankit)
    • Field Detail

      • ontologySolverUtilitiesWrapper

        public SharedParameter ontologySolverUtilitiesWrapper
        The shared parameter that links together every solver in the same model.
      • _adapterStore

        protected java.util.HashMap<java.lang.Object,​OntologyAdapter> _adapterStore
        The HashMap that caches components and their PropertyAdapter objects.
      • _nonSettables

        protected java.util.HashSet<java.lang.Object> _nonSettables
        The set of property-able objects that have non-settable property. A non-settable property results from setting an object with a fixed property through PropertyAdapter.setEquals().
      • _resolvedProperties

        protected java.util.HashMap<java.lang.Object,​Concept> _resolvedProperties
        The HashMap that caches property-able objects and their Property values. Each mapping is a pair of Object and Property.
      • _ontologySolverUtilities

        protected OntologySolverUtilities _ontologySolverUtilities
        The utilities shared between all solvers.
    • Constructor Detail

      • OntologySolverBase

        public OntologySolverBase​(NamedObj container,
                                  java.lang.String name)
                           throws IllegalActionException,
                                  NameDuplicationException
        Construct an OntologySolverBase with the specified container and name. If this is the first OntologySolver created in the model, the shared utility object will also be created.
        Parameters:
        container - The specified container.
        name - The specified name.
        Throws:
        IllegalActionException - If the OntologySolverBase is not of an acceptable attribute for the container.
        NameDuplicationException - If the name coincides with an attribute already in the container.
    • Method Detail

      • clearResolvedConcept

        public void clearResolvedConcept​(java.lang.Object object)
        Clear the resolved property for the specified object. The object is assumed to be property-able; otherwise, nothing happens.
        Parameters:
        object - The specified object.
      • cleanConstants

        public static void cleanConstants()
        Traverse the list of constants and remove any ConceptTokens that may have been added by MonotonicyConceptFunction.
        See Also:
        MonotonicityConceptFunction
      • getAllAdapters

        public java.util.List<OntologyAdapter> getAllAdapters()
                                                       throws IllegalActionException
        Return the list of all PropertyAdapters associated with this ontology solver.
        Returns:
        The list of PropertyAdapters.
        Throws:
        IllegalActionException - If there is an exception from getting all the subAdapters.
      • getAllConceptableNamedObjs

        public java.util.Set<NamedObj> getAllConceptableNamedObjs()
                                                           throws IllegalActionException
        Return the subset of all concept-able objects that are NamedObjs.
        Returns:
        The set of all concept-able NamedObjs.
        Throws:
        IllegalActionException - Thrown if an error occurs when getting the adapters or the concept-able objects from them.
      • getAllPropertyables

        public java.util.Set getAllPropertyables()
                                          throws IllegalActionException
        Return the set of all property-able objects obtained from all PropertyAdapter.
        Returns:
        The set of all property-able objects.
        Throws:
        IllegalActionException - Thrown if an error occurs when getting the adapters or the property-able objects from them.
      • getAllSolvers

        public static java.util.List<OntologySolver> getAllSolvers​(SharedParameter sharedParameter)
        Return the list of all solvers that are in the same model. They are linked by the specified SharedParameter.
        Parameters:
        sharedParameter - The specified SharedParameter links together the solvers.
        Returns:
        A list of PropertySolvers.
      • getAttribute

        public Attribute getAttribute​(ASTPtRootNode node)
        Get the attribute that corresponds to the specified ASTPtRootNode. This assumes that the correspondence is recorded previously through calling OntologySolverUtilities.putAttribute(ASTPtRootNode, Attribute).
        Parameters:
        node - The specified ASTPtRootNode.
        Returns:
        The attribute associated with the specified ASTPtRootNode.
        Throws:
        java.lang.AssertionError - Thrown if the specified node does not have a corresponding attribute.
      • getAdapter

        public OntologyAdapter getAdapter​(java.lang.Object object)
                                   throws IllegalActionException
        Return the property adapter for the specified component.
        Parameters:
        object - The specified component.
        Returns:
        The property adapter for the component.
        Throws:
        IllegalActionException - Thrown if the adapter cannot be found or instantiated.
      • getAllContainedOntologies

        public java.util.List<Ontology> getAllContainedOntologies()
        Return a list of all the ontologies contained in this solver. If it contains no ontologies, then return an empty list.
        Returns:
        A list containing all ontologies in this solver.
      • getOntology

        public Ontology getOntology()
                             throws IllegalActionException
        Return the ontology for this constraint solver. If this solver contains more than one ontology, then return the last one added. If it contains no ontologies, then return null.
        Returns:
        The ontology for this constraint solver.
        Throws:
        IllegalActionException - If the structure is not a lattice.
      • getParser

        public PtParser getParser()
        Return the expression parser.
        Returns:
        The expression parser.
      • getParseTree

        public ASTPtRootNode getParseTree​(Attribute attribute)
                                   throws IllegalActionException
        Return the root ASTPtRootNode associated with the specified attribute.
        Parameters:
        attribute - The specified attribute.
        Returns:
        The root ASTPtRootNode associated with the specified attribute.
        Throws:
        IllegalActionException - Thrown if there is a problem getting the parse tree.
      • getConcept

        public Concept getConcept​(java.lang.Object object)
        Return the concept value associated with the specified object.
        Parameters:
        object - The specified object.
        Returns:
        The property of the specified object.
        See Also:
        setConcept(Object, Concept)
      • initialize

        public void initialize()
                        throws IllegalActionException
        Initialize the solver. In the base class, only calls reset(). Subclasses can add functionality.
        Throws:
        IllegalActionException - Thrown if there is a problem initializing the solver.
      • markAsNonSettable

        public void markAsNonSettable​(java.lang.Object object)
        Mark the property of the specified object as non-settable. The specified object has a fixed assigned property.
        Parameters:
        object - The specified object.
      • reset

        public void reset()
        Reset the solver.
      • resetAll

        public void resetAll()
        Reset every solver in the model.
      • resolveConcepts

        public abstract void resolveConcepts()
                                      throws IllegalActionException
        Execute the OntologySolver's algorithm to resolve which Concepts in the Ontology are assigned to each object in the model.
        Throws:
        IllegalActionException - If the ontology resolution fails.
      • setOntologySolverUtilities

        public void setOntologySolverUtilities​(OntologySolverUtilities solverUtilities)
        Set the shared utility object to the given object.
        Parameters:
        solverUtilities - The given ontology solver utilities object.
        See Also:
        getOntologySolverUtilities()
      • setConcept

        public void setConcept​(java.lang.Object object,
                               Concept property)
        Set the resolved property of the specified object.
        Parameters:
        object - The specified object.
        property - The specified property.
        See Also:
        getConcept(Object)
      • _getAdapter

        protected static OntologyAdapter _getAdapter​(java.lang.Object component,
                                                     OntologySolverBase solver)
                                              throws IllegalActionException
        Return the PropertyAdapter for the specified component. This instantiates a new PropertyAdapter if it does not already exist for the specified component. This method is static so it can be called in any subclass of OntologySolverBase regardless of how many classes are in between in the inheritance hierarchy.
        Parameters:
        component - The specified component.
        solver - The solver for which to get the adapter.
        Returns:
        The PropertyAdapter for the specified component.
        Throws:
        IllegalActionException - Thrown if the PropertyAdapter cannot be instantiated.
      • _getPackageName

        protected static java.lang.String _getPackageName​(OntologySolverBase solver)
                                                   throws IllegalActionException
        Return the package name that contains the class of this solver.
        Parameters:
        solver - The ontology solver for which we get the adapter package name.
        Returns:
        The package name.
        Throws:
        IllegalActionException - Thrown if there is a problem getting the ontology package name.
      • _toplevel

        protected NamedObj _toplevel()
        Return the top level of the model hierarchy for the model we want to analyze.
        Returns:
        The top level model object as a NamedObj