private ParagraphFormatException?CheckLastChoiceContent(NumberNode node)
        {
            if (node.Children.Any())
            {
                var lastChoiceContent = NodeHelper.ConcatNodeContent(node.Children.Last(), false);
                if (lastChoiceContent.Length > 200)
                {
                    return(new NumberException(
                               "选项内容过长,可能是中间缺少了题号,以致未能正确分割",
                               string.Join(" ", NumberNodeHelper.GetNumberChain(node)),
                               lastChoiceContent));
                }
            }

            return(null);
        }
Пример #2
0
        private NumberNode?ConsumeNumberFromDataView(ref IDataView data, int paragraphOrder)
        {
            var backup = _numberManager.Save();
            InvalidNumberException?exception = null;

            foreach (var result in _decoratedNumberParser.Consume(data))
            {
                if (result.Result.Number.IntNumber > 50)
                {
                    continue;
                }

                try
                {
                    var node = _numberManager.AddNumber(result.Result, paragraphOrder);
                    data      = result.DataView;
                    exception = null;
                    return(node);
                }
                catch (ReadingParagraphNumberException)
                {
                    _numberManager.Load(backup);
                }
                catch (InvalidNumberException e)
                {
                    exception = e;
                    _numberManager.Load(backup);
                }
            }

            if (exception != null)
            {
                var p = _numberManager.Current;
                if (p == null)
                {
                    throw new NumberException(exception.Message, $"Paragraph {paragraphOrder}", data.CurrentView.ToString());
                }

                var chain = NumberNodeHelper.GetNumberChain(p);
                throw new NumberException(exception.Message, string.Join(" ", chain), data.CurrentView.ToString());
            }

            return(null);
        }
Пример #3
0
        protected override bool NumberNodeVisitor_OnVisited(NumberNode node, int level, out List <ParagraphFormatException> exceptions)
        {
            exceptions = new List <ParagraphFormatException>();

            var m = _childScoreRegex.Match(node.Header);

            if (m.Success)
            {
                var score = double.Parse(m.Groups["score"].Value);
                foreach (var child in node.Children)
                {
                    child.Score = score;
                }
            }

            m = _sumScoreRegex.Match(node.Header);
            if (m.Success)
            {
                var score = double.Parse(m.Groups["score"].Value);
                node.Score = score;
            }
            else
            {
                m = _currentScoreRegex.Match(node.Header);
                if (m.Success)
                {
                    if (!double.TryParse(m.Groups["score"].Value, out var score))
                    {
                        exceptions.Add(
                            new NumberException(
                                $"遇到 \"{m.Groups["score"].Value}\",应为数字",
                                string.Join(" ", NumberNodeHelper.GetNumberChain(node)),
                                node.Header));
                    }

                    node.Score = score;
                }
            }

            return(true);
        }