Exemple #1
0
        public void TestImportFullELANData()
        {
            string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" +
                         "<item type=\"title\" lang=\"en\">wordspace</item>" +
                         "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
                         "<paragraphs><paragraph><phrases><phrase media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" +
                         "<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" +
                         "<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" +
                         "<media-files offset-type=\"milliseconds\"><media guid=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" location=\"file:\\\\test.wav\"/></media-files></interlinear-text></document>";

            LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);

            FDO.IText text = null;
            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
            {
                li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
                using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
                {
                    firstEntry.MoveNext();
                    var imported = firstEntry.Current;
                    Assert.True(imported.ContentsOA.ParagraphsOS.Count > 0, "Paragraph was not imported as text content.");
                    var para = imported.ContentsOA[0];
                    Assert.NotNull(para, "The imported paragraph is null?");
                    Assert.True(para.SegmentsOS[0].Guid.ToString().ToUpper().Equals("BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB"), "Segment guid not maintained on import.");
                    VerifyMediaLink(imported);
                }
            }
        }
Exemple #2
0
        public void TestProvidedTextUsedIfPresent()
        {
            string xml = "<document><interlinear-text>" +
                         "<item type=\"title\" lang=\"en\">wordspace</item>" +
                         "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
                         "<paragraphs><paragraph><phrases><phrase>" +
                         "<item type=\"txt\" lang=\"en\">Text not built from words.</item>" +
                         "<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" +
                         "<words><word><item type=\"txt\" lang=\"en\">a</item></word>" +
                         "<word><item type=\"txt\" lang=\"en\">space</item></word>" +
                         "<word><item type=\"txt\" lang=\"en\">space</item></word>" +
                         "</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";

            LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);

            FDO.IText text = null;
            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
            {
                li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
                using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
                {
                    firstEntry.MoveNext();
                    var imported = firstEntry.Current;
                    var para     = imported.ContentsOA[0];
                    Assert.IsTrue(para.Contents.Text.Equals("Text not built from words."));
                }
            }
        }
Exemple #3
0
        public void OneOfEachElementTypeTest()
        {
            string title = "atrocious";
            string abbr  = "atroc";
            //an interliner text example xml string
            string xml = "<document><interlinear-text>" +
                         "<item type=\"title\" lang=\"en\">" + title + "</item>" +
                         "<item type=\"title-abbreviation\" lang=\"en\">" + abbr + "</item>" +
                         "<paragraphs><paragraph><phrases><phrase>" +
                         "<item type=\"reference-number\" lang=\"en\">1 Musical</item>" +
                         "<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" +
                         "<words><word><item type=\"txt\" lang=\"en\">supercalifragilisticexpialidocious</item>" +
                         "<item type=\"gls\" lang=\"pt\">absurdo</item></word>" +
                         "</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";

            LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);

            FDO.IText text = null;
            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
            {
                li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
                using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
                {
                    firstEntry.MoveNext();
                    var imported = firstEntry.Current;
                    //The title imported
                    Assert.True(imported.Name.get_String(Cache.WritingSystemFactory.get_Engine("en").Handle).Text.Equals(title));
                    //The title abbreviation imported
                    Assert.True(imported.Abbreviation.get_String(Cache.WritingSystemFactory.get_Engine("en").Handle).Text.Equals(abbr));
                }
            }
        }
Exemple #4
0
        public void TestImportCreatesReusesExistingSpeaker()
        {
            string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" +
                         "<item type=\"title\" lang=\"en\">wordspace</item>" +
                         "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
                         "<paragraphs><paragraph><phrases><phrase speaker=\"Jimmy Dorante\" media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" +
                         "<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" +
                         "<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" +
                         "<media-files offset-type=\"milliseconds\"><media guid=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" location=\"file:\\\\test.wav\"/></media-files></interlinear-text></document>";

            ICmPerson newPerson = null;

            //Create and add Jimmy to the project.
            NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor,
                                           () => {
                Cache.LanguageProject.PeopleOA = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create();
                //person not found create one and add it.
                newPerson = Cache.ServiceLocator.GetInstance <ICmPersonFactory>().Create();
                Cache.LanguageProject.PeopleOA.PossibilitiesOS.Add(newPerson);
                newPerson.Name.set_String(Cache.DefaultVernWs, "Jimmy Dorante");
            });
            Assert.NotNull(newPerson);

            LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);

            FDO.IText text = null;
            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
            {
                li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);

                //If the import sets the speaker in the segment to our Jimmy, and not a new Jimmy then all is well
                Assert.AreEqual(newPerson, text.ContentsOA[0].SegmentsOS[0].SpeakerRA, "Speaker not reused.");
            }
        }
Exemple #5
0
        public void TestSpacesAroundSpanishPunct()
        {
            string xml = "<document><interlinear-text>" +
                         "<item type=\"title\" lang=\"en\">wordspace</item>" +
                         "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
                         "<paragraphs><paragraph><phrases><phrase>" +
                         "<item type=\"reference-number\" lang=\"en\">1 Musical</item>" +
                         "<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" +
                         "<words>" +
                         "<word><item type=\"txt\" lang=\"en\">s</item></word>" +
                         "<word><item type=\"punct\" lang=\"en\">.&#xA1;</item></word>" + // spanish begin exclamation
                         "<word><item type=\"txt\" lang=\"en\">s</item></word>" +
                         "<word><item type=\"punct\" lang=\"en\">!&#xBF;</item></word>" + // spanish begin question
                         "<word><item type=\"txt\" lang=\"en\">s</item></word>" +
                         "<word><item type=\"punct\" lang=\"en\">?</item></word>" +
                         "<word><item type=\"txt\" lang=\"en\">s</item></word>" +
                         "<word><item type=\"punct\" lang=\"en\">. &#xBF;</item></word>" +
                         "<word><item type=\"txt\" lang=\"en\">s</item></word>" +
                         "<word><item type=\"punct\" lang=\"en\">? &quot;&#xBF;</item></word>" +
                         "<word><item type=\"txt\" lang=\"en\">s</item></word>" +
                         "<word><item type=\"punct\" lang=\"en\">&#xBF;</item></word>" +
                         "<word><item type=\"txt\" lang=\"en\">s</item></word>" +
                         "</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";
            // --------------------------
            // 01234567890123456789012345
            // s. es! qs? s. qs? "qs qs (e=spanish beg. exclamation, q=spanish beg. question)
            // --------------------------

            LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);

            FDO.IText text = null;
            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
            {
                li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
                using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
                {
                    firstEntry.MoveNext();
                    var imported   = firstEntry.Current;                   // why is this null?!
                    var para       = imported.ContentsOA[0];
                    var spaceArray = new char[] { ' ' };
                    var spaceOne   = para.Contents.Text.Substring(2, 1);                   //should be: " "
                    var spaceTwo   = para.Contents.Text.Substring(6, 1);                   //should be: " "
                    var spaceThree = para.Contents.Text.Substring(10, 1);
                    var spaceFour  = para.Contents.Text.Substring(13, 1);
                    var spaceFive  = para.Contents.Text.Substring(17, 1);
                    var spaceSix   = para.Contents.Text.Substring(21, 1);
                    //test to make sure no space was inserted before the comma, this is probably captured by the other assert
                    Assert.AreEqual(7, para.Contents.Text.Split(spaceArray).Length);                     //capture correct number of spaces, and no double spaces
                    //test to make sure spaces were inserted in each expected place
                    CollectionAssert.AreEqual(new[] { " ", " ", " ", " ", " ", " " },
                                              new[] { spaceOne, spaceTwo, spaceThree, spaceFour, spaceFive, spaceSix });
                }
            }
        }
 protected virtual void DoStage2Conversion(byte[] stage1, IThreadedProgress dlg)
 {
     using (var stage2Input = new MemoryStream(stage1))
     {
         var stage2Converter = new LinguaLinksImport(m_cache, null, null);
         // Until we have a better idea, assume we're half done with the import when we've produced the intermediate.
         // Allocate 5 progress units to the ImportInterlinear, in case it can do better resolution.
         // Enhance JohnT: we could divide the progress up based on the lengths of the files,
         // and possibly converter.Convert could move the bar along based on how far through the file it is.
         // ImportInterlinear could do something similar. However, procesing a single file is so quick
         // that this very crude approximation is good enough.
         dlg.Position += 50;
         stage2Converter.ImportInterlinear(dlg, stage2Input, 50, ref m_firstNewText);
     }
 }
Exemple #7
0
        public void ImportParatextExportBasic()
        {
            string path = Path.Combine(DirectoryFinder.FwSourceDirectory, @"LexText/Interlinear/ITextDllTests/FlexTextImport");
            string file = Path.Combine(path, "FlexTextExportOutput.flextext");

            using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                LinguaLinksImport li   = new LinguaLinksImport(Cache, null, null);
                FDO.IText         text = null;
                var options            = new LinguaLinksImport.ImportInterlinearOptions {
                    Progress             = new DummyProgressDlg(),
                    BirdData             = fileStream, AllottedProgress = 0,
                    CheckAndAddLanguages = DummyCheckAndAddLanguagesInternal
                };

                bool result = li.ImportInterlinear(options, ref text);
                Assert.True(result, "ImportInterlinear was not successful.");
            }
        }
Exemple #8
0
        public void TestImportCreatesPersonForSpeaker()
        {
            string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" +
                         "<item type=\"title\" lang=\"en\">wordspace</item>" +
                         "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
                         "<paragraphs><paragraph><phrases><phrase speaker=\"Jimmy Dorante\" media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" +
                         "<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" +
                         "<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" +
                         "<media-files offset-type=\"milliseconds\"><media guid=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" location=\"file:\\\\test.wav\"/></media-files></interlinear-text></document>";

            LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);

            FDO.IText text = null;
            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
            {
                li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);

                Assert.AreEqual("Jimmy Dorante",
                                (Cache.LanguageProject.PeopleOA.PossibilitiesOS[0] as ICmPerson).Name.get_String(Cache.DefaultVernWs).Text,
                                "Speaker was not created during the import.");
            }
        }
Exemple #9
0
        public void TestEmptyParagraph()
        {
            string xml = "<document><interlinear-text>" +
                         "<item type=\"title\" lang=\"en\">wordspace</item>" +
                         "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
                         "<paragraphs><paragraph/></paragraphs></interlinear-text></document>";

            LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);

            FDO.IText text = null;
            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
            {
                li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
                using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
                {
                    firstEntry.MoveNext();
                    var imported = firstEntry.Current;
                    Assert.True(imported.ContentsOA.ParagraphsOS.Count > 0, "Empty paragraph was not imported as text content.");
                    var para = imported.ContentsOA[0];
                    Assert.NotNull(para, "The imported paragraph is null?");
                }
            }
        }
Exemple #10
0
        public void TestSpacesBetweenWords()
        {
            string xml = "<document><interlinear-text>" +
                         "<item type=\"title\" lang=\"en\">wordspace</item>" +
                         "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
                         "<paragraphs><paragraph><phrases><phrase>" +
                         "<item type=\"reference-number\" lang=\"en\">1 Musical</item>" +
                         "<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" +
                         "<words><word><item type=\"txt\" lang=\"en\">a</item></word>" +
                         "<word><item type=\"txt\" lang=\"en\">space</item></word>" +
                         "<word><item type=\"txt\" lang=\"en\">space</item></word>" +
                         "</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";

            LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);

            FDO.IText text = null;
            using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
            {
                li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
                using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
                {
                    firstEntry.MoveNext();
                    var imported  = firstEntry.Current;
                    var para      = imported.ContentsOA[0];
                    var spaceOne  = para.Contents.Text.Substring(1, 1);                    //should be: " "
                    var wordAfter = para.Contents.Text.Substring(2, 5);                    //should be: "space"
                    var spaceTwo  = para.Contents.Text.Substring(7, 1);                    //should be: " "
                    //test to make sure no space was inserted before the first word.
                    Assert.IsFalse(" ".Equals(para.Contents.GetSubstring(0, 1)));
                    //test to make sure spaces were inserted between "a" and "space", and between "space" and "space"
                    //any extra spaces would result in the "space" word looking like " spac"
                    Assert.IsTrue(spaceOne.Equals(spaceTwo));
                    Assert.IsTrue(wordAfter.Equals("space"));
                }
            }
        }
		public void TestImportCreatesPersonForSpeaker()
		{
			string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" +
			"<item type=\"title\" lang=\"en\">wordspace</item>" +
			"<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
			"<paragraphs><paragraph><phrases><phrase speaker=\"Jimmy Dorante\" media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" +
			"<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" +
			"<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" +
			"<media-files offset-type=\"milliseconds\"><media guid=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" location=\"file:\\\\test.wav\"/></media-files></interlinear-text></document>";

			LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);
			FDO.IText text = null;
			using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
			{
				li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);

				Assert.AreEqual("Jimmy Dorante",
					(Cache.LanguageProject.PeopleOA.PossibilitiesOS[0] as ICmPerson).Name.get_String(Cache.DefaultVernWs).Text,
					"Speaker was not created during the import.");
			}
		}
		public void TestImportFullELANData()
		{
			const string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" +
				"<item type=\"title\" lang=\"en\">wordspace</item>" +
				"<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
				"<paragraphs><paragraph><phrases>" +
				"<phrase media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" +
				"<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" +
				"<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" +
				@"<media-files offset-type=""milliseconds""><media guid=""FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"" location=""file:\\test.wav""/></media-files></interlinear-text></document>";

			LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);
			FDO.IText text = null;
			using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
			{
				li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
				using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
				{
					firstEntry.MoveNext();
					var imported = firstEntry.Current;
					Assert.True(imported.ContentsOA.ParagraphsOS.Count > 0, "Paragraph was not imported as text content.");
					var para = imported.ContentsOA[0];
					Assert.NotNull(para, "The imported paragraph is null?");
					Assert.AreEqual(new Guid("BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB"), para.SegmentsOS[0].Guid, "Segment guid not maintained on import.");
					VerifyMediaLink(imported);
				}
			}
		}
		public void TestEmptyParagraph()
		{
			string xml = "<document><interlinear-text>" +
			"<item type=\"title\" lang=\"en\">wordspace</item>" +
			"<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
			"<paragraphs><paragraph/></paragraphs></interlinear-text></document>";

			LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);
			FDO.IText text = null;
			using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
			{
				li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
				using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
				{
					firstEntry.MoveNext();
					var imported = firstEntry.Current;
					Assert.True(imported.ContentsOA.ParagraphsOS.Count > 0, "Empty paragraph was not imported as text content.");
					var para = imported.ContentsOA[0];
					Assert.NotNull(para, "The imported paragraph is null?");
				}
			}
		}
		public void TestProvidedTextUsedIfPresent()
		{
			string xml = "<document><interlinear-text>" +
			"<item type=\"title\" lang=\"en\">wordspace</item>" +
			"<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
			"<paragraphs><paragraph><phrases><phrase>" +
			"<item type=\"txt\" lang=\"en\">Text not built from words.</item>" +
			"<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" +
			"<words><word><item type=\"txt\" lang=\"en\">a</item></word>" +
			"<word><item type=\"txt\" lang=\"en\">space</item></word>" +
			"<word><item type=\"txt\" lang=\"en\">space</item></word>" +
			"</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";

			LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);
			FDO.IText text = null;
			using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
			{
				li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
				using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
				{
					firstEntry.MoveNext();
					var imported = firstEntry.Current;
					var para = imported.ContentsOA[0];
					Assert.IsTrue(para.Contents.Text.Equals("Text not built from words."));
				}
			}
		}
		public void TestSpacesBetweenWords()
		{
			string xml = "<document><interlinear-text>" +
			"<item type=\"title\" lang=\"en\">wordspace</item>" +
			"<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
			"<paragraphs><paragraph><phrases><phrase>" +
			"<item type=\"reference-number\" lang=\"en\">1 Musical</item>" +
			"<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" +
			"<words><word><item type=\"txt\" lang=\"en\">a</item></word>" +
			"<word><item type=\"txt\" lang=\"en\">space</item></word>" +
			"<word><item type=\"txt\" lang=\"en\">space</item></word>" +
			"</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";

			LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);
			FDO.IText text = null;
			using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
			{
				li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
				using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
				{
					firstEntry.MoveNext();
					var imported = firstEntry.Current;
					var para = imported.ContentsOA[0];
					var spaceOne = para.Contents.Text.Substring(1, 1); //should be: " "
					var wordAfter = para.Contents.Text.Substring(2, 5); //should be: "space"
					var spaceTwo = para.Contents.Text.Substring(7, 1); //should be: " "
					//test to make sure no space was inserted before the first word.
					Assert.IsFalse(" ".Equals(para.Contents.GetSubstring(0, 1)));
					//test to make sure spaces were inserted between "a" and "space", and between "space" and "space"
					//any extra spaces would result in the "space" word looking like " spac"
					Assert.IsTrue(spaceOne.Equals(spaceTwo));
					Assert.IsTrue(wordAfter.Equals("space"));
				}
			}
		}
		public void TestSpacesAroundSpanishPunct()
		{
			string xml = "<document><interlinear-text>" +
			"<item type=\"title\" lang=\"en\">wordspace</item>" +
			"<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
			"<paragraphs><paragraph><phrases><phrase>" +
			"<item type=\"reference-number\" lang=\"en\">1 Musical</item>" +
			"<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" +
			"<words>" +
			"<word><item type=\"txt\" lang=\"en\">s</item></word>" +
			"<word><item type=\"punct\" lang=\"en\">.&#xA1;</item></word>" + // spanish begin exclamation
			"<word><item type=\"txt\" lang=\"en\">s</item></word>" +
			"<word><item type=\"punct\" lang=\"en\">!&#xBF;</item></word>" + // spanish begin question
			"<word><item type=\"txt\" lang=\"en\">s</item></word>" +
			"<word><item type=\"punct\" lang=\"en\">?</item></word>" +
			"<word><item type=\"txt\" lang=\"en\">s</item></word>" +
			"<word><item type=\"punct\" lang=\"en\">. &#xBF;</item></word>" +
			"<word><item type=\"txt\" lang=\"en\">s</item></word>" +
			"<word><item type=\"punct\" lang=\"en\">? &quot;&#xBF;</item></word>" +
			"<word><item type=\"txt\" lang=\"en\">s</item></word>" +
			"<word><item type=\"punct\" lang=\"en\">&#xBF;</item></word>" +
			"<word><item type=\"txt\" lang=\"en\">s</item></word>" +
			"</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";
			// --------------------------
			// 01234567890123456789012345
			// s. es! qs? s. qs? "qs qs (e=spanish beg. exclamation, q=spanish beg. question)
			// --------------------------

			LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);
			FDO.IText text = null;
			using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
			{
				li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
				using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
				{
					firstEntry.MoveNext();
					var imported = firstEntry.Current; // why is this null?!
					var para = imported.ContentsOA[0];
					var spaceArray = new char[] { ' ' };
					var spaceOne = para.Contents.Text.Substring(2, 1); //should be: " "
					var spaceTwo = para.Contents.Text.Substring(6, 1); //should be: " "
					var spaceThree = para.Contents.Text.Substring(10, 1);
					var spaceFour = para.Contents.Text.Substring(13, 1);
					var spaceFive = para.Contents.Text.Substring(17, 1);
					var spaceSix = para.Contents.Text.Substring(21, 1);
					//test to make sure no space was inserted before the comma, this is probably captured by the other assert
					Assert.AreEqual(7, para.Contents.Text.Split(spaceArray).Length); //capture correct number of spaces, and no double spaces
					//test to make sure spaces were inserted in each expected place
					CollectionAssert.AreEqual(new[] { " ", " ", " ", " ", " ", " " },
						new[] { spaceOne, spaceTwo, spaceThree, spaceFour, spaceFive, spaceSix });
				}
			}
		}
		public void OneOfEachElementTypeTest()
		{
			string title = "atrocious";
			string abbr = "atroc";
			//an interliner text example xml string
			string xml = "<document><interlinear-text>" +
			"<item type=\"title\" lang=\"en\">" + title + "</item>" +
			"<item type=\"title-abbreviation\" lang=\"en\">" + abbr + "</item>" +
			"<paragraphs><paragraph><phrases><phrase>" +
			"<item type=\"reference-number\" lang=\"en\">1 Musical</item>" +
			"<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" +
			"<words><word><item type=\"txt\" lang=\"en\">supercalifragilisticexpialidocious</item>" +
			"<item type=\"gls\" lang=\"pt\">absurdo</item></word>" +
			"</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";

			LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);
			FDO.IText text = null;
			using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
			{
				li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);
				using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
				{
					firstEntry.MoveNext();
					var imported = firstEntry.Current;
					//The title imported
					Assert.True(imported.Name.get_String(Cache.WritingSystemFactory.get_Engine("en").Handle).Text.Equals(title));
					//The title abbreviation imported
					Assert.True(imported.Abbreviation.get_String(Cache.WritingSystemFactory.get_Engine("en").Handle).Text.Equals(abbr));
				}
			}
		}
		public void UglyEmptyDataShouldNotCrash()
		{
			const string textGuid = "eb0770f4-23aa-4f7b-b45d-fe745a3790a2";
			//an interliner text example xml string
			const string xml = "<document><interlinear-text guid='" + textGuid + "'>" +
									 "<paragraphs><paragraph guid='819742f3-3840-479e-9300-51755880680b'/></paragraphs><languages/>" +
									 "</interlinear-text></document>";

			var li = new LinguaLinksImport(Cache, null, null);
			FDO.IText text = null;
			using(var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
			{
				Assert.DoesNotThrow(()=> li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text));
				using(var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
				{
					firstEntry.MoveNext();
					var imported = firstEntry.Current;
					//The empty ugly text imported as its empty ugly self
					Assert.AreEqual(imported.Guid.ToString(), textGuid);
				}
			}
		}
		public void TestImportCreatesReusesExistingSpeaker()
		{
			string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" +
			"<item type=\"title\" lang=\"en\">wordspace</item>" +
			"<item type=\"title-abbreviation\" lang=\"en\">ws</item>" +
			"<paragraphs><paragraph><phrases><phrase speaker=\"Jimmy Dorante\" media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" +
			"<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" +
			"<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" +
			"<media-files offset-type=\"milliseconds\"><media guid=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" location=\"file:\\\\test.wav\"/></media-files></interlinear-text></document>";

			ICmPerson newPerson = null;
			//Create and add Jimmy to the project.
			NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor,
				() => {
				Cache.LanguageProject.PeopleOA = Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>().Create();
				//person not found create one and add it.
				newPerson = Cache.ServiceLocator.GetInstance<ICmPersonFactory>().Create();
				Cache.LanguageProject.PeopleOA.PossibilitiesOS.Add(newPerson);
				newPerson.Name.set_String(Cache.DefaultVernWs, "Jimmy Dorante");
			});
			Assert.NotNull(newPerson);

			LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);
			FDO.IText text = null;
			using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray())))
			{
				li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text);

				//If the import sets the speaker in the segment to our Jimmy, and not a new Jimmy then all is well
				Assert.AreEqual(newPerson, text.ContentsOA[0].SegmentsOS[0].SpeakerRA, "Speaker not reused.");
			}
		}
		protected virtual void DoStage2Conversion(byte[] stage1, IThreadedProgress dlg)
		{
			using (var stage2Input = new MemoryStream(stage1))
			{
				var stage2Converter = new LinguaLinksImport(m_cache, null, null);
				// Until we have a better idea, assume we're half done with the import when we've produced the intermediate.
				// Allocate 5 progress units to the ImportInterlinear, in case it can do better resolution.
				// Enhance JohnT: we could divide the progress up based on the lengths of the files,
				// and possibly converter.Convert could move the bar along based on how far through the file it is.
				// ImportInterlinear could do something similar. However, procesing a single file is so quick
				// that this very crude approximation is good enough.
				dlg.Position += 50;
				stage2Converter.ImportInterlinear(dlg, stage2Input, 50, ref m_firstNewText);
			}
		}
		public void ImportParatextExportBasic()
		{
			string path = Path.Combine(FwDirectoryFinder.SourceDirectory, @"LexText/Interlinear/ITextDllTests/FlexTextImport");
			string file = Path.Combine(path, "FlexTextExportOutput.flextext");
			using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
			{
				LinguaLinksImport li = new LinguaLinksImport(Cache, null, null);
				FDO.IText text = null;
				var options = new LinguaLinksImport.ImportInterlinearOptions{Progress = new DummyProgressDlg(),
					BirdData = fileStream, AllottedProgress = 0,
					CheckAndAddLanguages = DummyCheckAndAddLanguagesInternal };

				bool result = li.ImportInterlinear(options, ref text);
				Assert.True(result, "ImportInterlinear was not successful.");
			}
		}