DiscourseExporter is an IVwEnv implementation which exports discourse data to an XmlWriter. Make one of these by creating an XmlTextWriter. Refactoring is probably in order to share more code with InterlinearExporter, or move common code down to CollectorEnv. This has been postponed in the interests of being able to release FW 5.2.1 without requiring changes to DLLs other than Discourse.
Inheritance: SIL.FieldWorks.Common.RootSites.CollectorEnv, IDisposable
Exemplo n.º 1
0
        internal bool ExportPhase1(out DiscourseExporter exporter, string fileName)
        {
            CheckDisposed();

            using (var writer = new XmlTextWriter(fileName, System.Text.Encoding.UTF8))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("document");
                exporter = new DiscourseExporter(m_cache, writer, m_hvoRoot, m_vc, m_wsLineNumber);
                exporter.ExportDisplay();
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
            }
            return(true);
        }
Exemplo n.º 2
0
        public void Export()
        {
            using (var stream = new MemoryStream())
            {
                //Set up some cells.
                var allParaOccurrences = m_helper.MakeAnalysesUsedN(6);

                // Make last analysis point to WfiWordform instead of WfiGloss
                var lastOccurrence = allParaOccurrences[5];
                var wordform       = (lastOccurrence.Analysis as IWfiGloss).Wordform;
                lastOccurrence.Segment.AnalysesRS.Replace(1, 0, new List <ICmObject> {
                    wordform
                });
                // This block makes the first row, puts WordGroups in cells 1 and 2, and list refs in cells 1 and 2
                var row0         = m_helper.MakeFirstRow();
                var movedItem    = allParaOccurrences[1];
                var cellPart0_1  = m_helper.MakeWordGroup(row0, 1, allParaOccurrences[0], allParaOccurrences[0]);
                var marker       = m_helper.GetAMarker();
                var cellPart0_1b = m_helper.MakeChartMarker(row0, 1, marker);
                var cellPart0_2  = m_helper.MakeWordGroup(row0, 2, movedItem, movedItem);
                var marker2      = m_helper.GetAnotherMarker();
                var cellPart0_2b = m_helper.MakeChartMarker(row0, 2, marker2);
                var cellPart0_2c = m_helper.MakeChartMarker(row0, 2, marker);
                var cellPart0_3  = m_helper.MakeWordGroup(row0, 3, lastOccurrence, lastOccurrence);

                // Now another row, and cell 4 on the first has a ref to it. The new row has a WordGroup with two
                // wordforms in cell 1. The cell is two columns wide, being merged with the previous cell.
                var row1 = m_helper.MakeSecondRow();
                m_helper.MakeDependentClauseMarker(row0, 4, new[] { row1 }, ClauseTypes.Song);
                var cellPart1_1 = m_helper.MakeWordGroup(row1, 1, allParaOccurrences[2], allParaOccurrences[3]);
                cellPart1_1.MergesBefore = true;

                // Let's have some notes on row 0.
                //var notesText = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create();
                row0.Notes = TsStringUtils.MakeString("This is a test note", Cache.DefaultAnalWs);
                //var notesPara = Cache.ServiceLocator.GetInstance<IStTxtParaFactory>().Create();
                //notesText.ParagraphsOS.Add(notesPara);
                //notesPara.Contents = ;

                // And some moved text in row 1
                var cellPart1_2 = m_helper.MakeWordGroup(row1, 2, allParaOccurrences[4], allParaOccurrences[4]);
                m_helper.MakeMovedTextMarker(row1, 3, cellPart1_2, true);

                // We need four rows to properly test the variations on endPara/endSent
                var row2 = m_helper.MakeRow(m_chart, "2");
                row2.EndSentence = true;
                var row3 = m_helper.MakeRow(m_chart, "3");
                row3.EndSentence  = true;
                row3.EndParagraph = true;
                m_helper.MakeRow(m_chart, "4");

                using (var writer = new XmlTextWriter(stream, Encoding.UTF8))
                {
                    using (var vc = new ConstChartVc(m_chartBody))
                    {
                        vc.LineChoices = m_chartBody.LineChoices;
                        using (var exporter = new DiscourseExporter(Cache, writer, m_chart.Hvo, vc, Cache.DefaultAnalWs))
                        {
                            writer.WriteStartDocument();
                            writer.WriteStartElement("document");
                            exporter.ExportDisplay();
                            writer.WriteEndElement();
                            writer.WriteEndDocument();
                            writer.Flush();
                            // Close makes it unuseable
                            stream.Position = 0;
                            using (var reader = new StreamReader(stream, Encoding.UTF8))
                            {
                                var result = reader.ReadToEnd();
                                var doc    = new XmlDocument();
                                doc.LoadXml(result);
                                var docNode = doc.DocumentElement;
                                Assert.AreEqual("document", docNode.Name);
                                var chartNode = VerifyNode("chart", docNode, 0, "chart", 7, 0);
                                VerifyTitleRow(chartNode);
                                VerifyTitle2Row(chartNode);
                                VerifyFirstDataRow(chartNode);
                                VerifySecondDataRow(chartNode);
                                var thirdRow = VerifyNode("row", chartNode, 4, "row", 8, 3);
                                AssertAttr(thirdRow, "endSent", "true");
                                var fourthRow = VerifyNode("row", chartNode, 5, "row", 8, 3);
                                AssertAttr(fourthRow, "endPara", "true");

                                var langNode = VerifyNode("languages", docNode, 1, "languages", 2, 0);
                                var enNode   = VerifyNode("english lang node", langNode, 0, "language", 0, 2);
                                AssertAttr(enNode, "lang", "en");
                                AssertAttr(enNode, "font", null);
                                // don't verify exact font, may depend on installation.
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
		public void Export()
		{
			using (MemoryStream stream = new MemoryStream())
			{
				//Set up some cells.
				int[] allParaWfics = m_helper.MakeAnnotationsUsedN(5);

				// This block makes the first row, puts CCAs in cells 1 and 2, and list refs in cells 1 and 2
				CmIndirectAnnotation row0 = m_helper.MakeFirstRow();
				int[] movedItems = new int[] { allParaWfics[1] };
				CmIndirectAnnotation cca0_1 = m_helper.MakeColumnAnnotation(1, new int[] { allParaWfics[0] }, row0);
				ICmPossibility marker = m_helper.GetAMarker();
				ICmBaseAnnotation cca0_1b = m_helper.MakeMarkerAnnotation(1, row0, marker);
				CmIndirectAnnotation cca0_2 = m_helper.MakeColumnAnnotation(2, movedItems, row0);
				ICmPossibility marker2 = m_helper.GetAnotherMarker();
				ICmBaseAnnotation cca0_2b = m_helper.MakeMarkerAnnotation(2, row0, marker2);
				ICmBaseAnnotation cca0_2c = m_helper.MakeMarkerAnnotation(2, row0, marker);

				// Now another row, and cell 4 on the first has a ref to it. The new row has a CCA with two wfics in cell 1. The cell is
				// two columns wide, being merged with the previous cell.
				CmIndirectAnnotation row1 = m_helper.MakeSecondRow();
				ICmIndirectAnnotation cca0_4 = m_helper.MakeDependentClauseMarker(row0, 4, new int[] { row1.Hvo }, "song", "2");
				CmIndirectAnnotation cca1_1 = m_helper.MakeColumnAnnotation(1, new int[] { allParaWfics[2], allParaWfics[3] }, row1);
				ConstituentChartLogic.SetFeature(Cache.MainCacheAccessor, cca1_1.Hvo, ConstituentChartLogic.mergeBeforeTag, true);

				// Let's have some notes on row 0.
				StText notesText = new StText();
				row0.TextOA = notesText;
				StTxtPara notesPara = new StTxtPara();
				notesText.ParagraphsOS.Append(notesPara);
				notesPara.Contents.UnderlyingTsString = Cache.MakeAnalysisTss("This is a test note");

				// And some moved text in row 1
				CmIndirectAnnotation cca1_2 = m_helper.MakeColumnAnnotation(2, new int[] { allParaWfics[4] }, row1);
				ConstituentChartLogic.SetFeature(Cache.MainCacheAccessor, cca1_2.Hvo,
					ConstituentChartLogic.MovedTextFeatureName, true);
				CmIndirectAnnotation cca2_3 = m_helper.MakeMovedTextAnnotation(3, cca1_2, row1, "Preposed");

				// We need four rows to properly test the variations on endPara/endSent
				CmIndirectAnnotation row2 = m_helper.MakeRow(m_chart, "2");
				ConstituentChartLogic.SetFeature(Cache.MainCacheAccessor, row2.Hvo, ConstituentChartLogic.EndSentFeatureName, true);
				CmIndirectAnnotation row3 = m_helper.MakeRow(m_chart, "3");
				ConstituentChartLogic.SetFeature(Cache.MainCacheAccessor, row3.Hvo, ConstituentChartLogic.EndParaFeatureName, true);
				ConstituentChartLogic.SetFeature(Cache.MainCacheAccessor, row3.Hvo, ConstituentChartLogic.EndSentFeatureName, true);
				CmIndirectAnnotation row4 = m_helper.MakeRow(m_chart, "4");


				XmlWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
				ConstChartVc vc = new ConstChartVc(m_chartBody);
				vc.LineChoices = m_chartBody.LineChoices;
				DiscourseExporter exporter = new DiscourseExporter(m_inMemoryCache.Cache, writer, m_chart.Hvo,
					vc, m_inMemoryCache.Cache.DefaultAnalWs);
				writer.WriteStartDocument();
				writer.WriteStartElement("document");
				exporter.ExportDisplay();
				writer.WriteEndElement();
				writer.WriteEndDocument();
				writer.Flush(); // Close makes it unuseable
				stream.Position = 0;
				StreamReader reader = new StreamReader(stream, Encoding.UTF8);
				string result = reader.ReadToEnd();
				XmlDocument doc = new XmlDocument();
				doc.LoadXml(result);
				XmlNode docNode = doc.DocumentElement;
				Assert.AreEqual("document", docNode.Name);
				XmlNode chartNode = VerifyNode("chart", docNode, 0, "chart", 7, 0);
				VerifyTitleRow(chartNode);
				VerifyTitle2Row(chartNode);
				VerifyFirstDataRow(chartNode);
				VerifySecondDataRow(chartNode);
				XmlNode thirdRow = VerifyNode("row", chartNode, 4, "row", 8, 3);
				AssertAttr(thirdRow, "endSent", "true");
				XmlNode fourthRow = VerifyNode("row", chartNode, 5, "row", 8, 3);
				AssertAttr(fourthRow, "endPara", "true");


				XmlNode langNode = VerifyNode("languages", docNode, 1, "languages", 2, 0);
				XmlNode enNode = VerifyNode("english lang node", langNode, 0, "language", 0, 2);
				AssertAttr(enNode, "lang", "en");
				AssertAttr(enNode, "font", null); // don't verify exact font, may depend on installation.

			}

		}
Exemplo n.º 4
0
		public void Export()
		{
			using (var stream = new MemoryStream())
			{
				//Set up some cells.
				var allParaOccurrences = m_helper.MakeAnalysesUsedN(6);

				// Make last analysis point to WfiWordform instead of WfiGloss
				var lastOccurrence = allParaOccurrences[5];
				var wordform = (lastOccurrence.Analysis as IWfiGloss).Wordform;
				lastOccurrence.Segment.AnalysesRS.Replace(1, 0, new List<ICmObject> { wordform });
				// This block makes the first row, puts WordGroups in cells 1 and 2, and list refs in cells 1 and 2
				var row0 = m_helper.MakeFirstRow();
				var movedItem = allParaOccurrences[1];
				var cellPart0_1 = m_helper.MakeWordGroup(row0, 1, allParaOccurrences[0], allParaOccurrences[0]);
				var marker = m_helper.GetAMarker();
				var cellPart0_1b = m_helper.MakeChartMarker(row0, 1, marker);
				var cellPart0_2 = m_helper.MakeWordGroup(row0, 2, movedItem, movedItem);
				var marker2 = m_helper.GetAnotherMarker();
				var cellPart0_2b = m_helper.MakeChartMarker(row0, 2, marker2);
				var cellPart0_2c = m_helper.MakeChartMarker(row0, 2, marker);
				var cellPart0_3 = m_helper.MakeWordGroup(row0, 3, lastOccurrence, lastOccurrence);

				// Now another row, and cell 4 on the first has a ref to it. The new row has a WordGroup with two
				// wordforms in cell 1. The cell is two columns wide, being merged with the previous cell.
				var row1 = m_helper.MakeSecondRow();
				m_helper.MakeDependentClauseMarker(row0, 4, new[] { row1 }, ClauseTypes.Song);
				var cellPart1_1 = m_helper.MakeWordGroup(row1, 1, allParaOccurrences[2], allParaOccurrences[3]);
				cellPart1_1.MergesBefore = true;

				// Let's have some notes on row 0.
				//var notesText = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create();
				row0.Notes = Cache.TsStrFactory.MakeString("This is a test note", Cache.DefaultAnalWs);
				//var notesPara = Cache.ServiceLocator.GetInstance<IStTxtParaFactory>().Create();
				//notesText.ParagraphsOS.Add(notesPara);
				//notesPara.Contents = ;

				// And some moved text in row 1
				var cellPart1_2 = m_helper.MakeWordGroup(row1, 2, allParaOccurrences[4], allParaOccurrences[4]);
				m_helper.MakeMovedTextMarker(row1, 3, cellPart1_2, true);

				// We need four rows to properly test the variations on endPara/endSent
				var row2 = m_helper.MakeRow(m_chart, "2");
				row2.EndSentence = true;
				var row3 = m_helper.MakeRow(m_chart, "3");
				row3.EndSentence = true;
				row3.EndParagraph = true;
				m_helper.MakeRow(m_chart, "4");

				using (var writer = new XmlTextWriter(stream, Encoding.UTF8))
				{
					using (var vc = new ConstChartVc(m_chartBody))
					{
						vc.LineChoices = m_chartBody.LineChoices;
						using (var exporter = new DiscourseExporter(Cache, writer, m_chart.Hvo, vc, Cache.DefaultAnalWs))
						{
							writer.WriteStartDocument();
							writer.WriteStartElement("document");
							exporter.ExportDisplay();
							writer.WriteEndElement();
							writer.WriteEndDocument();
							writer.Flush();
							// Close makes it unuseable
							stream.Position = 0;
							using (var reader = new StreamReader(stream, Encoding.UTF8))
							{
								var result = reader.ReadToEnd();
								var doc = new XmlDocument();
								doc.LoadXml(result);
								var docNode = doc.DocumentElement;
								Assert.AreEqual("document", docNode.Name);
								var chartNode = VerifyNode("chart", docNode, 0, "chart", 7, 0);
								VerifyTitleRow(chartNode);
								VerifyTitle2Row(chartNode);
								VerifyFirstDataRow(chartNode);
								VerifySecondDataRow(chartNode);
								var thirdRow = VerifyNode("row", chartNode, 4, "row", 8, 3);
								AssertAttr(thirdRow, "endSent", "true");
								var fourthRow = VerifyNode("row", chartNode, 5, "row", 8, 3);
								AssertAttr(fourthRow, "endPara", "true");

							var langNode = VerifyNode("languages", docNode, 1, "languages", 2, 0);
								var enNode = VerifyNode("english lang node", langNode, 0, "language", 0, 2);
								AssertAttr(enNode, "lang", "en");
								AssertAttr(enNode, "font", null);
								// don't verify exact font, may depend on installation.
							}
						}
					}
				}
			}
		}
Exemplo n.º 5
0
		internal bool ExportPhase1(out DiscourseExporter exporter, string fileName)
		{
			CheckDisposed();

			using (var writer = new XmlTextWriter(fileName, System.Text.Encoding.UTF8))
			{
				writer.WriteStartDocument();
				writer.WriteStartElement("document");
				exporter = new DiscourseExporter(m_cache, writer, m_hvoRoot, m_vc, m_wsLineNumber);
				exporter.ExportDisplay();
				writer.WriteEndElement();
				writer.WriteEndDocument();
				writer.Close();
			}
			return true;
		}
Exemplo n.º 6
0
        public void Export()
        {
            using (MemoryStream stream = new MemoryStream())
            {
                //Set up some cells.
                int[] allParaWfics = m_helper.MakeAnnotationsUsedN(5);

                // This block makes the first row, puts CCAs in cells 1 and 2, and list refs in cells 1 and 2
                CmIndirectAnnotation row0    = m_helper.MakeFirstRow();
                int[] movedItems             = new int[] { allParaWfics[1] };
                CmIndirectAnnotation cca0_1  = m_helper.MakeColumnAnnotation(1, new int[] { allParaWfics[0] }, row0);
                ICmPossibility       marker  = m_helper.GetAMarker();
                ICmBaseAnnotation    cca0_1b = m_helper.MakeMarkerAnnotation(1, row0, marker);
                CmIndirectAnnotation cca0_2  = m_helper.MakeColumnAnnotation(2, movedItems, row0);
                ICmPossibility       marker2 = m_helper.GetAnotherMarker();
                ICmBaseAnnotation    cca0_2b = m_helper.MakeMarkerAnnotation(2, row0, marker2);
                ICmBaseAnnotation    cca0_2c = m_helper.MakeMarkerAnnotation(2, row0, marker);

                // Now another row, and cell 4 on the first has a ref to it. The new row has a CCA with two wfics in cell 1. The cell is
                // two columns wide, being merged with the previous cell.
                CmIndirectAnnotation  row1   = m_helper.MakeSecondRow();
                ICmIndirectAnnotation cca0_4 = m_helper.MakeDependentClauseMarker(row0, 4, new int[] { row1.Hvo }, "song", "2");
                CmIndirectAnnotation  cca1_1 = m_helper.MakeColumnAnnotation(1, new int[] { allParaWfics[2], allParaWfics[3] }, row1);
                ConstituentChartLogic.SetFeature(Cache.MainCacheAccessor, cca1_1.Hvo, ConstituentChartLogic.mergeBeforeTag, true);

                // Let's have some notes on row 0.
                StText notesText = new StText();
                row0.TextOA = notesText;
                StTxtPara notesPara = new StTxtPara();
                notesText.ParagraphsOS.Append(notesPara);
                notesPara.Contents.UnderlyingTsString = Cache.MakeAnalysisTss("This is a test note");

                // And some moved text in row 1
                CmIndirectAnnotation cca1_2 = m_helper.MakeColumnAnnotation(2, new int[] { allParaWfics[4] }, row1);
                ConstituentChartLogic.SetFeature(Cache.MainCacheAccessor, cca1_2.Hvo,
                                                 ConstituentChartLogic.MovedTextFeatureName, true);
                CmIndirectAnnotation cca2_3 = m_helper.MakeMovedTextAnnotation(3, cca1_2, row1, "Preposed");

                // We need four rows to properly test the variations on endPara/endSent
                CmIndirectAnnotation row2 = m_helper.MakeRow(m_chart, "2");
                ConstituentChartLogic.SetFeature(Cache.MainCacheAccessor, row2.Hvo, ConstituentChartLogic.EndSentFeatureName, true);
                CmIndirectAnnotation row3 = m_helper.MakeRow(m_chart, "3");
                ConstituentChartLogic.SetFeature(Cache.MainCacheAccessor, row3.Hvo, ConstituentChartLogic.EndParaFeatureName, true);
                ConstituentChartLogic.SetFeature(Cache.MainCacheAccessor, row3.Hvo, ConstituentChartLogic.EndSentFeatureName, true);
                CmIndirectAnnotation row4 = m_helper.MakeRow(m_chart, "4");


                XmlWriter    writer = new XmlTextWriter(stream, Encoding.UTF8);
                ConstChartVc vc     = new ConstChartVc(m_chartBody);
                vc.LineChoices = m_chartBody.LineChoices;
                DiscourseExporter exporter = new DiscourseExporter(m_inMemoryCache.Cache, writer, m_chart.Hvo,
                                                                   vc, m_inMemoryCache.Cache.DefaultAnalWs);
                writer.WriteStartDocument();
                writer.WriteStartElement("document");
                exporter.ExportDisplay();
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Flush();                 // Close makes it unuseable
                stream.Position = 0;
                StreamReader reader = new StreamReader(stream, Encoding.UTF8);
                string       result = reader.ReadToEnd();
                XmlDocument  doc    = new XmlDocument();
                doc.LoadXml(result);
                XmlNode docNode = doc.DocumentElement;
                Assert.AreEqual("document", docNode.Name);
                XmlNode chartNode = VerifyNode("chart", docNode, 0, "chart", 7, 0);
                VerifyTitleRow(chartNode);
                VerifyTitle2Row(chartNode);
                VerifyFirstDataRow(chartNode);
                VerifySecondDataRow(chartNode);
                XmlNode thirdRow = VerifyNode("row", chartNode, 4, "row", 8, 3);
                AssertAttr(thirdRow, "endSent", "true");
                XmlNode fourthRow = VerifyNode("row", chartNode, 5, "row", 8, 3);
                AssertAttr(fourthRow, "endPara", "true");


                XmlNode langNode = VerifyNode("languages", docNode, 1, "languages", 2, 0);
                XmlNode enNode   = VerifyNode("english lang node", langNode, 0, "language", 0, 2);
                AssertAttr(enNode, "lang", "en");
                AssertAttr(enNode, "font", null);                 // don't verify exact font, may depend on installation.
            }
        }