Example #1
0
        public object Clone()
        {
            SettingAmount clone = new SettingAmount
            {
                Amount = Amount,
                Unit   = Unit
            };

            return(clone);
        }
Example #2
0
        /// <summary>
        /// If we have an amount then perform normalization.
        /// </summary>
        /// <param name="state">State.</param>
        /// <param name="change_sign_of_amount">Indicate whether to change sign on amount.</param>
        /// <returns>SettingAmount and relative indication.</returns>
        private (SettingAmount amount, bool isRelative) OptionalAmount(AutomotiveSkillState state, bool change_sign_of_amount)
        {
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            SettingAmount optional_amount = null;
            bool          isRelative      = false;

            if (state.Entities.TryGetValue("AMOUNT", out var amountEntityValues))
            {
                foreach (var amount_entity_value in amountEntityValues)
                {
                    var normalized_amount = this.amountNormalizer.NormalizeOrNull(amount_entity_value);
                    if (normalized_amount != null)
                    {
                        optional_amount = new SettingAmount
                        {
                            Unit = "%"
                        };

                        if ("+-".Equals(normalized_amount))
                        {
                            if (change_sign_of_amount)
                            {
                                optional_amount.Amount = 0.0;
                            }
                            else
                            {
                                optional_amount.Amount = 100.0;
                            }
                        }
                        else
                        {
                            optional_amount.Amount = double.Parse(normalized_amount, CultureInfo.InvariantCulture);
                        }
                    }
                    else
                    {
                        foreach (var chunk in this.numberNormalizer.SplitNumbers(amount_entity_value))
                        {
                            if (chunk.NumericValue != null)
                            {
                                optional_amount        = new SettingAmount();
                                optional_amount.Amount = chunk.NumericValue.Value;

                                // Deal with ASR error that transcribes "to 24" as "224"
                                if (!state.Entities.ContainsKey("TYPE") && ToAs2Pattern.Match(amount_entity_value).Success)
                                {
                                    optional_amount.Amount = optional_amount.Amount - 200;
                                    isRelative             = false;
                                }

                                break;
                            }
                        }
                    }

                    if (optional_amount != null)
                    {
                        if (state.Entities.TryGetValue("TYPE", out var typeEntityValues))
                        {
                            foreach (var typeEntityValue in typeEntityValues)
                            {
                                var normalized_type = this.typeNormalizer.NormalizeOrNull(typeEntityValue);
                                if (normalized_type != null)
                                {
                                    isRelative = "DELTA".Equals(normalized_type);
                                    break;
                                }
                            }
                        }

                        if (string.IsNullOrEmpty(optional_amount.Unit) && state.Entities.TryGetValue("UNIT", out var unitEntityValues))
                        {
                            foreach (var unitEntityValue in unitEntityValues)
                            {
                                var normalized_unit = this.unitNormalizer.NormalizeOrNull(unitEntityValue);
                                if (normalized_unit != null)
                                {
                                    optional_amount.Unit = normalized_unit;
                                }
                                else
                                {
                                    optional_amount.Unit = unitEntityValue;
                                }

                                break;
                            }
                        }

                        break;
                    }
                }
            }

            if (change_sign_of_amount && optional_amount != null && isRelative)
            {
                optional_amount.Amount = -optional_amount.Amount;
            }

            return(optional_amount, isRelative);
        }