Class OntologySolverBase

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

    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.

    Ptolemy II 10.0
    Man-Kit Leung
    Red (mankit)
    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,
        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.
        container - The specified container.
        name - The specified name.
        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.
        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:
      • getAllAdapters

        public java.util.List<OntologyAdapter> getAllAdapters()
                                                       throws IllegalActionException
        Return the list of all PropertyAdapters associated with this ontology solver.
        The list of PropertyAdapters.
        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.
        The set of all concept-able NamedObjs.
        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.
        The set of all property-able objects.
        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.
        sharedParameter - The specified SharedParameter links together the solvers.
        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).
        node - The specified ASTPtRootNode.
        The attribute associated with the specified ASTPtRootNode.
        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.
        object - The specified component.
        The property adapter for the component.
        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.
        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.
        The ontology for this constraint solver.
        IllegalActionException - If the structure is not a lattice.
      • getParser

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

        public ASTPtRootNode getParseTree​(Attribute attribute)
                                   throws IllegalActionException
        Return the root ASTPtRootNode associated with the specified attribute.
        attribute - The specified attribute.
        The root ASTPtRootNode associated with the specified attribute.
        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.
        object - The specified object.
        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.
        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.
        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.
        IllegalActionException - If the ontology resolution fails.
      • setOntologySolverUtilities

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

        public void setConcept​(java.lang.Object object,
                               Concept property)
        Set the resolved property of the specified object.
        object - The specified object.
        property - The specified property.
        See Also:
      • _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.
        component - The specified component.
        solver - The solver for which to get the adapter.
        The PropertyAdapter for the specified component.
        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.
        solver - The ontology solver for which we get the adapter package name.
        The package name.
        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.
        The top level model object as a NamedObj