public static Bible Run() { Bible bible = new Bible("English"); XDocument doc = XDocument.Load("ESV.xml"); var bookElements = doc.Root.Elements("b"); for (int i = 1; i < bookElements.Count() + 1; i++) { var bookElement = bookElements.ElementAt(i - 1); string bookName = bookElement.Attribute("n").Value; Book book = new Book(i, bookName); bible.Books.Add(book); foreach (var chapterElement in bookElement.Elements("c")) { int chapterId = Int32.Parse(chapterElement.Attribute("n").Value); Chapter chapter = new Chapter(chapterId); book.Chapters.Add(chapter); foreach (var verseElement in chapterElement.Elements("v")) { int verseId = Int32.Parse(verseElement.Attribute("n").Value); string text = verseElement.Value; Verse verse = new Verse(verseId, text); chapter.Verses.Add(verse); } } } return bible; }
public void Compare(Bible bible2) { if (this.Books.Count != bible2.Books.Count) { Log.Info(string.Format("Books: {0} vs {1}", this.Books.Count, bible2.Books.Count)); } for (int i = 0; i < this.Books.Count; i++) { var book1 = this.Books[i]; var book2 = bible2.Books[i]; if (book1.Chapters.Count != book2.Chapters.Count) { Log.Info(string.Format("Chapters: {0} vs {1} in Book {2}", book1.Chapters.Count, book2.Chapters.Count, book1.Id)); } for (int j = 0; j < book1.Chapters.Count; j++) { var chapter1 = book1.Chapters[j]; var chapter2 = book2.Chapters[j]; if (chapter1.Verses.Count != chapter2.Verses.Count) { Log.Info(string.Format("Verses: {0} vs {1} in Book {2}, Chapter {3}", chapter1.Verses.Count, chapter2.Verses.Count, book1.Id, chapter1.Id)); } for (int k = 0; k < chapter1.Verses.Count; k++) { var verse1 = chapter1.Verses[k]; if (string.IsNullOrEmpty(verse1.Text)) { Log.Info(string.Format("Empty verses in Bible 1, Book {0}, Chapter {1}, Verse {2}", book1.Id, chapter1.Id, verse1.Id)); } if (k < chapter2.Verses.Count) { var verse2 = chapter2.Verses[k]; if (string.IsNullOrEmpty(verse2.Text)) { Log.Info(string.Format("Empty verses in Bible 2, Book {0}, Chapter {1}, Verse {2}", book2.Id, chapter2.Id, verse2.Id)); } } } } } }
public static Bible Run() { Bible bible = new Bible("മലയാളം"); Regex regex = new Regex(@"{{verse\|(\d+)}}\s(.*)"); foreach (var pair in _books) { int bookId = pair.Key; string name = pair.Value; int numberOfChapters = Book.ChaptersPerBook[bookId]; Book book = new Book(bookId, name); bible.Books.Add(book); Log.Info("Book " + bookId); for (int i = 1; i < numberOfChapters + 1; i++) { Log.Info(string.Format("Chapter {0}/{1}", i, numberOfChapters)); Chapter chapter = new Chapter(i); book.Chapters.Add(chapter); string url = string.Format("http://malayalambible.in/wiki/{0}:{1}.htm", bookId, i); string page = Web.GetPage(url); string[] lines = page.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < lines.Length; j++) { string line = lines[j]; Match match = regex.Match(line); if (match.Success) { int verseId = Int32.Parse(match.Groups[1].Value); string text = match.Groups[2].Value.Trim(); Verse verse = new Verse(verseId, text); chapter.Verses.Add(verse); } } } } return bible; }
public static Bible Run() { Bible bible = new Bible("हिन्दी बाइबिल"); Regex regex = new Regex(@"<p><a>.*(\d+)</a><p>"); foreach (var tuple in _books) { int bookId = tuple.Item1; string url = tuple.Item2; string name = tuple.Item3; Book book = new Book(bookId, name); bible.Books.Add(book); string page = Web.GetPage(url); string[] lines = page.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; Match match = regex.Match(line); if (match.Success) { int chapterId = Int32.Parse(match.Groups[1].Value); Chapter chapter = new Chapter(chapterId); book.Chapters.Add(chapter); // Next line is the verses i++; string versesLine = lines[i]; string[] versesSplit = versesLine.Split(new string[] { "<b>", "</b>" }, StringSplitOptions.RemoveEmptyEntries); var verses = versesSplit.Slice(2) .Select(slice => new Verse(Int32.Parse(slice.ElementAt(0)), slice.ElementAt(1).Trim())); chapter.Verses.AddRange(verses); } } } return bible; }
public GenerateHtml(Bible english, Bible malayalam, Bible hindi) { _english = english; _malayalam = malayalam; _hindi = hindi; }