Class OntologySolverBase
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.moml.MoMLModelAttribute
-
- ptolemy.data.ontologies.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)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.HashMap<java.lang.Object,OntologyAdapter>
_adapterStore
The HashMap that caches components and their PropertyAdapter objects.protected java.util.HashSet<java.lang.Object>
_nonSettables
The set of property-able objects that have non-settable property.protected OntologySolverUtilities
_ontologySolverUtilities
The utilities shared between all solvers.protected java.util.HashMap<java.lang.Object,Concept>
_resolvedProperties
The HashMap that caches property-able objects and their Property values.SharedParameter
ontologySolverUtilitiesWrapper
The shared parameter that links together every solver in the same model.-
Fields inherited from class ptolemy.moml.MoMLModelAttribute
_model, modelURL
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Constructor Summary
Constructors Constructor Description OntologySolverBase(NamedObj container, java.lang.String name)
Construct an OntologySolverBase with the specified container and name.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static OntologyAdapter
_getAdapter(java.lang.Object component, OntologySolverBase solver)
Return the PropertyAdapter for the specified component.protected static java.lang.String
_getPackageName(OntologySolverBase solver)
Return the package name that contains the class of this solver.protected NamedObj
_toplevel()
Return the top level of the model hierarchy for the model we want to analyze.static void
cleanConstants()
Traverse the list of constants and remove any ConceptTokens that may have been added by MonotonicyConceptFunction.void
clearResolvedConcept(java.lang.Object object)
Clear the resolved property for the specified object.java.lang.Object
clone(Workspace workspace)
Clone the object into the specified workspace.OntologyAdapter
getAdapter(java.lang.Object object)
Return the property adapter for the specified component.java.util.List<OntologyAdapter>
getAllAdapters()
Return the list of all PropertyAdapters associated with this ontology solver.java.util.Set<NamedObj>
getAllConceptableNamedObjs()
Return the subset of all concept-able objects that are NamedObjs.java.util.List<Ontology>
getAllContainedOntologies()
Return a list of all the ontologies contained in this solver.java.util.Set
getAllPropertyables()
Return the set of all property-able objects obtained from all PropertyAdapter.static java.util.List<OntologySolver>
getAllSolvers(SharedParameter sharedParameter)
Return the list of all solvers that are in the same model.Attribute
getAttribute(ASTPtRootNode node)
Get the attribute that corresponds to the specified ASTPtRootNode.Concept
getConcept(java.lang.Object object)
Return the concept value associated with the specified object.Ontology
getOntology()
Return the ontology for this constraint solver.OntologySolverUtilities
getOntologySolverUtilities()
Return the shared utility object.PtParser
getParser()
Return the expression parser.ASTPtRootNode
getParseTree(Attribute attribute)
Return the root ASTPtRootNode associated with the specified attribute.void
initialize()
Initialize the solver.void
markAsNonSettable(java.lang.Object object)
Mark the property of the specified object as non-settable.void
reset()
Reset the solver.void
resetAll()
Reset every solver in the model.abstract void
resolveConcepts()
Execute the OntologySolver's algorithm to resolve which Concepts in the Ontology are assigned to each object in the model.void
setConcept(java.lang.Object object, Concept property)
Set the resolved property of the specified object.void
setOntologySolverUtilities(OntologySolverUtilities solverUtilities)
Set the shared utility object to the given object.-
Methods inherited from class ptolemy.moml.MoMLModelAttribute
_exportMoMLContents, attributeChanged, configure, getConfigureSource, getConfigureText, getContainedModel
-
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setContainer, setName, updateContent
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
-
-
-
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
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the object into the specified workspace.- Overrides:
clone
in classMoMLModelAttribute
- Parameters:
workspace
- The workspace for the new object.- Returns:
- A new NamedObj.
- Throws:
java.lang.CloneNotSupportedException
- If any of the attributes cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
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 callingOntologySolverUtilities.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)
-
getOntologySolverUtilities
public OntologySolverUtilities getOntologySolverUtilities()
Return the shared utility object.- Returns:
- The shared utility object.
- See Also:
setOntologySolverUtilities(ptolemy.data.ontologies.OntologySolverUtilities)
-
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
-
-