private bool Compare(ByzVerseWordInfo viWord, TroVerseWordInfo tiWord)
        {
            var viWordTransliterit = viWord.Text.TransliterateAncientGreek().ToLower();
            var tiWordTransliterit = tiWord.Text.TransliterateAncientGreek().ToLower();

            if (viWordTransliterit.Equals(tiWordTransliterit))
            {
                return(true);
            }

            if ($"h{viWordTransliterit}".Equals(tiWordTransliterit))
            {
                return(true);
            }
            if (viWordTransliterit.Equals($"h{tiWordTransliterit}"))
            {
                return(true);
            }
            if (tiWordTransliterit.Length > 1 && viWordTransliterit.Equals($"hy{tiWordTransliterit.Substring(1)}"))
            {
                return(true);
            }

            // jeszcze trzeba opracować przypadek hymin / umin

            return(default);
Ejemplo n.º 2
0
        public TroVerseInfo(int book, int chapter, int verse, string data)
        {
            Words   = new List <TroVerseWordInfo>();
            Book    = book;
            Chapter = chapter;
            Verse   = verse;
            var xmlText           = $"<verse>{data}</verse>";
            var xml               = XElement.Parse(xmlText);
            TroVerseWordInfo word = null;

            var wordIndex = 1;

            foreach (var node in xml.Nodes())
            {
                if (node.NodeType == System.Xml.XmlNodeType.Text)
                {
                    if (!String.IsNullOrEmpty((node as XText).Value))
                    {
                        var text = (node as XText).Value;
                        if (text.Contains("–"))
                        {
                            text = text.Substring(0, text.IndexOf('–') - 1).Trim();
                        }
                        word.Translation = text.RemoveAny(".", ":", ",", ";", "·", "—", "-", ")", "(", "]", "[", "’", ";").Trim();
                    }
                }
                else if (node is XElement)
                {
                    XElement el = node as XElement;
                    if (el.Name.LocalName == "e")
                    {
                        word = new TroVerseWordInfo()
                        {
                            Text          = el.Value.Trim(),
                            WordIndex     = wordIndex,
                            Transliterit2 = el.Value.Trim().TransliterateAncientGreek().ToLower()
                        };
                        Words.Add(word);
                        wordIndex++;
                    }
                    else if (el.Name.LocalName == "n")
                    {
                        word.Transliterit = el.Value.Trim();
                    }
                    else if (el.Name.LocalName == "S")
                    {
                        var code = Convert.ToInt32(el.Value.Trim());
                        word.StrongCode = code;
                    }
                    else if (el.Name.LocalName == "m")
                    {
                        word.GrammarCode = el.Value;
                    }
                }
            }
        }
        public void Build(UnitOfWork uow, string byzPath, string troPath, string pbpwPath)
        {
            var byzConnection  = GetConnection(byzPath);
            var troConnection  = GetConnection(troPath);
            var pbpwConnection = GetConnection(pbpwPath);

            var translation = CreateTranslation(uow);

            TroVerses    = GetTroVerseInfos(troConnection);
            ByzVerses    = GetByzVerses(byzConnection);
            PbpwVerses   = GetPbpwVerseInfos(pbpwConnection);
            Strongs      = new XPQuery <StrongCode>(uow).Where(x => x.Lang == Language.Greek);
            BaseBooks    = new XPQuery <BookBase>(uow).Where(x => x.Status.BiblePart == BiblePart.NewTestament).OrderBy(x => x.NumberOfBook);
            GrammarCodes = new XPQuery <GrammarCode>(uow).OrderBy(x => x.GrammarCodeVariant1);

            foreach (var baseBook in BaseBooks)
            {
                var chapterCount = ByzVerses.Where(x => x.Book == baseBook.NumberOfBook)
                                   .Max(x => x.Chapter);
                Book book = null;
                if (book.IsNull())
                {
                    book = new Book(uow)
                    {
                        BaseBook          = baseBook,
                        BookName          = baseBook.BookName,
                        BookShortcut      = baseBook.BookShortcut,
                        Color             = baseBook.Color,
                        NumberOfBook      = baseBook.NumberOfBook,
                        NumberOfChapters  = chapterCount,
                        ParentTranslation = translation
                    };
                    book.Save();
                    uow.CommitChanges();
                    uow.ReloadChangedObjects();

#if DEBUG
                    System.Diagnostics.Debug.WriteLine("-----------------------------------------------");
                    System.Diagnostics.Debug.Write($"{baseBook.BookTitle}");
#endif
                }

                for (int chapterIndex = 1; chapterIndex <= chapterCount; chapterIndex++)
                {
                    var versesCount = ByzVerses.Where(x => x.Book == baseBook.NumberOfBook &&
                                                      x.Chapter == chapterIndex)
                                      .Max(x => x.Verse);
                    Chapter chapter = null;
                    if (chapter.IsNull())
                    {
                        chapter = new Chapter(uow)
                        {
                            NumberOfChapter = chapterIndex,
                            NumberOfVerses  = versesCount,
                            ParentBook      = book
                        };
                        chapter.Save();
                        uow.CommitChanges();
                        uow.ReloadChangedObjects();
#if DEBUG
                        System.Diagnostics.Debug.WriteLine("");
                        System.Diagnostics.Debug.Write($"Rozdział {chapterIndex}");
#endif
                    }
                    for (int verseIndex = 1; verseIndex <= versesCount; verseIndex++)
                    {
                        Verse verse = null;
                        if (verse.IsNull())
                        {
                            var pbpwVerse = PbpwVerses.Where(x => x.Book == baseBook.NumberOfBook &&
                                                             x.Chapter == chapterIndex &&
                                                             x.Verse == verseIndex).FirstOrDefault();
                            verse = new Verse(uow)
                            {
                                NumberOfVerse = verseIndex,
                                ParentChapter = chapter,
                                Text          = pbpwVerse.IsNotNull() ? pbpwVerse.VerseText : String.Empty
                            };
                            verse.Save();
                            uow.CommitChanges();
                            uow.ReloadChangedObjects();
#if DEBUG
                            System.Diagnostics.Debug.WriteLine("");
                            System.Diagnostics.Debug.Write($"{verseIndex}. ");
#endif
                        }

                        var vi = ByzVerses.Where(x => x.Book == baseBook.NumberOfBook &&
                                                 x.Chapter == chapterIndex &&
                                                 x.Verse == verseIndex).FirstOrDefault();
                        if (vi.IsNotNull())
                        {
                            var ti = GetTroVerseInfo(vi);
                            if (ti.IsNotNull())
                            {
                                var wordIndex = 1;
                                foreach (var viWord in vi.Words)
                                {
                                    var tiWord = ti.Words.Where(x => x.WordIndex == viWord.WordIndex).FirstOrDefault();
                                    if (tiWord.IsNotNull())
                                    {
                                        if (tiWord.StrongCode != viWord.StrongCode)
                                        {
                                            // może kod się różni ale dla pewności porównam transliterację
                                            if (!Compare(viWord, tiWord))
                                            {
                                                // tu trzeba sprawdzić czy to słowo nie występuje gdzieś dalej
                                                // wówczas trzeba przetłumaczyć słowa w oparciu o wcześniej
                                                // zbudowany słownik aż do wystąpienia tego słowa w tekście
                                                // TRO



                                                tiWord = ti.Words.Where(x => x.StrongCode == viWord.StrongCode &&
                                                                        x.GrammarCode != null &&
                                                                        x.GrammarCode.Contains(viWord.GrammarCode) &&
                                                                        x.WordIndex >= viWord.WordIndex).FirstOrDefault();
                                                if (tiWord.IsNull())
                                                {
                                                    tiWord = ti.Words.Where(x => x.StrongCode == viWord.StrongCode &&
                                                                            x.GrammarCode != null &&
                                                                            x.GrammarCode.Contains(viWord.GrammarCode)).FirstOrDefault();
                                                }

                                                if (tiWord.IsNull())
                                                {
                                                    tiWord = new TroVerseWordInfo()
                                                    {
                                                        GrammarCode  = viWord.GrammarCode,
                                                        Text         = viWord.Text,
                                                        StrongCode   = viWord.StrongCode,
                                                        Translation  = viWord.Text.TransliterateAncientGreek(),
                                                        Transliterit = viWord.Text.TransliterateAncientGreek(),
                                                        WordIndex    = viWord.WordIndex
                                                    };
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        tiWord = new TroVerseWordInfo()
                                        {
                                            GrammarCode  = viWord.GrammarCode,
                                            Text         = viWord.Text,
                                            StrongCode   = viWord.StrongCode,
                                            Translation  = EMPTY_TRANSLATION,
                                            Transliterit = viWord.Text.TransliterateAncientGreek(),
                                            WordIndex    = viWord.WordIndex
                                        };
                                    }

                                    VerseWord word = null;
                                    if (word.IsNull())
                                    {
                                        word = new VerseWord(uow)
                                        {
                                            GrammarCode       = GetGrammarCode(uow, viWord.GrammarCode, tiWord.IsNotNull() ? tiWord.GrammarCode : null),
                                            StrongCode        = GetStrongCode(viWord.StrongCode),
                                            NumberOfVerseWord = wordIndex,
                                            ParentVerse       = verse,
                                            SourceWord        = viWord.Text,
                                            Translation       = tiWord.IsNotNull() ? tiWord.Translation : String.Empty,
                                            Transliteration   = tiWord.IsNotNull() ? tiWord.Transliterit : viWord.Text.TransliterateAncientGreek()
                                        };
                                        word.Save();
                                        uow.CommitChanges();
                                        uow.ReloadChangedObjects();

#if DEBUG
                                        System.Diagnostics.Debug.Write($"{word.Translation} ");
#endif
                                    }
                                    wordIndex++;
                                }
                            }
                        }
                    }
                }
            }
        }