예제 #1
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ValueExpression();

            result.Type          = CREFModel.ValueType.Boolean;
            result.TypeSpecified = true;

            result.Value = node.GetAttribute <string>("value"); // TODO: This assumes boolean representation will translate...

            return(result);
        }
예제 #2
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ValueExpression();

            result.Type          = CREFModel.ValueType.String;
            result.TypeSpecified = true;

            result.Value = node.GetAttribute <string>("value");

            return(result);
        }
예제 #3
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            // Physical quantity is not supported as a value type within CREF, so the literal will need to be transformed to a "unit normalized representation"
            var value = Convert.ToDecimal(node.GetAttribute <string>("value"));
            var unit  = node.GetAttribute <string>("unit");

            switch (unit)
            {
            case "1": break;                      // Do nothing, this is the unity unit in UCUM, value is unadjusted

            // Time units
            case "a": value *= 365.25m; break;    // Year, convert to days

            case "mo": value *= 30.4375m; break;  // Month, convert to days

            case "wk": value *= 7m; break;        // Week, convert to days

            case "d": break;                      // Day

            // These time units are not yet supported
            //"h" : break; // Hour
            //"min" : break; // Minute
            //"Ms" : break; // Megasecond
            //"ks" : break; // Kilosecond
            //"s" : break; // Second
            //"ms" : break; // Millisecond
            //"us" : break; // Microsecond
            //"ns" : break; // Nanosecond
            //"ps" : break; // Picosecond

            default: throw new NotSupportedException(String.Format("Physical quantity unit translation for unit type of '{0}' is not supported.", unit));
            }

            var result = new CREFModel.ValueExpression();

            result.Type          = CREFModel.ValueType.Decimal;
            result.TypeSpecified = true;

            result.Value = Convert.ToString(value);

            return(result);
        }
예제 #4
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ValueExpression();

            if (DataTypes.Equal(node.ResultType, DataTypes.String))
            {
                result.Type          = Model.ValueType.String;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.Integer))
            {
                result.Type          = Model.ValueType.Int32;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.Boolean))
            {
                result.Type          = Model.ValueType.Boolean;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.Decimal))
            {
                result.Type          = Model.ValueType.Decimal;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.DateTime))
            {
                result.Type          = Model.ValueType.Date;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");        // TODO: Convert to format expected by CREF
            }
            else
            {
                throw new NotSupportedException(String.Format("Unsupported literal type: {0}.", node.ResultType.Name));
            }

            return(result);
        }
예제 #5
0
		public object Translate(TranslationContext context, ASTNode node)
		{
			var result = new CREFModel.ValueExpression();

			if (DataTypes.Equal(node.ResultType, DataTypes.String))
			{
				result.Type = Model.ValueType.String;
				result.TypeSpecified = true;
				result.Value = node.GetAttribute<string>("value");
			}
			else if (DataTypes.Equal(node.ResultType, DataTypes.Integer))
			{
				result.Type = Model.ValueType.Int32;
				result.TypeSpecified = true;
				result.Value = node.GetAttribute<string>("value");
			}
			else if (DataTypes.Equal(node.ResultType, DataTypes.Boolean))
			{
				result.Type = Model.ValueType.Boolean;
				result.TypeSpecified = true;
				result.Value = node.GetAttribute<string>("value");
			}
			else if (DataTypes.Equal(node.ResultType, DataTypes.Decimal))
			{
				result.Type = Model.ValueType.Decimal;
				result.TypeSpecified = true;
				result.Value = node.GetAttribute<string>("value");
			}
			else if (DataTypes.Equal(node.ResultType, DataTypes.DateTime))
			{
				result.Type = Model.ValueType.Date;
				result.TypeSpecified = true;
				result.Value = node.GetAttribute<string>("value"); // TODO: Convert to format expected by CREF
			}
			else
			{
				throw new NotSupportedException(String.Format("Unsupported literal type: {0}.", node.ResultType.Name));
			}

			return result;
		}
		protected object GetCalculateAgeExpression(TranslationContext context, object result)
		{
			var calculateAge = new CREFModel.CalculateAge();

			calculateAge.Items.Add(result);

			var binaryExpression = new CREFModel.BinaryExpression();

			// Returns as years, so multiply by days/year to get consistent results with the physical quantity translator
			binaryExpression.Operator = CREFModel.BinaryOperator.opMultiply;
			binaryExpression.OperatorSpecified = true;
			binaryExpression.Items.Add(calculateAge);

			var multiplier = new CREFModel.ValueExpression();
			multiplier.Type = CREFModel.ValueType.Decimal;
			multiplier.TypeSpecified = true;
			multiplier.Value = Convert.ToString(365.25m);

			binaryExpression.Items.Add(multiplier);

			return binaryExpression;
		}
예제 #7
0
        protected object GetCalculateAgeExpression(TranslationContext context, object result)
        {
            var calculateAge = new CREFModel.CalculateAge();

            calculateAge.Items.Add(result);

            var binaryExpression = new CREFModel.BinaryExpression();

            // Returns as years, so multiply by days/year to get consistent results with the physical quantity translator
            binaryExpression.Operator          = CREFModel.BinaryOperator.opMultiply;
            binaryExpression.OperatorSpecified = true;
            binaryExpression.Items.Add(calculateAge);

            var multiplier = new CREFModel.ValueExpression();

            multiplier.Type          = CREFModel.ValueType.Decimal;
            multiplier.TypeSpecified = true;
            multiplier.Value         = Convert.ToString(365.25m);

            binaryExpression.Items.Add(multiplier);

            return(binaryExpression);
        }
예제 #8
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ValueExpression();

            result.Type = CREFModel.ValueType.Boolean;
            result.TypeSpecified = true;

            result.Value = node.GetAttribute<string>("value"); // TODO: This assumes boolean representation will translate...

            return result;
        }
예제 #9
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ValueExpression();

            result.Type = CREFModel.ValueType.String;
            result.TypeSpecified = true;

            result.Value = node.GetAttribute<string>("value");

            return result;
        }
예제 #10
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            // Physical quantity is not supported as a value type within CREF, so the literal will need to be transformed to a "unit normalized representation"
            var value = Convert.ToDecimal(node.GetAttribute<string>("value"));
            var unit = node.GetAttribute<string>("unit");

            switch (unit)
            {
                case "1" : break; // Do nothing, this is the unity unit in UCUM, value is unadjusted

                // Time units
                case "a" : value *= 365.25m; break; // Year, convert to days
                case "mo" : value *= 30.4375m; break; // Month, convert to days
                case "wk" : value *= 7m; break; // Week, convert to days
                case "d" : break; // Day

                // These time units are not yet supported
                //"h" : break; // Hour
                //"min" : break; // Minute
                //"Ms" : break; // Megasecond
                //"ks" : break; // Kilosecond
                //"s" : break; // Second
                //"ms" : break; // Millisecond
                //"us" : break; // Microsecond
                //"ns" : break; // Nanosecond
                //"ps" : break; // Picosecond

                default : throw new NotSupportedException(String.Format("Physical quantity unit translation for unit type of '{0}' is not supported.", unit));
            }

            var result = new CREFModel.ValueExpression();

            result.Type = CREFModel.ValueType.Decimal;
            result.TypeSpecified = true;

            result.Value = Convert.ToString(value);

            return result;
        }