private List <M_Poem> ReadTangshiBook(string fileName, int bookNo) { using (StreamReader reader = new StreamReader(fileName, System.Text.Encoding.UTF8)) { string text = reader.ReadLine(); Regex regex = new Regex(@"卷(?<SecNo>[0-9]+)_(?<No>[0-9]+)\s*【(?<title>[^】]+)】(?<auth>[^\r]+)"); List <M_Poem> poems = new List <M_Poem>(); M_Poem poemItem = null; int sectNo = 0; int no = 0; string title = ""; string auth = ""; StringBuilder content = null; while (text != null) { if (regex.IsMatch(text)) { if (poemItem != null) { poemItem.MainBody = FormatPoemText(content.ToString()); poems.Add(poemItem); } Match m = regex.Match(text); sectNo = int.Parse(m.Groups["SecNo"].Value); no = int.Parse(m.Groups["No"].Value); title = m.Groups["title"].Value.Trim(); auth = m.Groups["auth"].Value.Trim(); content = new StringBuilder(); poemItem = new M_Poem() { BookNo = bookNo, SectionNo = sectNo, PoemNo = no, Title = title, Author = auth, Dynasty = "唐" }; } else { if (content != null) { content.AppendLine(text.Trim()); } } text = reader.ReadLine(); } //最後の内容 if (poemItem != null) { poemItem.MainBody = FormatPoemText(content.ToString()); poems.Add(poemItem); } return(poems); } }
public PoemItem(M_Poem poem) { this.ID = poem.ID; this.SubID = poem.PoemNo.HasValue? poem.PoemNo.Value:0; this.Title = poem.Title; this.Author = poem.Author; this.Dynasty = poem.Dynasty; this.Body = poem.MainBody; this.Cipai = poem.Cipai; this.TitleNode = poem.Foreword; this.Footer = poem.Comment; }
private void FormatCiPoemItem(M_Poem poem) { string poemText = FormatPoemText(poem.MainBody); string foreword = GetForeword(poemText); string mainBody = GetMainBody(poemText); if (string.IsNullOrWhiteSpace(poem.Title)) { poem.Title = GetFirstSentence(mainBody); } if (!string.IsNullOrWhiteSpace(foreword)) { poem.Foreword = foreword; } if (!string.IsNullOrWhiteSpace(mainBody)) { poem.MainBody = mainBody; } }
private List <M_Poem> ReadSongciBook(string fileName, int bookNo) { using (StreamReader reader = new StreamReader(fileName, System.Text.Encoding.UTF8)) { List <M_Poem> poems = new List <M_Poem>(); List <M_Author> Auths = LinqSqlHelp.GetAllAuthor(); List <M_Cipai> Cipais = LinqSqlHelp.GetAllCipai(); M_Poem poemItem = null; int sectNo = 0; int no = 0; string title = ""; string auth = ""; string cipai = ""; StringBuilder content = null; string text = reader.ReadLine(); while (text != null) { //作成者変更 string tempAuth; if (TryParseAuth(Auths, text, out tempAuth)) { sectNo++; if (poemItem != null) { poemItem.MainBody = FormatPoemText(content.ToString()); poemItem.Title = title; FormatCiPoemItem(poemItem); poems.Add(poemItem); } auth = tempAuth; poemItem = null; no = 0; text = reader.ReadLine(); continue; } string tempCipai; string tempTitle; if (TryParseCipai(Cipais, text, out tempCipai, out tempTitle)) { if (poemItem != null) { poemItem.MainBody = FormatPoemText(content.ToString()); FormatCiPoemItem(poemItem); poems.Add(poemItem); } no++; cipai = tempCipai; title = tempTitle; content = new StringBuilder(); poemItem = new M_Poem() { BookNo = bookNo, SectionNo = sectNo, PoemNo = no, Cipai = cipai, Title = title, Author = auth, Dynasty = "宋", PoemType = "词" }; } else { if (content != null) { content.AppendLine(text.Trim()); } } text = reader.ReadLine(); } //最後の内容 if (poemItem != null) { poemItem.MainBody = FormatPoemText(content.ToString()); poems.Add(poemItem); } return(poems); } }