Package ptolemy.data.ontologies
Class ExpressionConceptFunctionParseTreeEvaluator
- java.lang.Object
-
- ptolemy.data.expr.AbstractParseTreeVisitor
-
- ptolemy.data.expr.ParseTreeEvaluator
-
- ptolemy.data.ontologies.ExpressionConceptFunctionParseTreeEvaluator
-
- All Implemented Interfaces:
ParseTreeVisitor
public class ExpressionConceptFunctionParseTreeEvaluator extends ParseTreeEvaluator
Visit a parse tree for a string expression that defines a concept function and evaluate to the string name of the concept that should be the output.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Charles Shelton
- See Also:
ASTPtRootNode
- Pt.AcceptedRating:
- Red (cshelton)
- Pt.ProposedRating:
- Green (cshelton)
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Ontology>
_scopeOntologies
The list of ontologies that specify the domain for each input argument to the concept function defined by the parsed expression.-
Fields inherited from class ptolemy.data.expr.ParseTreeEvaluator
_evaluatedChildToken, _typeInference
-
-
Constructor Summary
Constructors Constructor Description ExpressionConceptFunctionParseTreeEvaluator(java.util.List<java.lang.String> argumentNames, java.util.List<Concept> inputConceptValues, OntologySolverModel solverModel, java.util.List<Ontology> argumentDomainOntologies, Ontology outputRangeOntology)
Construct an ExpressionConceptFunctionParseTreeEvaluator for evaluating expressions that represent concept functions.ExpressionConceptFunctionParseTreeEvaluator(java.util.Map<java.lang.String,Concept> arguments, OntologySolverModel solverModel, java.util.List<Ontology> domainOntologies, Ontology outputRangeOntology)
Construct an ExpressionConceptFunctionParseTreeEvaluator for evaluating expressions that represent concept functions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Concept
_getNamedConcept(java.lang.String conceptString)
Return the concept with the specified string representation.protected java.lang.String
_getNodeLabel(ASTPtLeafNode node)
Return the label for the leaf node.ConceptToken
evaluateParseTree(ASTPtRootNode node)
Evaluate the parse tree for the expression concept function with the specified root node.ConceptToken
evaluateParseTree(ASTPtRootNode node, ParserScope scope)
Evaluate the parse tree for the expression concept function with the specified root node using the specified scope to resolve the values of variables.void
visitFunctionApplicationNode(ASTPtFunctionApplicationNode node)
Evaluate a concept function contained in a concept function expression.void
visitLeafNode(ASTPtLeafNode node)
Evaluate each leaf node in the parse tree to a concept string.-
Methods inherited from class ptolemy.data.expr.ParseTreeEvaluator
_assert, _evaluateAllChildren, _evaluateArrayIndex, _evaluateChild, _evaluateMatrixIndex, _functionCall, _methodCall, _trace, _traceEnter, _traceLeave, traceParseTreeEvaluation, visitArrayConstructNode, visitBitwiseNode, visitFunctionalIfNode, visitFunctionDefinitionNode, visitLogicalNode, visitMatrixConstructNode, visitMethodCallNode, visitPowerNode, visitProductNode, visitRecordConstructNode, visitRelationalNode, visitShiftNode, visitSumNode, visitUnaryNode, visitUnionConstructNode
-
Methods inherited from class ptolemy.data.expr.AbstractParseTreeVisitor
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNode
-
-
-
-
Field Detail
-
_scopeOntologies
protected java.util.List<Ontology> _scopeOntologies
The list of ontologies that specify the domain for each input argument to the concept function defined by the parsed expression.
-
-
Constructor Detail
-
ExpressionConceptFunctionParseTreeEvaluator
public ExpressionConceptFunctionParseTreeEvaluator(java.util.List<java.lang.String> argumentNames, java.util.List<Concept> inputConceptValues, OntologySolverModel solverModel, java.util.List<Ontology> argumentDomainOntologies, Ontology outputRangeOntology) throws IllegalActionException
Construct an ExpressionConceptFunctionParseTreeEvaluator for evaluating expressions that represent concept functions.- Parameters:
argumentNames
- The array of argument names used in the concept function expression.inputConceptValues
- The array of concept values to which the arguments are set.solverModel
- The ontology solver model that contains the scope of other concept functions that can be called in the expression.argumentDomainOntologies
- The array of ontologies that represent the concept domain for each input concept argument.outputRangeOntology
- The ontology that represents the concept range for the concept function.- Throws:
IllegalActionException
- If there is a problem instantiating the parse tree evaluator object.
-
ExpressionConceptFunctionParseTreeEvaluator
public ExpressionConceptFunctionParseTreeEvaluator(java.util.Map<java.lang.String,Concept> arguments, OntologySolverModel solverModel, java.util.List<Ontology> domainOntologies, Ontology outputRangeOntology) throws IllegalActionException
Construct an ExpressionConceptFunctionParseTreeEvaluator for evaluating expressions that represent concept functions.- Parameters:
arguments
- A map of argument names to concept values.solverModel
- The ontology solver model that contains the scope of other concept functions that can be called in the expression.domainOntologies
- Ontologies over which the parser is defined.outputRangeOntology
- The ontology that represents the concept range for the concept function.- Throws:
IllegalActionException
- If there is a problem instantiating the parse tree evaluator object.
-
-
Method Detail
-
evaluateParseTree
public ConceptToken evaluateParseTree(ASTPtRootNode node) throws IllegalActionException
Evaluate the parse tree for the expression concept function with the specified root node.- Overrides:
evaluateParseTree
in classParseTreeEvaluator
- Parameters:
node
- The root of the parse tree.- Returns:
- The result of evaluation which must be a ConceptToken.
- Throws:
IllegalActionException
- If an evaluation error occurs.
-
evaluateParseTree
public ConceptToken evaluateParseTree(ASTPtRootNode node, ParserScope scope) throws IllegalActionException
Evaluate the parse tree for the expression concept function with the specified root node using the specified scope to resolve the values of variables.- Overrides:
evaluateParseTree
in classParseTreeEvaluator
- Parameters:
node
- The root of the parse tree.scope
- The scope for evaluation.- Returns:
- The result of evaluation which must be a ConceptToken.
- Throws:
IllegalActionException
- If an error occurs during evaluation or if the result is not a ConceptToken or an ObjectToken containing a Concept.
-
visitFunctionApplicationNode
public void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node) throws IllegalActionException
Evaluate a concept function contained in a concept function expression. The concept function must be defined in an attribute contained in the ontology solver model.- Specified by:
visitFunctionApplicationNode
in interfaceParseTreeVisitor
- Overrides:
visitFunctionApplicationNode
in classParseTreeEvaluator
- Parameters:
node
- The function expression node to be evaluated.- Throws:
IllegalActionException
- If the function cannot be parsed correctly.
-
visitLeafNode
public void visitLeafNode(ASTPtLeafNode node) throws IllegalActionException
Evaluate each leaf node in the parse tree to a concept string. Either replace an argument label from the concept function with its concept value string name or assume it is a concept name if it is not a function argument label.- Specified by:
visitLeafNode
in interfaceParseTreeVisitor
- Overrides:
visitLeafNode
in classParseTreeEvaluator
- Parameters:
node
- The leaf node to be visited.- Throws:
IllegalActionException
- If the node label cannot be resolved to a concept.
-
_getNamedConcept
protected Concept _getNamedConcept(java.lang.String conceptString) throws IllegalActionException
Return the concept with the specified string representation. If it cannot be found in any of the argument domain ontologies, throw an exception.- Parameters:
conceptString
- The specified string the concept should have.- Returns:
- The concept with the specified string if it is found.
- Throws:
IllegalActionException
- If the concept cannot be found.
-
_getNodeLabel
protected java.lang.String _getNodeLabel(ASTPtLeafNode node)
Return the label for the leaf node.- Parameters:
node
- The given leaf node- Returns:
- The string label for the node; If the node is constant this is the token contained in the node as a string, if not then this is the name of the node.
-
-