Ejemplo n.º 1
0
        private bool IsTitle(string lastQuestionHeader, ParagraphPart paragraph, double maxTextSize, double avgTextSize)
        {
            if (!paragraph.Parts.Any())
            {
                return(false);
            }

            var isUnderlined = paragraph.Parts[0] is TextPart textPart2 && textPart2.Style.IsUnderlined == true;
            var isRealCenter = paragraph.Style.Justification == Justification.Center;
            var isCenter     = isRealCenter ||
                               (!isUnderlined && paragraph.Content.Length - paragraph.Content.TrimStart().Length > 2);
            var isBold = paragraph.Parts[0] is TextPart textPart && textPart.Style.IsBold == true;
            var isTextSizeLargeEnough = maxTextSize - paragraph.GetAverageTextSize() <= 4;
            var isTextLargerThanAvg   = paragraph.GetAverageTextSize() > avgTextSize;

            var sentences = paragraph.Content.Trim().Split(new char[] { ',', ',', '。', '.' }, StringSplitOptions.RemoveEmptyEntries);
            var isPoem    = (sentences.Length == 2 && sentences[0].Length == sentences[1].Length) ||
                            _poemQuestionRegex.IsMatch(lastQuestionHeader);

            if (isPoem)
            {
                return(false);
            }

            return(((isRealCenter || isBold) && isTextSizeLargeEnough && isTextLargerThanAvg) ||
                   (isCenter && isBold && isTextSizeLargeEnough) ||
                   (paragraph.Content.Contains("答案") && (isCenter || isBold)) ||
                   (isCenter &&
                    paragraph.Content.Trim().StartsWith("第") &&
                    paragraph.Content.Trim().Replace(" ", "").Length < 5));
        }
        public static ParagraphPart TrimStart(this ParagraphPart paragraphPart)
        {
            var parts   = new List <IPart>();
            var isStart = true;

            foreach (var part in paragraphPart.Parts)
            {
                if (part is TextPart textPart)
                {
                    if (string.IsNullOrWhiteSpace(textPart.Content))
                    {
                        if (isStart)
                        {
                            continue;
                        }
                    }
                    else if (isStart)
                    {
                        textPart.Content = textPart.Content.TrimStart();
                        isStart          = false;
                        parts.Add(textPart);
                        continue;
                    }
                }

                parts.Add(part);
            }

            paragraphPart.Parts = parts;
            return(paragraphPart);
        }
Ejemplo n.º 3
0
        private NumberNode?ExtractFromParagraph(ParagraphPart paragraph)
        {
            paragraph = paragraph.TrimStart();
            var content = paragraph.Content;
            var data    = new StringDataView(content);

            return(ExtractFromDataView(data, paragraph.Order));
        }
 public static double GetAverageTextSize(this ParagraphPart paragraphPart)
 {
     return(paragraphPart.Parts.Where(o => o is TextPart).Average(o => ((TextPart)o).Style.Size));
 }