Manipulate information for standard chatper/verse schemes
Ejemplo n.º 1
0
        // Parse lines giving number of verses for each chapter like
        // GEN 1:10 2:23 ...
        private static void ParseMappingLine(string fileName, VersificationTable versification, string line)
        {
            try
            {
                string[] parts       = line.Split('=');
                string[] leftPieces  = parts[0].Trim().Split('-');
                string[] rightPieces = parts[1].Trim().Split('-');

                BCVRef left      = new BCVRef(leftPieces[0]);
                int    leftLimit = leftPieces.GetUpperBound(0) == 0 ? 0 : int.Parse(leftPieces[1]);

                BCVRef right = new BCVRef(rightPieces[0]);

                while (true)
                {
                    versification.toStandard[left.ToString()]    = right.ToString();
                    versification.fromStandard[right.ToString()] = left.ToString();

                    if (left.Verse >= leftLimit)
                    {
                        break;
                    }

                    left.Verse  = left.Verse + 1;
                    right.Verse = right.Verse + 1;
                }
            }
            catch
            {
                // ENHANCE: Make it so the TE version of Localizer can have its own resources for stuff
                // like this.
                throw new Exception("Invalid [" + line + "] " + fileName);
            }
        }
Ejemplo n.º 2
0
 public void GetLastChapterForBook()
 {
     Assert.AreEqual(2, VersificationTable.Get(ScrVers.English).LastChapter(
                         BCVRef.BookToNumber("HAG")));
     Assert.AreEqual(150, VersificationTable.Get(ScrVers.English).LastChapter(
                         BCVRef.BookToNumber("PSA")));
     Assert.AreEqual(0, VersificationTable.Get(ScrVers.English).LastChapter(-1));
 }
Ejemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Constructs and returns a new ScrReference representing Revelation 22:21 (or whatver
        /// the last verse is in Revelation for the current default versification scheme).
        /// </summary>
        /// <param name="versification">The versification scheme.</param>
        /// ------------------------------------------------------------------------------------
        public static ScrReference EndOfBible(ScrVers versification)
        {
            VersificationTable versificationTable = VersificationTable.Get(versification);
            int lastChapter = versificationTable.LastChapter(LastBook);

            return(new ScrReference(LastBook, lastChapter,
                                    versificationTable.LastVerse(LastBook, lastChapter), versification));
        }
Ejemplo n.º 4
0
 public void GetLastVerseForChapter()
 {
     Assert.AreEqual(20, VersificationTable.Get(ScrVers.English).LastVerse(
                         BCVRef.BookToNumber("PSA"), 9));
     Assert.AreEqual(39, VersificationTable.Get(ScrVers.Septuagint).LastVerse(
                         BCVRef.BookToNumber("PSA"), 9));
     Assert.AreEqual(1, VersificationTable.Get(ScrVers.English).LastVerse(
                         BCVRef.BookToNumber("PSA"), 0), "Intro chapter (0) should be treated as having 1 verse.");
     Assert.AreEqual(0, VersificationTable.Get(ScrVers.Septuagint).LastVerse(0, 0));
 }
Ejemplo n.º 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get the versification table for this versification
		/// </summary>
		/// <param name="vers"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public static VersificationTable Get(Paratext.ScrVers vers)
		{
			Debug.Assert(vers != Paratext.ScrVers.Unknown);

			if (versifications == null)
				versifications = new VersificationTable[versificationFiles.GetUpperBound(0)];

			// Read versification table if not already read
			if (versifications[(int)vers] == null)
			{
				versifications[(int)vers] = new VersificationTable(vers);
				ReadVersificationFile(FileName(vers), versifications[(int)vers]);
			}

			return versifications[(int)vers];
		}
Ejemplo n.º 6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Read versification file and "add" its entries.
		/// At the moment we only do this once. Eventually we will call this twice.
		/// Once for the standard versification, once for custom entries in versification.vrs
		/// file for this project.
		/// </summary>
		/// <param name="fileName"></param>
		/// <param name="versification"></param>
		/// ------------------------------------------------------------------------------------
		private static void ReadVersificationFile(string fileName, VersificationTable versification)
		{
			using (TextReader reader = new StreamReader(fileName))
			{
				for (string line = reader.ReadLine(); line != null; line = reader.ReadLine())
				{
					line = line.Trim();
					if (line == "" || line[0] == '#')
						continue;

					if (line.Contains("="))
						ParseMappingLine(fileName, versification, line);
					else
						ParseChapterVerseLine(fileName, versification, line);
				}
			}
		}
Ejemplo n.º 7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the versification table for this versification
        /// </summary>
        /// <param name="vers"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public static VersificationTable Get(Paratext.ScrVers vers)
        {
            Debug.Assert(vers != Paratext.ScrVers.Unknown);

            if (versifications == null)
            {
                versifications = new VersificationTable[versificationFiles.GetUpperBound(0)];
            }

            // Read versification table if not already read
            if (versifications[(int)vers] == null)
            {
                versifications[(int)vers] = new VersificationTable(vers);
                ReadVersificationFile(FileName(vers), versifications[(int)vers]);
            }

            return(versifications[(int)vers]);
        }
Ejemplo n.º 8
0
        // Parse lines mapping from this versification to standard versification
        // GEN 1:10	= GEN 2:11
        // GEN 1:10-13 = GEN 2:11-14
        private static void ParseChapterVerseLine(string fileName, VersificationTable versification, string line)
        {
            string[] parts   = line.Split(' ');
            int      bookNum = BCVRef.BookToNumber(parts[0]);

            if (bookNum == -1)
            {
                return;                 // Deuterocanonical books not supported
            }
            if (bookNum == 0)
            {
                throw new Exception("Invalid [" + parts[0] + "] " + fileName);
            }

            while (versification.bookList.Count < bookNum)
            {
                versification.bookList.Add(new int[1] {
                    1
                });
            }

            List <int> verses = new List <int>();

            for (int i = 1; i <= parts.GetUpperBound(0); ++i)
            {
                string[] pieces = parts[i].Split(':');
                int      verseCount;
                if (pieces.GetUpperBound(0) != 1 ||
                    !int.TryParse(pieces[1], out verseCount) || verseCount <= 0)
                {
                    throw new Exception("Invalid [" + line + "] " + fileName);
                }

                verses.Add(verseCount);
            }

            versification.bookList[bookNum - 1] = verses.ToArray();
        }
Ejemplo n.º 9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Read versification file and "add" its entries.
        /// At the moment we only do this once. Eventually we will call this twice.
        /// Once for the standard versification, once for custom entries in versification.vrs
        /// file for this project.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="versification"></param>
        /// ------------------------------------------------------------------------------------
        private static void ReadVersificationFile(string fileName, VersificationTable versification)
        {
            using (TextReader reader = new StreamReader(fileName))
            {
                for (string line = reader.ReadLine(); line != null; line = reader.ReadLine())
                {
                    line = line.Trim();
                    if (line == "" || line[0] == '#')
                    {
                        continue;
                    }

                    if (line.Contains("="))
                    {
                        ParseMappingLine(fileName, versification, line);
                    }
                    else
                    {
                        ParseChapterVerseLine(fileName, versification, line);
                    }
                }
            }
        }
Ejemplo n.º 10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				// Just in case we didn't remove our message filter (which would now be invalid
				// since we would be disposed) when losing focus, we remove it here (TE-8297)
				Application.RemoveMessageFilter(this);

				if (components != null)
					components.Dispose();
				if (m_dropdownForm != null)
					m_dropdownForm.Dispose();
			}
			m_mulScrBooks = null;
			m_versTable = null;
			m_rgnEncodings = null;
			m_availableBookIds = null;
			m_bookLabels = null;
			m_dropdownForm = null;
			base.Dispose( disposing );
		}
Ejemplo n.º 11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialization, either from constructor or elsewhere following the default constructor.
		/// </summary>
		/// <param name="reference">Initial reference</param>
		/// <param name="availableBooks">Array of canonical book IDs to include</param>
		/// ------------------------------------------------------------------------------------
		public void Initialize(ScrReference reference, int[] availableBooks)
		{
			m_availableBookIds = null;

			if (availableBooks != null)
			{
				Array.Sort(availableBooks);
				m_availableBookIds = availableBooks.Distinct().ToList();
				InitializeBookLabels();
			}
			else
				BookLabels = m_mulScrBooks.BookLabels;

			if (reference != null && !reference.IsEmpty)
				ScReference = reference;
			else if (m_bookLabels != null && m_bookLabels.Length > 0)
				ScReference = new ScrReference(m_bookLabels[0].BookNum, 1, 1, Versification);
			else
				ScReference = new ScrReference(0, 0, 0, Versification);

			Reference = m_mulScrBooks.GetRefString(ScReference);

			// Use a default versification scheme if one is not available.
			m_versTable = VersificationTable.Get(Versification);
		}
Ejemplo n.º 12
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Copy a reference, converting it to the specified versification if necessary
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public ScrReference(ScrReference from, ScrVers targetVersification)
     : this(from.Book, from.Chapter, from.Verse, from.Segment, from.m_versification)
 {
     VersificationTable.Get(targetVersification).ChangeVersification(this);
 }
Ejemplo n.º 13
0
		// Parse lines giving number of verses for each chapter like
		// GEN 1:10 2:23 ...
		private static void ParseMappingLine(string fileName, VersificationTable versification, string line)
		{
			try
			{
				string[] parts = line.Split('=');
				string[] leftPieces = parts[0].Trim().Split('-');
				string[] rightPieces = parts[1].Trim().Split('-');

				BCVRef left = new BCVRef(leftPieces[0]);
				int leftLimit = leftPieces.GetUpperBound(0) == 0 ? 0 : int.Parse(leftPieces[1]);

				BCVRef right = new BCVRef(rightPieces[0]);

				while (true)
				{
					versification.toStandard[left.ToString()] = right.ToString();
					versification.fromStandard[right.ToString()] = left.ToString();

					if (left.Verse >= leftLimit)
						break;

					left.Verse = left.Verse + 1;
					right.Verse = right.Verse + 1;
				}
			}
			catch
			{
				// ENHANCE: Make it so the TE version of Localizer can have its own resources for stuff
				// like this.
				throw new Exception("Invalid [" + line + "] " + fileName);
			}
		}
Ejemplo n.º 14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the parameters needed for this check.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void GetParameters()
		{
			m_versificationScheme = m_checksDataSource.GetParameterValue(ksVerseSchemeParam);
			ScrVers scrVers;
			try
			{
				scrVers = (ScrVers)Enum.Parse(typeof(ScrVers),
					m_versificationScheme);
			}
			catch
			{
				// Default to English
				scrVers = ScrVers.English;
			}

			m_versification = VersificationTable.Get(scrVers);

			m_sBookId = m_checksDataSource.GetParameterValue(ksBookIdParam);
			if (!int.TryParse(m_checksDataSource.GetParameterValue(ksChapterParam), out m_nChapterToCheck))
				m_nChapterToCheck = 0;

			string temp = m_checksDataSource.GetParameterValue(ksVerseBridgeParam);
			string verseBridge = (string.IsNullOrEmpty(temp)) ? "-" : temp;

			temp = m_checksDataSource.GetParameterValue(ksScriptDigitZeroParam);
			char scriptDigitZero = (string.IsNullOrEmpty(temp)) ? '0' : temp[0];
			string numberRange = string.Format("[{1}-{2}][{0}-{2}]*", scriptDigitZero,
				(char)(scriptDigitZero + 1), (char)(scriptDigitZero + 9));

			temp = m_checksDataSource.GetParameterValue(ksSubVerseLetterAParam);
			if (!string.IsNullOrEmpty(temp))
				m_subVerseA = temp;

			temp = m_checksDataSource.GetParameterValue(ksSubVerseLetterBParam);
			if (!string.IsNullOrEmpty(temp))
				m_subVerseB = temp;
			string subverseRange = string.Format("[{0}{1}]?", m_subVerseA, m_subVerseB);

			// Original Regex for Roman script: "^[1-9][0-9]{0,2}[ab]?(-[1-9][0-9]{0,2}[ab]?)?$"
			m_verseNumberFormat = new Regex(String.Format("^{0}{1}({2}{0}{1})?$",
				numberRange, subverseRange, verseBridge));
			m_chapterNumberFormat = new Regex("^" + numberRange + "$");
		}
Ejemplo n.º 15
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Read the versification files into static tables
 /// </summary>
 /// <param name="vrsFolder">Path to the folder containing the .vrs files</param>
 /// <param name="fSupportDeuterocanon">set to <c>true</c> to support deuterocanonical
 /// books, otherwise <c>false</c>.</param>
 /// ------------------------------------------------------------------------------------
 public static void InitializeVersification(string vrsFolder, bool fSupportDeuterocanon)
 {
     VersificationTable.Initialize(vrsFolder);
     SupportDeuterocanon = fSupportDeuterocanon;
 }
Ejemplo n.º 16
0
		// Parse lines mapping from this versification to standard versification
		// GEN 1:10	= GEN 2:11
		// GEN 1:10-13 = GEN 2:11-14
		private static void ParseChapterVerseLine(string fileName, VersificationTable versification, string line)
		{
			string[] parts = line.Split(' ');
			int bookNum = BCVRef.BookToNumber(parts[0]);
			if (bookNum == -1)
				return; // Deuterocanonical books not supported

			if (bookNum == 0)
				throw new Exception("Invalid [" + parts[0] + "] " + fileName);

			while (versification.bookList.Count < bookNum)
				versification.bookList.Add(new int[1] { 1 });

			List<int> verses = new List<int>();

			for (int i = 1; i <= parts.GetUpperBound(0); ++i)
			{
				string[] pieces = parts[i].Split(':');
				int verseCount;
				if (pieces.GetUpperBound(0) != 1 ||
					!int.TryParse(pieces[1], out verseCount) || verseCount <= 0)
				{
					throw new Exception("Invalid [" + line + "] " + fileName);
				}

				verses.Add(verseCount);
			}

			versification.bookList[bookNum - 1] = verses.ToArray();
		}
Ejemplo n.º 17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialization, either from constructor or elsewhere following the default constructor.
		/// </summary>
		/// <param name="reference">Initial reference</param>
		/// <param name="scr">Scripture project</param>
		/// <param name="useBooksFromDB">Flag indicating whether to display the list of books
		/// available in the database or show all books in the Canon of Scripture.</param>
		/// ------------------------------------------------------------------------------------
		public void Initialize(ScrReference reference, Scripture scr, bool useBooksFromDB)
		{
			Debug.Assert(scr != null);
			m_scripture = scr;
			m_wsf = scr.Cache.LanguageWritingSystemFactoryAccessor;

			if (useBooksFromDB)
				m_mulScrBooks = new DBMultilingScrBooks(scr);
			else
				m_mulScrBooks = new MultilingScrBooks(scr);

			m_mulScrBooks.InitializeWritingSystems(m_wsf);

			if (m_rgnAvailableBooks != null)
				InitializeBookLabels();
			else
			{
				BookLabels = m_mulScrBooks.GetBookNames(true);
				m_rgnAvailableBooks = new int[m_mulScrBooks.ScriptureBooksLim];
			}

			if (reference != null && !reference.IsEmpty)
				ScReference = reference;
			else if (m_rgblBookNames != null && m_rgblBookNames.Length > 0)
				ScReference = new ScrReference(m_rgblBookNames[0].BookNum, 1, 1, Versification);
			else
				ScReference = new ScrReference(0, 0, 0, Versification);

			Reference = m_mulScrBooks.GetRefString(ScReference);

			// Use a default versification scheme if one is not available.
			m_versTable = VersificationTable.Get(Versification);
		}