private void ProcessQuestion(Parser.ParserResult result, ProcessingResult conversionResult) { conversionResult.Units = result.Tokens.Where(s => UnitsMapping.ContainsKey(s)).ToList(); conversionResult.MetalName = result.Tokens.Except(conversionResult.Units).FirstOrDefault(); if (conversionResult.Units.Count == 0) { conversionResult.ResultType = Parser.ResultType.Unknown; return; } conversionResult.ConvertedValue = GetEquivalentNumber(conversionResult.Units); if (conversionResult.ConvertedValue == -1) { conversionResult.ResultType = Parser.ResultType.Unknown; return; } if (conversionResult.MetalName != null) { if (MetalPriceMapping.ContainsKey(conversionResult.MetalName)) { conversionResult.ConvertedValue *= MetalPriceMapping[conversionResult.MetalName]; } else { conversionResult.ResultType = Parser.ResultType.Unknown; } } }
private void AddMetalInformationInDictionary(Parser.ParserResult result, ProcessingResult conversionResult) { var units = result.Tokens.Where(s => UnitsMapping.ContainsKey(s)).ToList(); var metalInfo = result.Tokens.Except(units).ToList(); // Get remaining info. if (metalInfo.Count != 2) { conversionResult.ResultType = Parser.ResultType.Unknown; return; } long romanEquivalentNumber = GetEquivalentNumber(units); if (romanEquivalentNumber == -1) { conversionResult.ResultType = Parser.ResultType.Unknown; return; } var metalName = metalInfo.First(); var metalCredits = Decimal.Parse(metalInfo.Last()); // Get the credit for each unit. var creditsPerUnit = metalCredits / romanEquivalentNumber; if (!MetalPriceMapping.ContainsKey(metalName)) { MetalPriceMapping.Add(metalName, creditsPerUnit); } else { MetalPriceMapping[metalName] = creditsPerUnit; } }
private void AddUnitInformationInDictionary(Parser.ParserResult result, ProcessingResult conversionResult) { // Add token information. var intergalacticUnit = result.Tokens.First(); var romanEquivalentSymbol = result.Tokens.Last().First(); // get the first character. var validRomanSymbols = RomanNumeralConverter.GetValidSymbols(); if (!validRomanSymbols.Contains(romanEquivalentSymbol)) { conversionResult.ResultType = Parser.ResultType.Unknown; return; } if (!UnitsMapping.ContainsKey(intergalacticUnit)) { UnitsMapping.Add(intergalacticUnit, romanEquivalentSymbol); // Add units mapping. } else { UnitsMapping[intergalacticUnit] = romanEquivalentSymbol; } }