/* A class representing a concept function that is defined by a boolean expression * of concepts specified in a ConceptFunctionDefinitionAttribute. * * Copyright (c) 2010-2014 The Regents of the University of California. All * rights reserved. Permission is hereby granted, without written agreement and * without license or royalty fees, to use, copy, modify, and distribute this * software and its documentation for any purpose, provided that the above * copyright notice and the following two paragraphs appear in all copies of * this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN * "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY */ package ptolemy.data.ontologies; import java.util.LinkedList; import java.util.List; import ptolemy.data.expr.ASTPtRootNode; import ptolemy.data.expr.PtParser; import ptolemy.kernel.util.IllegalActionException; import ptolemy.kernel.util.NamedObj; /////////////////////////////////////////////////////////////////// //// ExpressionConceptFunction /**
This is a class for concept functions that are used * specified using an expression from a ConceptFunctionDefinitionAttribute. * The expression is evaluated with the input arguments to evaluate the * concept function. * *
An expression that represents a concept function is a boolean if-then expression
* that has multiple conditional statements that specifies the output concept value
* based on the input concept valuesof the arguments. Example: consider a function
* that has two arguments arg1 and arg2, and each argument can be a concept from
* the DimensionSystem ontology which has the possible Concept values:
*
*
{Unknown, Dimensionless, Time, Position, Velocity, Acceleration, Conflict}
*
* A valid expression concept function could be defined like this:
*
* f(arg1, arg2) =
*
*
arg1 == Unknown || arg2 == Unknown ? Unknown :
*
arg1 == Position && arg2 == Time ? Velocity :
*
arg1 == Velocity && arg2 == Time ? Acceleration :
*
Conflict
*
This expression function specifies that the output of the function is Unknown
* if either argument is Unknown, Velocity if arg1 is Position and arg2 is Time,
* Acceleration if arg1 is Velocity and arg2 is Time, and Conflict if arg1 and
* arg2 are any other combination of concept values.
*
* @author Charles Shelton
* @version $Id: ExpressionConceptFunction.java 70398 2014-10-22 23:44:32Z cxh $
* @since Ptolemy II 10.0
* @Pt.ProposedRating Green (cshelton)
* @Pt.AcceptedRating Red (cshelton)
*/
public class ExpressionConceptFunction extends ConceptFunction {
/** Initialize the expression concept function with the number of
* arguments it takes, the ontologies from which input and output
* concepts can be taken, the name of the function, and the
* string boolean expression that defines the function.
* @param numArgsIsFixed True if the number of arguments for this function
* is fixed and cannot change, false otherwise.
* @param argumentDomainOntologies The array of ontologies that
* represent the concept domain for each input concept argument.
* @param outputRangeOntology The ontology that represents the
* range of output concepts for this concept function.
* @param name The string name used to identify this concept function.
* @param argumentNames The list of strings that represent the
* names of the arguments to be used in parsing the concept
* function expression.
* @param conceptFunctionExpression A string representing the
* boolean expression that defines the concept function.
* @param solverModel The ontology solver model that contains
* other concept function definitions that could be called by
* the function defined in this expression.
* @param functionScopeModelElement knk.
* @exception IllegalActionException If the ontology inputs are null
* or the length of the array of domain ontologies does not
* match the number of arguments for the function.
*/
public ExpressionConceptFunction(String name, boolean numArgsIsFixed,
List