public VERS GetVerse(ModuleVersePointer versePointer, string moduleShortName, bool getVerseNumberForEmptyVerses, out VerseIndex verseIndex, out bool isPartOfBigVerse) { isPartOfBigVerse = false; verseIndex = new VerseIndex(versePointer.Verse, versePointer.TopVerse); if (_versesDictionary == null) { LoadVersesDictionary(versePointer, moduleShortName); } if (_versesDictionary.TryGetValue(versePointer.VerseNumber.Verse, out VERS result)) { verseIndex = result.VerseIndex; isPartOfBigVerse = verseIndex.IsSeveralVerses; } else { result = Verses.FirstOrDefault(v => v.IsMultiVerse && (v.Index <= versePointer.VerseNumber.Verse && versePointer.VerseNumber.Verse <= v.TopIndex)); if (result != null) { if (getVerseNumberForEmptyVerses) { verseIndex = result.VerseIndex; } isPartOfBigVerse = true; result = VERS.Empty; // так как стих является частью бОльшего стиха } } return(result); }
private void JoinBaseAndParallelVerses(ModuleVersePointer versesKey, ComparisonVersesInfo baseVerses, ComparisonVersesInfo parallelVerses, ModuleVersePointersComparisonTable bookVersePointersComparisonTables) { if (baseVerses.Count == 1) { if (parallelVerses.Count == 1 && baseVerses[0].PartIndex.GetValueOrDefault(-1) == parallelVerses[0].PartIndex.GetValueOrDefault(-1)) { var baseVerseToAdd = (ModuleVersePointer)baseVerses[0].Clone(); var parallelVerseToAdd = (ModuleVersePointer)parallelVerses[0].Clone(); baseVerseToAdd.PartIndex = null; parallelVerseToAdd.PartIndex = null; if (!bookVersePointersComparisonTables.ContainsKey(baseVerseToAdd)) { bookVersePointersComparisonTables.Add(baseVerseToAdd, ComparisonVersesInfo.FromVersePointer(parallelVerseToAdd)); } } else { bookVersePointersComparisonTables.Add(baseVerses[0], parallelVerses); } } else { var notApocryphaBaseVerses = baseVerses.Where(v => !v.IsApocrypha); var notApocryphaParallelVerses = parallelVerses.Where(v => !v.IsApocrypha); bool isPartVersePointer = notApocryphaParallelVerses.Count() < notApocryphaBaseVerses.Count(); int parallelVerseIndex = 0; List <ModuleVersePointer> prevParallelVerses = new List <ModuleVersePointer>(); for (int baseVerseIndex = 0; baseVerseIndex < baseVerses.Count; baseVerseIndex++) { var baseVerse = baseVerses[baseVerseIndex]; var nextBaseVerse = baseVerseIndex < baseVerses.Count - 1 ? baseVerses[baseVerseIndex + 1] : null; var getAllVerses = nextBaseVerse == null ? GetAllVersesType.All : (nextBaseVerse.IsApocrypha != baseVerse.IsApocrypha ? GetAllVersesType.AllOfTheSameType : GetAllVersesType.One); prevParallelVerses = GetParallelVersesList(baseVerse, parallelVerses, ref parallelVerseIndex, getAllVerses, isPartVersePointer, prevParallelVerses); ComparisonVersesInfo parallelVersesInfo = new ComparisonVersesInfo(prevParallelVerses); //parallelVersesInfo.Strict = parallelVerses.Strict; bookVersePointersComparisonTables.Add(baseVerse, parallelVersesInfo); } } }
/// <summary> /// You should be careful after call this method: versePointer can be in inconsistent state - IsMultiVerse and TopVerseNumber can return not actual information. /// </summary> /// <param name="versePointer"></param> private void ExpandVerse(VersePointer versePointer, string moduleShortName) { var bibleContent = string.IsNullOrEmpty(moduleShortName) ? _applicationManager.CurrentBibleContent : _applicationManager.GetBibleContent(moduleShortName); var bookContent = bibleContent.BooksDictionary[versePointer.BookIndex]; for (var chapterIndex = versePointer.Chapter; chapterIndex <= versePointer.MostTopChapter; chapterIndex++) { if (bookContent.Chapters.Count < chapterIndex) { versePointer.SubVerses.NotFoundVerses.Add(new ModuleVersePointer(versePointer.BookIndex, chapterIndex)); break; } var chapterContent = bookContent.Chapters[chapterIndex - 1]; if ((versePointer.Chapter < chapterIndex || (versePointer.VerseNumber.IsChapter && versePointer.Chapter == chapterIndex)) && (!versePointer.TopVerseNumber.HasValue || (chapterIndex < versePointer.MostTopChapter || (versePointer.TopVerseNumber.Value.IsChapter && versePointer.MostTopChapter == chapterIndex)))) { versePointer.SubVerses.Verses.Add(new ModuleVersePointer(versePointer.BookIndex, chapterIndex)); versePointer.SubVerses.VersesCount += versePointer.IsChapter ? 1 : chapterContent.Verses.Count; } else { var startVerse = chapterIndex == versePointer.Chapter ? versePointer.Verse : 1; var endVerse = chapterIndex == versePointer.MostTopChapter ? versePointer.MostTopVerse : chapterContent.Verses.Count; for (var verseIndex = startVerse; verseIndex <= endVerse; verseIndex++) { var verse = new ModuleVersePointer(versePointer.BookIndex, chapterIndex, verseIndex); if (chapterContent.Verses.Count < verseIndex) { versePointer.SubVerses.NotFoundVerses.Add(verse); break; } versePointer.SubVerses.Verses.Add(verse); versePointer.SubVerses.VersesCount++; } } } }
public bool VerseExists(ModuleVersePointer vp, out VerseIndex verseIndex) { verseIndex = new VerseIndex(vp.Verse, vp.TopVerse); try { this.BooksDictionary[vp.BookIndex].GetVerseContent(vp, ModuleShortName, string.Empty, true, out verseIndex, out bool isEmpty, out bool isFullVerse, out bool isPartOfBigVerse, out bool hasValueEvenIfEmpty); return(true); } catch (VerseNotFoundException) { return(false); } catch (ChapterNotFoundException) { return(false); } }
public List <ModuleVersePointer> GetParallelVersePointer(ModuleVersePointer baseVersePointer, string parallelModuleShortName) { List <ModuleVersePointer> result = null; var parallelBibleInfo = GetParallelBibleInfo(parallelModuleShortName, _configurationManager.ModuleShortName); var parallelBookInfo = parallelBibleInfo[baseVersePointer.BookIndex]; if (parallelBookInfo != null && parallelBookInfo.TryGetValue(baseVersePointer, out ComparisonVersesInfo verseInfo)) { result = verseInfo; } else { result = new List <ModuleVersePointer>(1) { (ModuleVersePointer)baseVersePointer.Clone() } }; return(result); }
public List <ModuleVersePointer> GetParallelVerses(ModuleVersePointer baseVerse, ModuleVersePointer prevVerse) { var result = new List <ModuleVersePointer>(); if (IsEmpty) { result.Add(new ModuleVersePointer(baseVerse) { IsEmpty = true }); } else { var parallelVerses = VersesFormulaPart.CalculateParallelVerses(baseVerse.VerseNumber.Verse); if (!ValueVersesCount.HasValue && CorrespondenceType != BibleBookDifference.CorrespondenceVerseType.All) { ValueVersesCount = 1; } var versePartIndex = prevVerse != null?prevVerse.PartIndex.GetValueOrDefault(-1) + 1 : 0; var verseIndex = 0; foreach (var parallelVerse in parallelVerses) { var parallelVersePointer = new ModuleVersePointer( baseVerse.BookIndex, ChapterFormulaPart.CalculateParallelChapter(baseVerse.Chapter), parallelVerse); if (VersesFormulaPart.AllVersesArePart.GetValueOrDefault(false)) { parallelVersePointer.PartIndex = versePartIndex++; } if (!VerseIsValue(verseIndex, parallelVerses.Count)) { parallelVersePointer.IsApocrypha = true; } result.Add(parallelVersePointer); verseIndex++; } if (VersesFormulaPart.FirstVersePartIndex.HasValue) { result[0].PartIndex = VersesFormulaPart.FirstVersePartIndex; } if (VersesFormulaPart.LastVersePartIndex.HasValue) { result[result.Count - 1].PartIndex = VersesFormulaPart.LastVersePartIndex; } } if (this.SkipCheck) { result.ForEach(v => v.SkipCheck = SkipCheck); } if (this.EmptyVerseContent) { result.ForEach(v => v.EmptyVerseContent = EmptyVerseContent); } if (SecondFormula != null) { result.AddRange(SecondFormula.GetParallelVerses(baseVerse, prevVerse)); } return(result); }
/// <summary> /// /// </summary> /// <param name="versePointer"></param> /// <param name="moduleShortName"></param> /// <param name="strongPrefix"></param> /// <param name="getVerseNumberForEmptyVerses"></param> /// <param name="verseIndex"></param> /// <param name="isEmpty"></param> /// <param name="isFullVerse"></param> /// <param name="isPartOfBigVerse"></param> /// <param name="hasValueEvenIfEmpty">У нас есть стих в ibs (Лев 12:7). Ему по смыслу соответствуют два стиха из rst (Лев 12:7-8). Но поделить стих в ibs не поулчается, потому палочка стоит в конце стиха. Но это не значит, что воьсмой стих пустой!</param> /// <returns></returns> public string GetVerseContent(ModuleVersePointer versePointer, string moduleShortName, string strongPrefix, bool getVerseNumberForEmptyVerses, out VerseIndex verseIndex, out bool isEmpty, out bool isFullVerse, out bool isPartOfBigVerse, out bool hasValueEvenIfEmpty) { isFullVerse = true; isEmpty = false; isPartOfBigVerse = false; hasValueEvenIfEmpty = false; verseIndex = new VerseIndex(versePointer.Verse, versePointer.TopVerse); if (versePointer.IsEmpty) { isEmpty = true; return(null); } if (this.Chapters.Count < versePointer.Chapter) { throw new ChapterNotFoundException(versePointer, moduleShortName, BaseVersePointerException.Severity.Warning); } var chapter = this.Chapters[versePointer.Chapter - 1]; if (versePointer.VerseNumber.IsChapter) { return(string.Empty); } var verse = chapter.GetVerse(versePointer, moduleShortName, getVerseNumberForEmptyVerses, out verseIndex, out isPartOfBigVerse); if (verse == null) { throw new VerseNotFoundException(versePointer, moduleShortName, BaseVersePointerException.Severity.Warning); } if (verse.IsEmpty) { isEmpty = true; return(string.Empty); } string result = null; var verseContent = verse.GetValue(true, strongPrefix); var shelledVerseContent = ShellVerseText(verseContent); if (versePointer.PartIndex.HasValue) { var versesParts = verseContent.Split(new char[] { '|' }); if (versesParts.Length > versePointer.PartIndex.Value) { result = versesParts[versePointer.PartIndex.Value].Trim(); } if (result == SystemConstants.NotEmptyVerseContentSymbol) { hasValueEvenIfEmpty = true; } result = ShellVerseText(result); if (result != shelledVerseContent) { isFullVerse = false; } } else { if (verseContent == SystemConstants.NotEmptyVerseContentSymbol) // пока эту строчку не тестировал. Не понятно, можно ли такое использовать и зачем. { hasValueEvenIfEmpty = true; } result = shelledVerseContent; } return(result); }
private List <ModuleVersePointer> GetParallelVersesList(ModuleVersePointer baseVerse, ComparisonVersesInfo parallelVerses, ref int startIndex, GetAllVersesType getAllVerses, bool isPartParallelVersePointer, List <ModuleVersePointer> prevParallelVerses) { var result = new List <ModuleVersePointer>(); var lastIndex = startIndex; var lastPrevVerse = prevParallelVerses.Count > 0 ? prevParallelVerses.Last() : null; var partIndex = lastPrevVerse != null?lastPrevVerse.PartIndex.GetValueOrDefault(-1) + 1 : 0; bool getAllFirstOtherTypeVerses = startIndex == 0 && parallelVerses.Count > 0 && !baseVerse.IsApocrypha && parallelVerses[0].IsApocrypha; for (int i = startIndex; i < parallelVerses.Count; i++) { if (parallelVerses[i].IsApocrypha == baseVerse.IsApocrypha || getAllVerses == GetAllVersesType.All || getAllFirstOtherTypeVerses) { var parallelVerseToAdd = (ModuleVersePointer)parallelVerses[i].Clone(); if (!parallelVerseToAdd.IsApocrypha) { parallelVerseToAdd.PartIndex = (isPartParallelVersePointer && getAllVerses != GetAllVersesType.One) ? (int?)partIndex++ : parallelVerseToAdd.PartIndex; } else if (parallelVerseToAdd.PartIndex.HasValue) { throw new NotSupportedException(string.Format("Apocrypha part verses are not supported yet. Parallel verse is '{0}'.", parallelVerseToAdd)); } result.Add(parallelVerseToAdd); lastIndex = i + 1; } else { if (getAllVerses != GetAllVersesType.All && result.Count > 0) // то есть IsApocrypha сменилась { break; } if (getAllVerses == GetAllVersesType.AllOfTheSameType && startIndex == 0) // то есть сразу не то пошло { break; } } if (getAllVerses == GetAllVersesType.One && (!getAllFirstOtherTypeVerses || result.Any(v => v.IsApocrypha == baseVerse.IsApocrypha))) { break; } } startIndex = lastIndex; if (result.Count == 0) { ModuleVersePointer parallelVerseToAdd = null; if (!baseVerse.IsApocrypha) { if (lastPrevVerse != null) { if (!lastPrevVerse.PartIndex.HasValue) { lastPrevVerse.PartIndex = partIndex++; } parallelVerseToAdd = (ModuleVersePointer)lastPrevVerse.Clone(); parallelVerseToAdd.PartIndex = isPartParallelVersePointer ? (int?)partIndex++ : null; } else { throw new NotSupportedException(string.Format("Can not find parallel value verse for base verse '{0}'.", baseVerse)); } } else { parallelVerseToAdd = (ModuleVersePointer)baseVerse.Clone(); parallelVerseToAdd.IsEmpty = true; } result.Add(parallelVerseToAdd); } return(result); }