public void visualize(Canvas canvas, Rect rect) { Paint paint = new Paint {color = Colors.blue}; Paint paint2 = new Paint {color = Colors.red}; Paint paint3 = new Paint {color = Colors.green}; Paint paint4 = new Paint {color = Colors.white70}; float[] costFrames = this._laps; int curFrame = (this._currentSample - 1) % InstrumentationUtils.kMaxSamples; float barWidth = Mathf.Max(1, rect.width / costFrames.Length); float perHeight = rect.height / 32.0f; canvas.drawRect(rect, paint4); canvas.drawRect(Rect.fromLTWH(rect.left, rect.top + perHeight * 16.0f, rect.width, 1), paint3); float cur_x = rect.left; Path barPath = new Path(); for (var i = 0; i < costFrames.Length; i++) { if (costFrames[i] != 0) { float curHeight = Mathf.Min(perHeight * costFrames[i] * 1000, rect.height); Rect barRect = Rect.fromLTWH(cur_x, rect.top + rect.height - curHeight, barWidth, curHeight); barPath.addRect(barRect); } cur_x += barWidth; } canvas.drawPath(barPath, paint); if (curFrame >= 0 && curFrame < costFrames.Length) { if (costFrames[curFrame] != 0) { float curHeight = Mathf.Min(perHeight * costFrames[curFrame] * 1000, rect.height); Rect barRect = Rect.fromLTWH(rect.left + barWidth * curFrame, rect.top + rect.height - curHeight, barWidth, curHeight); canvas.drawRect(barRect, paint2); } var pb = new ParagraphBuilder(new ParagraphStyle { }); pb.addText("Current Frame Cost: " + costFrames[curFrame] * 1000 + "ms" + " ; Max(in last 120 frames): " + this.maxDelta() * 1000 + "ms"); var paragraph = pb.build(); paragraph.layout(new ParagraphConstraints(width: 800)); canvas.drawParagraph(paragraph, new Offset(rect.left, rect.top + rect.height - 12)); } }
public void FootnoteText() { //Create new TextDocument TextDocument document = new TextDocument(); document.New(); //Create a new Paragph Paragraph para = ParagraphBuilder.CreateStandardTextParagraph(document); //Create some simple Text para.TextContent.Add(new SimpleText(document, "Some simple text. And I have a footnode")); //Create a Footnote para.TextContent.Add(new Footnote(document, "Footer Text", "1", FootnoteType.footnode)); //Add the paragraph document.Content.Add(para); //Save document.SaveTo(AARunMeFirstAndOnce.outPutFolder + "footnote.odt"); }
public void ParagraphFormatedText() { //Create a new text document TextDocument document = new TextDocument(); document.New(); //Create a standard paragraph using the ParagraphBuilder Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document); //Add some formated text FormatedText formText = new FormatedText(document, "T1", "Some formated text!"); formText.TextStyle.TextProperties.Bold = "bold"; paragraph.TextContent.Add(formText); //Add the paragraph to the document document.Content.Add(paragraph); //Save empty document.SaveTo(AARunMeFirstAndOnce.outPutFolder + "formated.odt"); }
public void ParagraphSimpleText() { //Create a new text document TextDocument document = new TextDocument(); document.New(); //Create a standard paragraph using the ParagraphBuilder Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document); //Add some simple text paragraph.TextContent.Add(new SimpleText(document, "Some simple text!")); //Add the paragraph to the document document.Content.Add(paragraph); //Save empty using (IPackageWriter writer = new OnDiskPackageWriter()) { document.Save(AARunMeFirstAndOnce.outPutFolder + "simple.odt", new OpenDocumentTextExporter(writer)); } }
/// <summary> /// Creates the tables. /// </summary> /// <param name="lines">The lines.</param> private void CreateTables(ArrayList lines) { string unicodeDelimiter = "\u00BF"; // turned question mark if (lines != null) { Table table = TableBuilder.CreateSpreadsheetTable( (SpreadsheetDocument)this._document, "Table1", "table1"); //First line must specify the used delimiter string delimiter = lines[0] as string; lines.RemoveAt(0); try { //Perform lines foreach (string line in lines) { string lineContent = line.Replace(delimiter, unicodeDelimiter); string[] cellContents = lineContent.Split(unicodeDelimiter.ToCharArray()); Row row = new Row(table); foreach (string cellContent in cellContents) { Cell cell = new Cell(table); Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(this._document); paragraph.TextContent.Add(new SimpleText(this._document, cellContent)); cell.Content.Add(paragraph); row.InsertCellAt(row.CellCollection.Count, cell); } table.RowCollection.Add(row); } } catch (Exception ex) { AODLException aodlExeception = new AODLException("Error while proccessing the csv file."); aodlExeception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); aodlExeception.OriginalException = ex; throw aodlExeception; } this._document.Content.Add(table); } }
public void build(ParagraphBuilder builder, float textScaleFactor = 1.0f) { var hasStyle = this.style != null; if (hasStyle) { builder.pushStyle(this.style, textScaleFactor); } if (this.splitedText != null) { if (this.splitedText.Count == 1 && !char.IsHighSurrogate(this.splitedText[0][0]) && !EmojiUtils.isSingleCharEmoji(this.splitedText[0][0])) { builder.addText(this.splitedText[0]); } else { TextStyle style = this.style ?? new TextStyle(); for (int i = 0; i < this.splitedText.Count; i++) { builder.pushStyle(style, textScaleFactor); builder.addText(this.splitedText[i]); builder.pop(); } } } if (this.children != null) { foreach (var child in this.children) { Assert.IsNotNull(child); child.build(builder, textScaleFactor); } } if (hasStyle) { builder.pop(); } }
void Supl(int id) //бланк в разрезе по поставщикам, поэтому функция для фильтрации объектов того или иного поставщика { SpreadsheetDocument spreadsheetDocument = new SpreadsheetDocument(); spreadsheetDocument.New(); Table table = new Table(spreadsheetDocument, "First", "tablefirst"); for (int j = 0; j < countsup; j++) { Paragraph parag = ParagraphBuilder.CreateSpreadsheetParagraph(spreadsheetDocument); var text = TextBuilder.BuildTextCollection(spreadsheetDocument, " "); Cell cell = table.CreateCell(); parag.TextContent.Add(new SimpleText(spreadsheetDocument, "элемент бд, где поставщик ид=ид"));//И за это тоже выебу и в прямом, и в переносном смысле за такие фразы cell.Content.Add(parag); table.InsertCellAt(0, 0, cell); spreadsheetDocument.TableCollection.Add(table); spreadsheetDocument.SaveTo("Matr.ods"); } }
/// <summary> /// /// </summary> /// <param name="row"></param> private void SetColumnsName(DataRow row) { table.Rows.Add(new Row(table)); foreach (String columnName in row.ItemArray) { Cell columnHeader = new Cell(document, "cell003"); columnHeader.OfficeValueType = "string"; columnHeader.CellStyle.CellProperties.Border = Border.HeavySolid; columnHeader.CellStyle.CellProperties.BackgroundColor = "#D0B1A1"; Paragraph titoloParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(document); FormatedText fText = new FormatedText(document, "T3", columnName); fText.TextStyle.TextProperties.Bold = "bold"; fText.TextStyle.TextProperties.FontSize = "10pt"; titoloParagraph.TextContent.Add(fText); columnHeader.Content.Add(titoloParagraph); table.Rows[currentRow].Cells.Add(columnHeader); } currentRow++; }
public void InsertAndRemoveTest() { //Create a new document TextDocument document = new TextDocument(); document.New(); //Create a standard paragraph Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document); //Create some simple text SimpleText simpleText = new SimpleText(document, "Some simple text"); //Add the text paragraph.TextContent.Add(simpleText); Assert.IsNotEmpty(paragraph.TextContent, "Must be contain one element."); //Remove the simple text paragraph.TextContent.Remove(simpleText); Assert.IsEmpty(paragraph.TextContent, "Must be empty"); Assert.IsTrue(paragraph.Node.InnerXml.Length == 0, "Node from simple text must be removed."); }
private void button5_Click(object sender, EventArgs e) { saveFileDialog1.ShowDialog(); KURS.allDataSet kursDataSet = new KURS.allDataSet(); KURS.allDataSetTableAdapters.TovarTableAdapter TovarTableAdapter = new KURS.allDataSetTableAdapters.TovarTableAdapter(); TovarTableAdapter.Fill(kursDataSet.Tovar); TextDocument textdocument = new TextDocument(); textdocument.New(); Paragraph headerText1 = ParagraphBuilder.CreateStandardTextParagraph(textdocument); headerText1.TextContent.Add(new SimpleText(textdocument, "firma kosmetics")); textdocument.Content.Add(headerText1); Paragraph headerText2 = ParagraphBuilder.CreateStandardTextParagraph(textdocument); headerText2.TextContent.Add(new SimpleText(textdocument, "Ulyanovsk, Russian Federation")); textdocument.Content.Add(headerText2); Paragraph headerText3 = ParagraphBuilder.CreateStandardTextParagraph(textdocument); headerText3.TextContent.Add(new SimpleText(textdocument, "Кому: " + listBox1.Text)); textdocument.Content.Add(headerText3); var d = from price in kursDataSet.Tovar.AsEnumerable() where price.kolvo == 0 select price; Paragraph maintext = ParagraphBuilder.CreateStandardTextParagraph(textdocument); maintext.TextContent.Add(new SimpleText(textdocument, "ID--name--srok--price" + Environment.NewLine)); textdocument.Content.Add(maintext); foreach (var obj in d) { Paragraph maintext2 = ParagraphBuilder.CreateStandardTextParagraph(textdocument); maintext2.TextContent.Add(new SimpleText(textdocument, obj.id.ToString() + "--" + obj.name.ToString() + "--" + obj.srok.ToString() + "--" + obj.price.ToString() + Environment.NewLine)); textdocument.Content.Add(maintext2); } Paragraph footerText = ParagraphBuilder.CreateStandardTextParagraph(textdocument); footerText.TextContent.Add(new SimpleText(textdocument, "Подпись продавца:_____________")); textdocument.Content.Add(footerText); textdocument.SaveTo(saveFileDialog1.FileName); }
public void CreateFreePositionGraphic() { TextDocument textdocument = new TextDocument(); textdocument.New(); Paragraph p = ParagraphBuilder.CreateStandardTextParagraph(textdocument); Frame frame = FrameBuilder.BuildStandardGraphicFrame(textdocument, "frame1", "graphic1", _imagefile); //Setps to set a graphic free with x and y frame.SvgX = "1.75cm"; frame.SvgY = "1.75cm"; ((FrameStyle)frame.Style).GraphicProperties.HorizontalPosition = "from-left"; ((FrameStyle)frame.Style).GraphicProperties.VerticalPosition = "from-top"; ((FrameStyle)frame.Style).GraphicProperties.HorizontalRelative = "paragraph"; ((FrameStyle)frame.Style).GraphicProperties.VerticalRelative = "paragraph"; p.Content.Add(frame); textdocument.Content.Add(p); textdocument.SaveTo(AARunMeFirstAndOnce.outPutFolder + "grapic_free_xy.odt"); }
/// <summary> /// Metodo per l'impostazione del titolo di un report /// </summary> /// <param name="title">Titolo da assegnare al foglio</param> /// <param name="sheet">Foglio a cui aggiungere il titolo</param> private void SetTitle(String title, Table sheet, String reportKey) { Cell titleCell = new Cell(sheet.Document, "cell001"); titleCell.OfficeValueType = "string"; Paragraph titleParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(sheet.Document); FormatedText fText = new FormatedText(sheet.Document, "T1", title); fText.TextStyle.TextProperties.Bold = "bold"; fText.TextStyle.TextProperties.FontSize = "16pt"; if (reportKey == "RegistroAccessiPublish") { fText.TextStyle.TextProperties.Bold = String.Empty; titleCell.CellStyle.CellProperties.BackgroundColor = "#DDDDDD"; } titleParagraph.TextContent.Add(fText); titleCell.Content.Add(titleParagraph); sheet.Rows.Add(new Row(sheet)); sheet.Rows[0].Cells.Add(titleCell); }
/// <summary> /// Metodo per l'impostazione delle informazioni aggiuntive di un report /// </summary> /// <param name="additionalInformation"></param> /// <param name="sheet"></param> /// <param name="reportKey"></param> private void SetAdditionalInformation(String additionalInformation, Table sheet, String reportKey) { Cell addInfoCell = new Cell(sheet.Document, "cell002"); addInfoCell.OfficeValueType = "string"; Paragraph subTitleParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(sheet.Document); FormatedText fText = new FormatedText(sheet.Document, "T2", additionalInformation); fText.TextStyle.TextProperties.Bold = "bold"; fText.TextStyle.TextProperties.FontSize = "15pt"; if (reportKey == "RegistroAccessiPublish") { fText.TextStyle.TextProperties.Bold = String.Empty; addInfoCell.CellStyle.CellProperties.BackgroundColor = "#DDDDDD"; } subTitleParagraph.TextContent.Add(fText); addInfoCell.Content.Add(subTitleParagraph); sheet.Rows.Add(new Row(sheet)); sheet.Rows[2].Cells.Add(addInfoCell); }
public void BeginFrame() { var window = FlutterBinding.UI.Window.Instance; double devicePixelRatio = window.devicePixelRatio; var physicalSize = window.physicalSize; var logicalSize = physicalSize / devicePixelRatio; var paragraphBuilder = new ParagraphBuilder(new ParagraphStyle()); paragraphBuilder.addText("Hello, world!"); var paragraph = paragraphBuilder.build(); paragraph.layout(new ParagraphConstraints(width: logicalSize.width)); var physicalBounds = Offset.zero & physicalSize; var recorder = new PictureRecorder(); var canvas = new FlutterBinding.UI.Canvas(recorder, physicalBounds); canvas.scale((float)devicePixelRatio, (float)devicePixelRatio); canvas.drawParagraph(paragraph, new Offset( (logicalSize.width - paragraph.maxIntrinsicWidth) / 2.0, (logicalSize.height - paragraph.height) / 2.0 )); var picture = recorder.endRecording(); var sceneBuilder = new SceneBuilder(); sceneBuilder.pushClipRect(physicalBounds); sceneBuilder.addPicture(Offset.zero, picture); sceneBuilder.pop(); var scene = sceneBuilder.build(); var display = Windows.Graphics.Display.DisplayInformation.GetForCurrentView(); var _scale = display.LogicalDpi / 96.0f; window.render(scene); }
/// <summary> /// Metodo per l'aggiunta dell'header ad un foglio Excel /// </summary> /// <param name="header">Header da aggiungere</param> /// <param name="sheet">Foglio a cui aggiungere l'instestazione</param> private void AddHeaderRow(DocsPaVO.Report.HeaderColumnCollection header, Table sheet, String reportKey) { sheet.Rows.Add(new Row(sheet)); int actualRow = sheet.Rows.Count - 1; int actualCol = 0; foreach (var headerColumn in header) { Cell headerCell = new Cell(sheet.Document, "cell003"); headerCell.OfficeValueType = "string"; headerCell.CellStyle.CellProperties.Border = Border.HeavySolid; headerCell.CellStyle.CellProperties.BackgroundColor = "#D0B1A1"; Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(sheet.Document); FormatedText fText = new FormatedText(sheet.Document, "T3", headerColumn.ColumnName); fText.TextStyle.TextProperties.Bold = "bold"; fText.TextStyle.TextProperties.FontName = "Arial"; fText.TextStyle.TextProperties.FontSize = "11pt"; paragraph.TextContent.Add(fText); headerCell.Content.Add(paragraph); sheet.Rows[actualRow].Cells.Add(headerCell); if (reportKey == "RegistroAccessiPublish") { headerCell.CellStyle.CellProperties.BackgroundColor = String.Empty; fText.TextStyle.TextProperties.FontName = "ArialNarrow"; fText.TextStyle.TextProperties.FontColor = "#006699"; sheet.ColumnCollection[actualCol].ColumnStyle.ColumnProperties.Width = String.Format("{0}px", (headerColumn.ColumnSize * 2).ToString()); Cell titleCell = new Cell(sheet.Document, "cell001"); Cell subTitleCell = new Cell(sheet.Document, "cell002"); Cell addInfoCell = new Cell(sheet.Document, "cell000"); titleCell.CellStyle.CellProperties.BackgroundColor = "#DDDDDD"; subTitleCell.CellStyle.CellProperties.BackgroundColor = "#DDDDDD"; addInfoCell.CellStyle.CellProperties.BackgroundColor = "#DDDDDD"; sheet.Rows[0].Cells.Add(titleCell); sheet.Rows[1].Cells.Add(subTitleCell); sheet.Rows[2].Cells.Add(addInfoCell); } actualCol++; } }
/// <summary> /// Builds the illustration frame. /// </summary> /// <param name="document">The document.</param> /// <param name="frameStyleName">Name of the frame style.</param> /// <param name="graphicName">Name of the graphic.</param> /// <param name="pathToGraphic">The path to graphic.</param> /// <param name="illustrationText">The illustration text.</param> /// <param name="illustrationNumber">The illustration number.</param> /// <returns> /// A new Frame object containing a DrawTextBox which contains the /// illustration Graphic object and a text sequence representing /// the displayed illustration text. /// </returns> public static Frame BuildIllustrationFrame(IDocument document, string frameStyleName, string graphicName, string pathToGraphic, string illustrationText, int illustrationNumber) { DrawTextBox drawTextBox = new DrawTextBox(document); Frame frameTextBox = new Frame(document, frameStyleName); frameTextBox.DrawName = frameStyleName + "_" + graphicName; frameTextBox.ZIndex = "0"; Paragraph pIllustration = ParagraphBuilder.CreateStandardTextParagraph(document); pIllustration.StyleName = "Illustration"; Frame frame = new Frame(document, "InnerFrame_" + frameStyleName, graphicName, pathToGraphic); frame.ZIndex = "1"; pIllustration.Content.Add(frame); //add Illustration as text pIllustration.TextContent.Add(new SimpleText(document, "Illustration")); //add TextSequence TextSequence textSequence = new TextSequence(document); textSequence.Name = "Illustration"; textSequence.NumFormat = "1"; textSequence.RefName = "refIllustration" + illustrationNumber.ToString(); textSequence.Formula = "ooow:Illustration+1"; textSequence.TextContent.Add(new SimpleText(document, illustrationNumber.ToString())); pIllustration.TextContent.Add(textSequence); //add the ilustration text pIllustration.TextContent.Add(new SimpleText(document, illustrationText)); //add the Paragraph to the DrawTextBox drawTextBox.Content.Add(pIllustration); frameTextBox.SvgWidth = frame.SvgWidth; drawTextBox.MinWidth = frame.SvgWidth; drawTextBox.MinHeight = frame.SvgHeight; frameTextBox.Content.Add(drawTextBox); return(frameTextBox); }
public void CreateTableFormatedText() { //Create new spreadsheet document _spreadsheetDocument3 = new SpreadsheetDocument(); using (IPackageReader reader = new OnDiskPackageReader()) { _spreadsheetDocument3.Load(AARunMeFirstAndOnce.inPutFolder + @"blank.ods", new OpenDocumentImporter(reader)); } //Create a new table Table table = new Table(_spreadsheetDocument3, "First", "tablefirst"); table.Rows.Add(new Row(table)); //Create a new cell, without any extra styles Cell cell = table.CreateCell(); cell.OfficeValueType = "string"; //Set full border //cell.CellStyle.CellProperties.Border = Border.NormalSolid; //Add a paragraph to this cell Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph( _spreadsheetDocument3); //Create some Formated text FormatedText fText = new FormatedText(_spreadsheetDocument3, "T1", "Some Text"); //fText.TextStyle.TextProperties.Bold = "bold"; fText.TextStyle.TextProperties.Underline = LineStyles.dotted; //Add formated text paragraph.TextContent.Add(fText); //Add paragraph to the cell cell.Content.Add(paragraph); //Insert the cell at row index 2 and column index 3 //All need rows, columns and cells below the given //indexes will be build automatically. table.InsertCellAt(2, 3, cell); //Insert table into the spreadsheet document _spreadsheetDocument3.TableCollection.Add(table); // Test inserted content Object insertedText = ((Paragraph)_spreadsheetDocument3.TableCollection[0].Rows[2].Cells[3].Content[0]).TextContent[0]; Assert.AreEqual(fText, insertedText as FormatedText); }
public void HeaderAndFooterCreateTest() { TextDocument document = new TextDocument(); document.New(); // get default mast page layout TextMasterPage txtMP = document.TextMasterPageCollection.GetDefaultMasterPage(); // IMPORTANT: activating header and footer usage // has to be called before setting there layout properties! txtMP.ActivatePageHeaderAndFooter(); Console.WriteLine(txtMP.TextPageHeader.MarginLeft); // set page header layout // txtMP.TextPageHeader.MarginLeft = "4cm"; // // set text page layout // txtMP.TextPageLayout.MarginLeft = "6cm"; // // create a paragraph for the header Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document); // add some formated text // TODO: FIXME there is a bug with the text styles for header and footer! FormatedText formText = new FormatedText(document, "T1", "Some formated text in the page header ..."); formText.TextStyle.TextProperties.Bold = "bold"; paragraph.TextContent.Add(formText); // add this paragraph to the page header txtMP.TextPageHeader.ContentCollection.Add(paragraph); // create a paragraph collection with some text for the document // ParagraphCollection pColl = AODL.Document.Content.Text.ParagraphBuilder.CreateParagraphCollection( // document, // "Some text in here ... \n\n... with a modified master page :)", // true, // ParagraphBuilder.ParagraphSeperator); // // add the paragraphs // foreach(AODL.Document.Content.Text.Paragraph p in pColl) // document.Content.Add(p); // save the document using (IPackageWriter writer = new OnDiskPackageWriter()) { document.Save(AARunMeFirstAndOnce.outPutFolder + "text_master_page_1.odt", new OpenDocumentTextExporter(writer)); } }
/// <summary> /// /// </summary> /// <param name="subtitle"></param> public void SetSubtitle(String subtitle) { if (!title.Equals("")) { Cell sottoTitolo = new Cell(document, "cell002"); sottoTitolo.OfficeValueType = "string"; Paragraph sottoTitoloParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(document); FormatedText fText = new FormatedText(document, "T2", subtitle); fText.TextStyle.TextProperties.Bold = "bold"; fText.TextStyle.TextProperties.FontSize = "15pt"; sottoTitoloParagraph.TextContent.Add(fText); sottoTitolo.Content.Add(sottoTitoloParagraph); table.Rows.Add(new Row(table)); table.Rows[1].Cells.Add(sottoTitolo); currentRow++; } else { throw new Exception("Try to insert subtitle before title, please insert title first"); } }
public void FootnoteText() { //Create new TextDocument TextDocument document = new TextDocument(); document.New(); //Create a new Paragph Paragraph para = ParagraphBuilder.CreateStandardTextParagraph(document); //Create some simple Text para.TextContent.Add(new SimpleText(document, "Some simple text. And I have a footnode")); //Create a Footnote para.TextContent.Add(new Footnote(document, "Footer Text", "1", FootnoteType.Footnode)); //Add the paragraph document.Content.Add(para); //Save using (IPackageWriter writer = new OnDiskPackageWriter()) { document.Save(AARunMeFirstAndOnce.outPutFolder + "footnote.odt", new OpenDocumentTextExporter(writer)); } }
public void Add2GraphicsWithSameNameFromDifferentLocations() { string file1 = @"E:\fotos\schnee.jpg"; string file2 = @"E:\fotos\resize\schnee.jpg"; TextDocument textdocument = new TextDocument(); textdocument.New(); Paragraph p = ParagraphBuilder.CreateStandardTextParagraph(textdocument); Frame frame = new Frame(textdocument, "frame1", "graphic1", file1); p.Content.Add(frame); Paragraph p1 = ParagraphBuilder.CreateStandardTextParagraph(textdocument); Frame frame1 = new Frame(textdocument, "frame2", "graphic2", file2); p1.Content.Add(frame1); textdocument.Content.Add(p); textdocument.Content.Add(p1); textdocument.SaveTo(AARunMeFirstAndOnce.outPutFolder + "graphic.odt"); }
/// <summary> /// Metodo per l'aggiunta delle righe al report /// </summary> /// <param name="sheet">Foglio a cui aggiungere le righe</param> /// <param name="reportRows">Righe del report</param> private void AddReportData(Table sheet, DocsPaVO.Report.ReportMapRow reportRows) { foreach (var row in reportRows.Rows) { sheet.Rows.Add(new Row(sheet)); foreach (var column in row.Columns) { Cell columnItem = new Cell(sheet.Document, "cell004"); columnItem.OfficeValueType = "string"; columnItem.CellStyle.CellProperties.Border = Border.HeavySolid; Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(sheet.Document); FormatedText fText = new FormatedText(sheet.Document, "T4", column.Value); //fText.TextStyle.TextProperties.Bold = "bold"; fText.TextStyle.TextProperties.FontSize = "11pt"; paragraph.TextContent.Add(fText); columnItem.Content.Add(paragraph); int rowNum = sheet.Rows.Count - 1; sheet.Rows[rowNum].Cells.Add(columnItem); } } }
public void HeaderContentsTest1() { string file = AARunMeFirstAndOnce.inPutFolder + "pagestyles.odt"; TextDocument textDocument = new TextDocument(); textDocument.Load(file); TextMasterPage txtMP = textDocument.TextMasterPageCollection.GetDefaultMasterPage(); txtMP.ActivatePageHeaderAndFooter(); txtMP.TextPageHeader.MarginLeft = "4cm"; foreach (IContent iContent in txtMP.TextPageHeader.ContentCollection) { if (iContent is Paragraph) { Assert.IsNotNull(((Paragraph)iContent).MixedContent, "Must be mixed content available."); Assert.IsTrue(((Paragraph)iContent).MixedContent.Count > 0, "Must be mixed contents object inside."); Assert.IsTrue(((Paragraph)iContent).MixedContent[0] is SimpleText, "First IContent has to be type of SimpleText."); Assert.IsTrue(((Paragraph)iContent).MixedContent[1] is FormatedText, "Second IContent has to be type of FormatedText."); // Change the simple text string changeText = "Has changed "; SimpleText simpleText = ((Paragraph)iContent).MixedContent[0] as SimpleText; simpleText.Text = changeText; } else { Console.WriteLine(iContent.GetType().FullName); } } Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(textDocument); // add one extra Paragraph SimpleText extraText = new SimpleText(textDocument, "Some extra text..."); paragraph.TextContent.Add(extraText); txtMP.TextPageHeader.ContentCollection.Add(paragraph); textDocument.DocumentStyles.Styles.Save(AARunMeFirstAndOnce.outPutFolder + "pagestyles_changed.xml"); textDocument.SaveTo(AARunMeFirstAndOnce.outPutFolder + "pagestyles_changed.odt"); }
public void SimpleTableWithList() { //Create a new text document TextDocument document = new TextDocument(); document.New(); //Create a table for a text document using the TableBuilder Table table = TableBuilder.CreateTextDocumentTable( document, "table1", "table1", 3, 3, 16.99, false, false); //Create a bullet list List list = new List(document, "L1", ListStyles.Bullet, "L1P1"); //Create a list item ListItem lit = new ListItem(list); //Create a standard paragraph Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document); //Add some simple text paragraph.TextContent.Add(new SimpleText(document, "List item text")); //Add paragraph to the list item lit.Content.Add(paragraph); //Add item to the list list.Content.Add(lit); //Insert paragraph into the first cell table.Rows[0].Cells[0].Content.Add(list); //Add table to the document document.Content.Add(table); //Save the document using (IPackageWriter writer = new OnDiskPackageWriter()) { document.Save(AARunMeFirstAndOnce.outPutFolder + "simpleTableWithList.odt", new OpenDocumentTextExporter(writer)); } }
public void CreateSimpleTable() { //Create new spreadsheet document _spreadsheetDocument2 = new SpreadsheetDocument(); using (IPackageReader reader = new OnDiskPackageReader()) { _spreadsheetDocument2.Load(AARunMeFirstAndOnce.inPutFolder + @"blank.ods", new OpenDocumentImporter(reader)); } //Create a new table Table table = new Table(_spreadsheetDocument2, "First", "tablefirst"); table.Rows.Add(new Row(table)); //Create a new cell, without any extra styles Cell cell = new Cell(_spreadsheetDocument2, "cell001"); cell.OfficeValueType = "string"; //Set full border cell.CellStyle.CellProperties.Border = Border.NormalSolid; //Add a paragraph to this cell Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph( _spreadsheetDocument2); //Add some text content String cellText = "Some text"; paragraph.TextContent.Add(new SimpleText(_spreadsheetDocument2, cellText)); //Add paragraph to the cell cell.Content.Add(paragraph); //Insert the cell at row index 2 and column index 3 //All need rows, columns and cells below the given //indexes will be build automatically. table.InsertCellAt(1, 1, cell); //Insert table into the spreadsheet document _spreadsheetDocument2.TableCollection.Add(table); // Test inserted content Assert.AreEqual(_spreadsheetDocument2.TableCollection[0], table); String text = _spreadsheetDocument2.TableCollection[0].Rows[1].Cells[1].Node.Value; Assert.AreEqual(text, cellText); }
public void SimpleTableWithMergedCells() { //Create a new text document TextDocument document = new TextDocument(); document.New(); //Create a table for a text document using the TableBuilder Table table = TableBuilder.CreateTextDocumentTable( document, "table1", "table1", 3, 3, 16.99, false, false); //Fill first all tables foreach (Row row in table.Rows) { foreach (Cell cell in row.Cells) { //Create a standard paragraph Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document); //Add some simple text paragraph.TextContent.Add(new SimpleText(document, "Cell text")); cell.Content.Add(paragraph); } } //Merge some cells. Notice this is only available in text documents! table.Rows[1].MergeCells(document, 1, 2, true); //Add table to the document document.Content.Add(table); //Save the document using (IPackageWriter writer = new OnDiskPackageWriter()) { document.Save(AARunMeFirstAndOnce.outPutFolder + "simpleTableWithMergedCells.odt", new OpenDocumentTextExporter(writer)); } }
public void CreateNewDocumentAndDoAPrintOut() { string fileToPrint = AARunMeFirstAndOnce.outPutFolder + "fileToPrint.odt"; //Create a new text document TextDocument document = new TextDocument(); document.New(); //Create a standard paragraph using the ParagraphBuilder Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document); //Add some simple text paragraph.TextContent.Add(new SimpleText(document, "Some simple text!")); //Add the paragraph to the document document.Content.Add(paragraph); //Save empty using (IPackageWriter writer = new OnDiskPackageWriter()) { document.Save(fileToPrint, new OpenDocumentTextExporter(writer)); } //Now print the new document via the OpenOfficeLib //Get the Component Context XComponentContext xComponentContext = Connector.GetComponentContext(); //Get a MultiServiceFactory XMultiServiceFactory xMultiServiceFactory = Connector.GetMultiServiceFactory(xComponentContext); //Get a Dektop instance XDesktop xDesktop = Connector.GetDesktop(xMultiServiceFactory); //Convert a windows path to an OpenOffice one fileToPrint = Component.PathConverter(fileToPrint); //Load the document you want to print XComponent xComponent = Component.LoadDocument( (XComponentLoader)xDesktop, fileToPrint, "_blank"); //Print the XComponent Printer.Print(xComponent); }
/// <summary> /// First Row of data must contains columns' names /// </summary> /// <param name="data"></param> public void SetData(DataSet data) { int dataRows = 0; if (data.Tables[0].Rows[0] != null) { SetColumnsName(data.Tables[0].Rows[0]); foreach (DataRow row in data.Tables[0].Rows) { if (dataRows != 0) { table.Rows.Add(new Row(table)); foreach (String columnName in row.ItemArray) { Cell columnItem = new Cell(document, "cell004"); columnItem.OfficeValueType = "string"; columnItem.CellStyle.CellProperties.Border = Border.HeavySolid; //columnItem.CellStyle.CellProperties.BackgroundColor = "#D0B1A1"; Paragraph titoloParagraph = ParagraphBuilder.CreateSpreadsheetParagraph(document); FormatedText fText = new FormatedText(document, "T4", columnName); fText.TextStyle.TextProperties.Bold = "bold"; fText.TextStyle.TextProperties.FontSize = "10pt"; titoloParagraph.TextContent.Add(fText); columnItem.Content.Add(titoloParagraph); table.Rows[currentRow].Cells.Add(columnItem); } currentRow++; } dataRows++; } } else { throw new Exception("Columns' names not found"); } }
public void ImageMapTest() { TextDocument document = new TextDocument(); document.New(); //Create standard paragraph Paragraph paragraphOuter = ParagraphBuilder.CreateStandardTextParagraph(document); //Create the frame with graphic Frame frame = new Frame(document, "frame1", "graphic1", new DiskFile(_imagefile)); //Create a Draw Area Rectangle DrawAreaRectangle drawAreaRec = new DrawAreaRectangle( document, "0cm", "0cm", "1.5cm", "2.5cm", null); drawAreaRec.Href = "http://OpenDocument4all.com"; //Create a Draw Area Circle DrawAreaCircle drawAreaCircle = new DrawAreaCircle( document, "4cm", "4cm", "1.5cm", null); drawAreaCircle.Href = "http://AODL.OpenDocument4all.com"; DrawArea[] drawArea = new DrawArea[2] { drawAreaRec, drawAreaCircle }; //Create a Image Map ImageMap imageMap = new ImageMap(document, drawArea); //Add Image Map to the frame frame.Content.Add(imageMap); //Add frame to paragraph paragraphOuter.Content.Add(frame); //Add paragraph to document document.Content.Add(paragraphOuter); //Save the document using (IPackageWriter writer = new OnDiskPackageWriter()) { document.Save(AARunMeFirstAndOnce.outPutFolder + "simpleImageMap.odt", new OpenDocumentTextExporter(writer)); } }
public void Add2GraphicsWithSameNameFromDifferentLocations() { string file1 = _imagefile; //@"E:\fotos\schnee.jpg"; string file2 = _imagefile; //@"E:\fotos\resize\schnee.jpg"; TextDocument textdocument = new TextDocument(); textdocument.New(); Paragraph p = ParagraphBuilder.CreateStandardTextParagraph(textdocument); Frame frame = new Frame(textdocument, "frame1", "graphic1", new DiskFile(file1)); p.Content.Add(frame); Paragraph p1 = ParagraphBuilder.CreateStandardTextParagraph(textdocument); Frame frame1 = new Frame(textdocument, "frame2", "graphic2", new DiskFile(file2)); p1.Content.Add(frame1); textdocument.Content.Add(p); textdocument.Content.Add(p1); using (IPackageWriter writer = new OnDiskPackageWriter()) { textdocument.Save(AARunMeFirstAndOnce.outPutFolder + "graphic.odt", new OpenDocumentTextExporter(writer)); } }
public void Phrase_Make() { // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int) Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); XmlNode paraDef0 = pb.ParagraphDefinition.CloneNode(true); XmlNode paraDef_afterJoin1_2; pb.ParseParagraph(); // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola [xxxhesyla xxxnihimbilira]. xxxpus xxxyalola xxxnihimbilira tapb.MergeAdjacentAnnotations(1, 2, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); }
public void Phrase_MakeAndBreak_UndoRedo() { CheckDisposed(); // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); WordformInventory wfi = m_fdoCache.LangProject.WordformInventoryOA as WordformInventory; ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); XmlNode paraDef0 = pb.ParagraphDefinition.CloneNode(true); XmlNode paraDef_afterJoin1_2; using (new UndoRedoTaskHelper(Cache, "Phrase_MakeAndBreak_UndoRedo_Join", "Phrase_MakeAndBreak_UndoRedo_Join")) { // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola [xxxhesyla xxxnihimbilira]. xxxpus xxxyalola xxxnihimbilira tapb.MergeAdjacentAnnotations(1, 2, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); paraDef_afterJoin1_2 = pb.ParagraphDefinition.CloneNode(true) ; } UndoResult ures; Cache.Undo(out ures); WordformInventory.OnChangedWordformsOC(); pb.ParagraphDefinition = paraDef0; pb.ParseParagraph(false, false, false); tapb.ValidateAnnotations(); Cache.Redo(out ures); WordformInventory.OnChangedWordformsOC(); pb.ParagraphDefinition = paraDef_afterJoin1_2; pb.ParseParagraph(false, false, false); tapb.ValidateAnnotations(); paraDef_afterJoin1_2 = pb.ParagraphDefinition.CloneNode(true); XmlNode paraDef_afterBreak1_2; using (new UndoRedoTaskHelper(Cache, "Phrase_MakeAndBreak_UndoRedo_Break", "Phrase_MakeAndBreak_UndoRedo_Break")) { // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola /xxxhesyla/ /xxxnihimbilira/. xxxpus xxxyalola xxxnihimbilira secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(1, 2, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); paraDef_afterBreak1_2 = pb.ParagraphDefinition.CloneNode(true); } Cache.Undo(out ures); WordformInventory.OnChangedWordformsOC(); pb.ParagraphDefinition = paraDef_afterJoin1_2; pb.ParseParagraph(false, false, false); tapb.ValidateAnnotations(); Cache.Redo(out ures); WordformInventory.OnChangedWordformsOC(); pb.ParagraphDefinition = paraDef_afterBreak1_2; pb.ParseParagraph(false, false, false); tapb.ValidateAnnotations(); }
public void NoAnalyses_SimpleEdits_MultipleWritingSystemsParagraph() { ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MultipleWritingSystems); // verify that our wfics point to wordforms in the expected wss. pb.ParseParagraph(); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); FdoValidator.ValidateCbaWordToBaselineWord(tapb, 0, 0); //FdoValidator.ValidateCbaWordToBaselineWord(tapb, 0, 1); // currently considered punctuation. //FdoValidator.ValidateCbaWordToBaselineWord(tapb, 1, 0); // french word considered punctuation. //FdoValidator.ValidateCbaWordToBaselineWord(tapb, 1, 1); // eng word considered punctuation // FdoValidator.ValidateCbaWordToBaselineWord(tapb, 1, 4); // german word considered punctuation. // validate the rest tapb.ValidateAnnotations(); // xxxpus xxes xxxnihimbilira. xxfr xxen xxxnihimbilira xxxpus xxde. xxkal xxkal xxxxhesyla xxxxhesyla. // xxkal: German (de) -- occurrence 0 // xxkal: Kalaba (xkal) -- occurrence 1 Dictionary<string, int> expectedOccurrences = pb.ExpectedWordformsAndOccurrences; CheckExpectedWordformsAndOccurrences(pb.ActualParagraph, expectedOccurrences); // replace the german occurrence of "xxkal" with a xkal version. int wsDe; FdoValidator.GetTssStringValue(tapb, 2, 0, out wsDe); int wsVernDef = Cache.DefaultVernWs; Assert.AreNotEqual(wsVernDef, wsDe, "Precondition: did not expect to have a default vern ws."); pb.ReplaceSegmentForm(2, 0, "xxkal", wsVernDef); var segformNode = pb.SegmentFormNode(2, 0); // Now it should parse as a wfic. var linkNode = segformNode.SelectSingleNode("AnnotationType34/Link"); linkNode.Attributes["guid"].Value = ParagraphBuilder.WficGuid; linkNode.Attributes["name"].Value = "Wordform In Context"; expectedOccurrences.Remove("xxkal" + wsDe.ToString()); expectedOccurrences["xxkal" + wsVernDef.ToString()] += 1; pb.RebuildParagraphContentFromAnnotations(true); pb.ParseParagraph(); int wsAnalysis2_0; FdoValidator.GetTssStringValue(tapb, 2, 0, out wsAnalysis2_0); Assert.AreEqual(Cache.DefaultVernWs, wsAnalysis2_0, "Precondition: expected to have default vern ws."); FdoValidator.ValidateCbaWordToBaselineWord(tapb, 2, 0); // validate the rest. tapb.ValidateAnnotations(); CheckExpectedWordformsAndOccurrences(pb.ActualParagraph, expectedOccurrences); }
public void SparseAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms_RemoveSegment_LT5376() { // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); pb.ParseParagraph(); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); tapb.SetDefaultWordGloss("xxxyalola", 0); // gloss first occurrence. tapb.ValidateAnnotations(); // Remove first sentence containing 'xxxyalola'; its annotation should be removed. pb.RemoveSegment(0); pb.RebuildParagraphContentFromAnnotations(); pb.ParseParagraph(); tapb.ValidateAnnotations(); }
public void SparseAnalyses_NoEdits_MixedCaseWordformsParagraph() { // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MixedCases); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); // set the corresponding annotations to lowercase wordforms. IWfiWordform wf_xxxpus0_0 = tapb.SetAlternateCase("Xxxpus", 0, StringCaseStatus.allLower); IWfiWordform wf_xxxnihimbilira1_0 = tapb.SetAlternateCase("Xxxnihimbilira", 0, StringCaseStatus.allLower); IWfiWordform wf_xxxhesyla2_0 = tapb.SetAlternateCase("Xxxhesyla", 0, StringCaseStatus.allLower); IWfiWordform wf_xxxnihimbilira2_1 = tapb.SetAlternateCase("XXXNIHIMBILIRA", 0, StringCaseStatus.allLower); pb.ParseParagraph(); Assert.AreEqual(wf_xxxpus0_0, tapb.GetAnalysis(0, 0)); Assert.AreEqual(wf_xxxnihimbilira1_0, tapb.GetAnalysis(1, 0)); Assert.AreEqual(wf_xxxhesyla2_0, tapb.GetAnalysis(2, 0)); Assert.AreEqual(wf_xxxnihimbilira2_1, tapb.GetAnalysis(2, 1)); tapb.ValidateAnnotations(); }
public void Phrase_SimpleEdits_LT6244() { // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); // first do a basic phrase (without secondary phrases (guesses)) // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola [xxxhesyla xxxnihimbilira]. xxxpus xxxyalola xxxnihimbilira tapb.MergeAdjacentAnnotations(1, 2, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(true); // edit the second word in the phrase. pb.ReplaceSegmentForm("xxxhesyla xxxnihimbilira", 0, "xxxhesyla xxxra"); pb.BreakPhraseAnnotation(1, 2); // this edit should break the phrase back into words. tapb.ValidateAnnotations(); }
public void FindExampleSentences() { // Make some analyses linked to the same LexSense. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); ParagraphParser.ParseParagraph(pb.ActualParagraph); // Create a new lexical entry and sense. int clsidForm; string formLexEntry = "xnihimbilira"; var morphTypeRepository = Cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>(); var rootMorphType = morphTypeRepository. GetObject(MoMorphTypeTags.kguidMorphRoot); ITsString tssLexEntryForm = TsStringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs); var entryFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>(); ILexEntry xnihimbilira_Entry = entryFactory.Create(rootMorphType, tssLexEntryForm, "xnihimbilira.sense1", null); ILexSense xnihimbilira_Sense1 = xnihimbilira_Entry.SensesOS[0]; var senseFactory = Cache.ServiceLocator.GetInstance<ILexSenseFactory>(); ILexSense xnihimbilira_Sense2 = senseFactory.Create(xnihimbilira_Entry, null, "xnihimbilira.sense2"); //<!--xxxpus xxxyalola xxxnihimbilira. xxxnihimbilira xxxpus xxxyalola. xxxhesyla xxxnihimbilira.--> ArrayList moForms = new ArrayList(); moForms.Add("xx"); moForms.Add(xnihimbilira_Entry.LexemeFormOA); // 1. Establish first analysis with Sense1 IWfiAnalysis wfiAnalysis1 = tapb.BreakIntoMorphs(1, 0, moForms); tapb.SetMorphSense(1, 0, 1, xnihimbilira_Sense1); Assert.That(xnihimbilira_Sense1.ReferringObjects, Has.Count.EqualTo(1)); Assert.That(xnihimbilira_Sense2.ReferringObjects, Has.Count.EqualTo(0)); IWfiAnalysis waCba1_0 = pb.ActualParagraph.SegmentsOS[1].AnalysesRS[0] as IWfiAnalysis; Assert.IsNotNull(waCba1_0, String.Format("Unexpected class({0}) of Analysis({1}) for cba0.", pb.ActualParagraph.SegmentsOS[0].AnalysesRS[2].GetType(), pb.ActualParagraph.SegmentsOS[0].AnalysesRS[2].Hvo)); Assert.AreEqual(xnihimbilira_Sense1, waCba1_0.MorphBundlesOS[1].SenseRA); Assert.That(waCba1_0.ReferringObjects, Has.Count.EqualTo(1)); // one ref to the analysis (from segment 0) var wordform = (IWfiWordform)waCba1_0.Owner; Assert.That(wordform.FullConcordanceCount, Is.EqualTo(3)); // unchanged even though one is now an analysis // 2. Establish word gloss on the existing analysis. string wordGloss1; tapb.SetDefaultWordGloss(2, 1, wfiAnalysis1, out wordGloss1); Assert.That(wordform.FullConcordanceCount, Is.EqualTo(3)); // analysis and gloss and unchanged wordform all count var wgCba2_1 = pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1] as IWfiGloss; Assert.IsNotNull(wgCba2_1, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba1.", pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].GetType(), pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].Hvo)); var waCba2_1 = wgCba2_1.Owner as IWfiAnalysis; Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba2_1.MorphBundlesOS[1].SenseRA.Hvo); // 3. establish a new analysis with Sense1. IWfiAnalysis wfiAnalysis2 = tapb.BreakIntoMorphs(0, 2, moForms); // xxxnihimbilira (first occurrence) tapb.SetMorphSense(0, 2, 1, xnihimbilira_Sense1); Assert.That(wordform.FullConcordanceCount, Is.EqualTo(3)); var waCba0_2 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[2] as IWfiAnalysis; Assert.IsNotNull(waCba0_2, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].GetType(), pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].Hvo)); Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba0_2.MorphBundlesOS[1].SenseRA.Hvo); Assert.That(xnihimbilira_Sense1.ReferringObjects, Has.Count.EqualTo(2)); Assert.That(xnihimbilira_Sense2.ReferringObjects, Has.Count.EqualTo(0)); // 4. change an existing sense to sense2. tapb.SetMorphSense(0, 2, 1, xnihimbilira_Sense2); Assert.That(xnihimbilira_Sense1.ReferringObjects, Has.Count.EqualTo(1)); Assert.That(xnihimbilira_Sense2.ReferringObjects, Has.Count.EqualTo(1)); waCba0_2 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[2] as IWfiAnalysis; Assert.IsNotNull(waCba0_2, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].GetType(), pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].Hvo)); Assert.AreEqual(xnihimbilira_Sense2, waCba0_2.MorphBundlesOS[1].SenseRA); // do multiple occurrences of the same sense in the same segment. IWfiAnalysis wfiAnalysis3 = tapb.BreakIntoMorphs(0, 0, moForms); // break xxxpus into xx xnihimbilira (for fun). tapb.SetMorphSense(0, 0, 1, xnihimbilira_Sense2); Assert.That(xnihimbilira_Sense2.ReferringObjects, Has.Count.EqualTo(2)); // reparse paragraph and make sure important stuff doesn't change tapb.ReparseParagraph(); Assert.That(xnihimbilira_Sense1.ReferringObjects, Has.Count.EqualTo(1)); Assert.That(xnihimbilira_Sense2.ReferringObjects, Has.Count.EqualTo(2)); }
public void SegmentInitialUppercaseWordMatchesLowercaseWordform() { // prepopulate lowercase Wordforms new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara).ParseParagraph(); // Build and parse paragraph var pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MixedCases); var tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); // Verify WF's are reused across case iff appropriate: Assert.AreEqual( tapb.GetAnalysis(0, 0), tapb.GetAnalysis(1, 1), "Initial Xxxpus should have been interpreted as sentence case"); Assert.AreNotEqual(tapb.GetAnalysis(0, 1), tapb.GetAnalysis(1, 2), "Mid-sentence Xxxyalola should not match lowercase WF"); Assert.AreNotEqual(tapb.GetAnalysis(0, 2), tapb.GetAnalysis(1, 0), "Congratulations! You fixed it! Please Assert.AreEqual with this message: xxxnihimbilira should have been reused for segment initial."); Assert.AreNotEqual(tapb.GetAnalysis(0, 2), tapb.GetAnalysis(2, 1), "XXXNIHIMBILIRA should have been given its own all-caps WF"); }
internal ParagraphAnnotatorForParagraphBuilder(ParagraphBuilder pb) : base(pb.ActualParagraph) { m_pb = pb; }
public void FindExampleSentences() { // Make some analyses linked to the same LexSense. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); // Create a new lexical entry and sense. int clsidForm; string formLexEntry = "xnihimbilira"; ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs); ILexEntry xnihimbilira_Entry = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "xnihimbilira.sense1", null); ILexSense xnihimbilira_Sense1 = xnihimbilira_Entry.SensesOS[0]; ILexSense xnihimbilira_Sense2 = LexSense.CreateSense(xnihimbilira_Entry, null, "xnihimbilira.sense2"); //<!--xxxpus xxxyalola xxxnihimbilira. xxxnihimbilira xxxpus xxxyalola. xxxhesyla xxxnihimbilira.--> ArrayList moForms = new ArrayList(); moForms.Add("xx"); moForms.Add(xnihimbilira_Entry.LexemeFormOA); // 1. Establish first analysis with Sense1 IWfiAnalysis wfiAnalysis1 = tapb.BreakIntoMorphs(1, 0, moForms); tapb.SetMorphSense(1, 0, 1, xnihimbilira_Sense1); List<int> instancesInTwfics_Sense1 = (xnihimbilira_Sense1 as LexSense).InstancesInTwfics; List<int> instancesInTwfics_Sense2 = (xnihimbilira_Sense2 as LexSense).InstancesInTwfics; Assert.AreEqual(1, instancesInTwfics_Sense1.Count, String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense1.Gloss.AnalysisDefaultWritingSystem)); Assert.AreEqual(0, instancesInTwfics_Sense2.Count, String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense2.Gloss.AnalysisDefaultWritingSystem)); StTxtPara.TwficInfo infoCba1_0 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense1[0]); Assert.AreEqual(pb.ActualParagraph.Hvo, infoCba1_0.Object.BeginObjectRAHvo); Assert.AreEqual(1, infoCba1_0.SegmentIndex, String.Format("Unexpected index of segment '{0}'", infoCba1_0.SegmentHvo)); WfiAnalysis waCba1_0 = infoCba1_0.Object.InstanceOfRA as WfiAnalysis; Assert.IsNotNull(waCba1_0, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", infoCba1_0.Object.InstanceOfRA.ClassID, infoCba1_0.Object.InstanceOfRAHvo)); Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba1_0.MorphBundlesOS[1].SenseRAHvo); // get the segment information for the twfics. List<int> segments_Sense1 = StTxtPara.TwficSegments(Cache, instancesInTwfics_Sense1); Assert.AreEqual(1, segments_Sense1.Count, "Unexpected number of senses for twfics."); Assert.AreEqual(infoCba1_0.SegmentHvo, segments_Sense1[0], "Unexpected segment hvo."); // 2. Establish word gloss on the existing analysis. string wordGloss1; tapb.SetDefaultWordGloss(2, 1, wfiAnalysis1, out wordGloss1); instancesInTwfics_Sense1 = (xnihimbilira_Sense1 as LexSense).InstancesInTwfics; Assert.AreEqual(2, instancesInTwfics_Sense1.Count, String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense1.Gloss.AnalysisDefaultWritingSystem)); infoCba1_0 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense1[0]); Assert.AreEqual(pb.ActualParagraph.Hvo, infoCba1_0.Object.BeginObjectRAHvo); Assert.AreEqual(1, infoCba1_0.SegmentIndex, String.Format("Unexpected index of segment '{0}'", infoCba1_0.SegmentHvo)); StTxtPara.TwficInfo infoCba2_1 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense1[1]); Assert.AreEqual(pb.ActualParagraph.Hvo, infoCba2_1.Object.BeginObjectRAHvo); Assert.AreEqual(2, infoCba2_1.SegmentIndex, String.Format("Unexpected index of segment '{0}'", infoCba2_1.SegmentHvo)); waCba1_0 = infoCba1_0.Object.InstanceOfRA as WfiAnalysis; Assert.IsNotNull(waCba1_0, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", infoCba1_0.Object.InstanceOfRA.ClassID, infoCba1_0.Object.InstanceOfRAHvo)); Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba1_0.MorphBundlesOS[1].SenseRAHvo); WfiGloss wgCba2_1 = infoCba2_1.Object.InstanceOfRA as WfiGloss; Assert.IsNotNull(wgCba2_1, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba1.", infoCba2_1.Object.InstanceOfRA.ClassID, infoCba2_1.Object.InstanceOfRAHvo)); WfiAnalysis waCba2_1 = WfiAnalysis.CreateFromDBObject(Cache, wgCba2_1.OwnerHVO) as WfiAnalysis; Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba2_1.MorphBundlesOS[1].SenseRAHvo); segments_Sense1 = StTxtPara.TwficSegments(Cache, instancesInTwfics_Sense1); Assert.AreEqual(2, segments_Sense1.Count, "Unexpected number of senses for twfics."); Assert.AreEqual(infoCba1_0.SegmentHvo, segments_Sense1[0], "Unexpected segment hvo."); Assert.AreEqual(infoCba2_1.SegmentHvo, segments_Sense1[1], "Unexpected segment hvo."); // 3. establish a new analysis with Sense1. IWfiAnalysis wfiAnalysis2 = tapb.BreakIntoMorphs(0, 2, moForms); // xxxnihimbilira (first occurrence) tapb.SetMorphSense(0, 2, 1, xnihimbilira_Sense1); instancesInTwfics_Sense1 = (xnihimbilira_Sense1 as LexSense).InstancesInTwfics; Assert.AreEqual(3, instancesInTwfics_Sense1.Count, String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense1.Gloss.AnalysisDefaultWritingSystem)); StTxtPara.TwficInfo infoCba0_2 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense1[0]); Assert.AreEqual(pb.ActualParagraph.Hvo, infoCba0_2.Object.BeginObjectRAHvo); Assert.AreEqual(0, infoCba0_2.SegmentIndex, String.Format("Unexpected index of segment '{0}'", infoCba0_2.SegmentHvo)); WfiAnalysis waCba0_2 = infoCba0_2.Object.InstanceOfRA as WfiAnalysis; Assert.IsNotNull(waCba0_2, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", infoCba0_2.Object.InstanceOfRA.ClassID, infoCba0_2.Object.InstanceOfRAHvo)); Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba0_2.MorphBundlesOS[1].SenseRAHvo); segments_Sense1 = StTxtPara.TwficSegments(Cache, instancesInTwfics_Sense1); Assert.AreEqual(3, segments_Sense1.Count, "Unexpected number of senses for twfics."); Assert.AreEqual(infoCba0_2.SegmentHvo, segments_Sense1[0], "Unexpected segment hvo."); Assert.AreEqual(infoCba1_0.SegmentHvo, segments_Sense1[1], "Unexpected segment hvo."); Assert.AreEqual(infoCba2_1.SegmentHvo, segments_Sense1[2], "Unexpected segment hvo."); // 4. change an existing sense to sense2. tapb.SetMorphSense(0, 2, 1, xnihimbilira_Sense2); instancesInTwfics_Sense1 = (xnihimbilira_Sense1 as LexSense).InstancesInTwfics; Assert.AreEqual(2, instancesInTwfics_Sense1.Count, String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense1.Gloss.AnalysisDefaultWritingSystem)); instancesInTwfics_Sense2 = (xnihimbilira_Sense2 as LexSense).InstancesInTwfics; Assert.AreEqual(1, instancesInTwfics_Sense2.Count, String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense2.Gloss.AnalysisDefaultWritingSystem)); infoCba0_2 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense2[0]); Assert.AreEqual(pb.ActualParagraph.Hvo, infoCba0_2.Object.BeginObjectRAHvo); Assert.AreEqual(0, infoCba0_2.SegmentIndex, String.Format("Unexpected index of segment '{0}'", infoCba0_2.SegmentHvo)); waCba0_2 = infoCba0_2.Object.InstanceOfRA as WfiAnalysis; Assert.IsNotNull(waCba0_2, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", infoCba0_2.Object.InstanceOfRA.ClassID, infoCba0_2.Object.InstanceOfRAHvo)); Assert.AreEqual(xnihimbilira_Sense2.Hvo, waCba0_2.MorphBundlesOS[1].SenseRAHvo); // do multiple occurrences of the same sense in the same segment. IWfiAnalysis wfiAnalysis3 = tapb.BreakIntoMorphs(0, 0, moForms); // break xxxpus into xx xnihimbilira (for fun). tapb.SetMorphSense(0, 0, 1, xnihimbilira_Sense2); instancesInTwfics_Sense2 = (xnihimbilira_Sense2 as LexSense).InstancesInTwfics; Assert.AreEqual(2, instancesInTwfics_Sense2.Count, String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense2.Gloss.AnalysisDefaultWritingSystem)); StTxtPara.TwficInfo infoCba0_0 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense2[0]); // reparse paragraph to convert all segments with real analyses to real ones. tapb.ReparseParagraph(); infoCba0_0.ReloadInfo(); infoCba0_2.ReloadInfo(); infoCba1_0.ReloadInfo(); infoCba2_1.ReloadInfo(); List<int> segments_Sense2 = StTxtPara.TwficSegments(Cache, instancesInTwfics_Sense2); Assert.AreEqual(2, segments_Sense2.Count, "Unexpected number of senses for twfics."); Assert.AreEqual(infoCba0_0.SegmentHvo, segments_Sense2[0], "Unexpected segment hvo."); Assert.AreEqual(infoCba0_2.SegmentHvo, segments_Sense2[1], "Unexpected segment hvo."); // Load free form annotations for segments Sense 2. Set<int> analWsIds = new Set<int>(Cache.LangProject.AnalysisWssRC.HvoArray); StTxtPara.LoadSegmentFreeformAnnotationData(Cache, new Set<int>(segments_Sense2), analWsIds); int tagSegFF = StTxtPara.SegmentFreeformAnnotationsFlid(Cache); int[] segFFs = Cache.GetVectorProperty(infoCba0_0.SegmentHvo, tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 0 should not have any freeform annotations."); StTxtPara.LoadSegmentFreeformAnnotationData(Cache, pb.ActualParagraph.Hvo, analWsIds); segFFs = Cache.GetVectorProperty(infoCba0_0.SegmentHvo, tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 0 should not have any freeform annotations."); segFFs = Cache.GetVectorProperty(infoCba1_0.SegmentHvo, tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 1 should not have any freeform annotations."); segFFs = Cache.GetVectorProperty(infoCba2_1.SegmentHvo, tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 2 should not have any freeform annotations."); // Try adding some freeform translations int segDefn_literalTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation); int segDefn_freeTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation); BaseFreeformAdder ffAdder = new BaseFreeformAdder(Cache); ICmIndirectAnnotation freeTrans0 = ffAdder.AddFreeformAnnotation(infoCba0_0.SegmentHvo, segDefn_freeTranslation); freeTrans0.Comment.SetAlternative("Segment0: Freeform translation.", Cache.DefaultAnalWs); ICmIndirectAnnotation literalTrans0 = ffAdder.AddFreeformAnnotation(infoCba0_0.SegmentHvo, segDefn_literalTranslation); literalTrans0.Comment.SetAlternative("Segment0: Literal translation.", Cache.DefaultAnalWs); // see if we can load this into the cache. StTxtPara.LoadSegmentFreeformAnnotationData(Cache, new Set<int>(segments_Sense2), analWsIds); segFFs = Cache.GetVectorProperty(infoCba0_0.SegmentHvo, tagSegFF, true); Assert.AreEqual(2, segFFs.Length, "Segment 0 should have freeform annotations."); Assert.AreEqual(segFFs[0], freeTrans0.Hvo, "Segment 0 Freeform translation id."); Assert.AreEqual(segFFs[1], literalTrans0.Hvo, "Segment 0 Literal translation id."); StTxtPara.LoadSegmentFreeformAnnotationData(Cache, pb.ActualParagraph.Hvo, analWsIds); segFFs = Cache.GetVectorProperty(infoCba0_0.SegmentHvo, tagSegFF, true); Assert.AreEqual(2, segFFs.Length, "Segment 0 should have freeform annotations."); Assert.AreEqual(segFFs[0], freeTrans0.Hvo, "Segment 0 Freeform translation id."); Assert.AreEqual(segFFs[1], literalTrans0.Hvo, "Segment 0 Literal translation id."); segFFs = Cache.GetVectorProperty(infoCba1_0.SegmentHvo, tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 1 should not have any freeform annotations."); segFFs = Cache.GetVectorProperty(infoCba2_1.SegmentHvo, tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 2 should not have any freeform annotations."); }
public void SparseTwficAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms() { CheckDisposed(); // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); tapb.SetDefaultWordGloss("xxxyalola", 0); // gloss first occurrence. tapb.SetDefaultWordGloss("xxxpus", 1); // gloss second occurrence. tapb.SetDefaultWordGloss("xxxnihimbilira", 2); // gloss third occurrence. tapb.ValidateAnnotations(); // Replace some occurrences of these wordforms from the text to validate the analysis does not show up on the wrong occurrence. // Remove the first occurrence of 'xxxnihimbilira'; the second occurrence should have the gloss. pb.ReplaceSegmentForm("xxxnihimbilira", 0, ""); pb.RebuildParagraphContentFromAnnotations(); tapb.ValidateAnnotations(); // Remove first occurrence of 'xxxpus'; the next one should still have the gloss. pb.ReplaceSegmentForm("xxxpus", 0, ""); pb.RebuildParagraphContentFromAnnotations(); tapb.ValidateAnnotations(); //SparseTwficAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms_RemoveSegment_LT5376() //SparseTwficAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms_AddWhitespace_LT5313() }
public void SparseSegmentAnalyses_FreeformAnnotations_LT7318() { // Make some analyses linked to the same LexSense. //<!--xxxpus xxxyalola xxxnihimbilira. xxxnihimbilira xxxpus xxxyalola. xxxhesyla xxxnihimbilira.--> ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); List<int> segments = (pb.ActualParagraph as StTxtPara).Segments; Assert.AreEqual(3, segments.Count, "Unexpected number of senses."); // Verify that each of these segments are dummy Assert.IsTrue(Cache.IsDummyObject(segments[0]), "Expected dummy segment."); Assert.IsTrue(Cache.IsDummyObject(segments[1]), "Expected dummy segment."); Assert.IsTrue(Cache.IsDummyObject(segments[2]), "Expected dummy segment."); // Load free form annotations for segments. shouldn't have any. Set<int> analWsIds = new Set<int>(Cache.LangProject.AnalysisWssRC.HvoArray); StTxtPara.LoadSegmentFreeformAnnotationData(Cache, new Set<int>(segments), analWsIds); int tagSegFF = StTxtPara.SegmentFreeformAnnotationsFlid(Cache); int[] segFFs = Cache.GetVectorProperty(segments[0], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 0 should not have any freeform annotations."); StTxtPara.LoadSegmentFreeformAnnotationData(Cache, pb.ActualParagraph.Hvo, analWsIds); segFFs = Cache.GetVectorProperty(segments[1], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 1 should not have any freeform annotations."); segFFs = Cache.GetVectorProperty(segments[2], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 2 should not have any freeform annotations."); // convert the third segment to a real, in preparation for adding the annotation. ICmBaseAnnotation cbaReal = CmBaseAnnotation.ConvertBaseAnnotationToReal(m_fdoCache, segments[2]); segments = (pb.ActualParagraph as StTxtPara).Segments; Assert.IsTrue(!Cache.IsDummyObject(segments[2]), "Expected real segment."); // Try adding some freeform translations to third segment. int segDefn_literalTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation); int segDefn_freeTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation); BaseFreeformAdder ffAdder = new BaseFreeformAdder(Cache); ICmIndirectAnnotation freeTrans0 = ffAdder.AddFreeformAnnotation(segments[2], segDefn_freeTranslation); freeTrans0.Comment.SetAlternative("Segment2: Freeform translation.", Cache.DefaultAnalWs); ICmIndirectAnnotation literalTrans0 = ffAdder.AddFreeformAnnotation(segments[2], segDefn_literalTranslation); literalTrans0.Comment.SetAlternative("Segment2: Literal translation.", Cache.DefaultAnalWs); // see if we can load this into the cache. StTxtPara.LoadSegmentFreeformAnnotationData(Cache, new Set<int>(segments), analWsIds); segFFs = Cache.GetVectorProperty(segments[2], tagSegFF, true); Assert.AreEqual(2, segFFs.Length, "Segment 2 should have freeform annotations."); Assert.AreEqual(segFFs[0], freeTrans0.Hvo, "Segment 2 Freeform translation id."); Assert.AreEqual(segFFs[1], literalTrans0.Hvo, "Segment 2 Literal translation id."); // make sure the other segments don't have freeform annotations. segFFs = Cache.GetVectorProperty(segments[0], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 0 should not have any freeform annotations."); StTxtPara.LoadSegmentFreeformAnnotationData(Cache, pb.ActualParagraph.Hvo, analWsIds); segFFs = Cache.GetVectorProperty(segments[1], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 1 should not have any freeform annotations."); // reparse the paragraph and make sure nothing changed. ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); tapb.ReparseParagraph(); segments = (pb.ActualParagraph as StTxtPara).Segments; StTxtPara.LoadSegmentFreeformAnnotationData(Cache, new Set<int>(segments), analWsIds); segFFs = Cache.GetVectorProperty(segments[2], tagSegFF, true); Assert.AreEqual(2, segFFs.Length, "Segment 2 should have freeform annotations."); Assert.AreEqual(segFFs[0], freeTrans0.Hvo, "Segment 2 Freeform translation id."); Assert.AreEqual(segFFs[1], literalTrans0.Hvo, "Segment 2 Literal translation id."); // make sure the other segments don't have freeform annotations. segFFs = Cache.GetVectorProperty(segments[0], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 0 should not have any freeform annotations."); StTxtPara.LoadSegmentFreeformAnnotationData(Cache, pb.ActualParagraph.Hvo, analWsIds); segFFs = Cache.GetVectorProperty(segments[1], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 1 should not have any freeform annotations."); }
//[Ignore("FWC-16: this test causes NUnit to hang in fixture teardown - need more investigation")] public void Phrase_MakeAndBreak() { CheckDisposed(); // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); // first do a basic phrase (without secondary phrases (guesses)) and break it // [xxxpus xxxyalola] xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(true); // \xxxpus\ \xxxyalola\ xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(true); // make phrases with secondary phrases (guesses). // [xxxpus xxxyalola] xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); secondaryPathsToJoinWords.Add(new int[2] { 1, 0 }); // {xxxpus xxxyalola} xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // then check that the last phrase has been properly annotated. tapb.ValidateAnnotations(); // [xxxpus xxxyalola xxxnihimbilira]. xxxpus xxxyalola xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira}. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); secondaryPathsToBreakPhrases.Add(new int[2] { 1, 0 }); // \xxxpus\ \xxxyalola\ xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {{xxxpus xxxyalola} xxxnihimbilira} tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // [xxxpus xxxyalola xxxnihimbilira]. [xxxpus xxxyalola] xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira} secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.MergeAdjacentAnnotations(1, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // 2. Break Phrases. // [xxxpus xxxyalola xxxnihimbilira]. \xxxpus\ \xxxyalola\ xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira} secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(1, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); // [\xxxpus\ \xxxyalola\ \xxxnihimbilira\]. xxxpus xxxyalola xxxhesyla xxxnihimbilira. {\xxxpus\ \xxxyalola\ \xxxnihimbilira\} secondaryPathsToBreakPhrases.Clear(); secondaryPathsToBreakPhrases.Add(new int[2] { 2, 0 }); // {\xxxpus\ \xxxyalola\ \xxxnihimbilira\} tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); // gloss the second occurrence of xxxyalola and check that we don't overwrite it with a secondary guess. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira tapb.SetDefaultWordGloss("xxxyalola", 1); secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // reparse so that we can 'confirm' "xxxpus xxxyalola" phrase. tapb.SetDefaultWordGloss("xxxpus xxxyalola", 0); // 'confirm' this merge. tapb.ValidateAnnotations(); // join the last occurrence of 'xxxpus xxxyalola xxxnihimbilira' // and check that we don't overwrite the first join of 'xxxpus xxxyalola' with a secondary guess. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. [xxxpus xxxyalola xxxnihimbilira] tapb.MergeAdjacentAnnotations(2, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // reparse so that we can 'confirm' "xxxpus xxxyalola xxxnihimbilira" phrase. tapb.SetDefaultWordGloss("xxxpus xxxyalola xxxnihimbilira", 0); // 'confirm' this merge. tapb.ValidateAnnotations(); // make sure we can break our analysis. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. {\xxxpus\ \xxxyalola\} \xxxnihimbilira\ secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.BreakPhrase(2, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, "xxxpus xxxyalola"); tapb.ValidateAnnotations(); }
public void LT7974_Phrase_MakeAndBreak() { CheckDisposed(); // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); // go ahead and parse the text generating real wordforms to be more like a real user situation (LT-7974) // and reset the concordance to simulate the situation where the user hasn't loaded ConcordanceWords yet. (Cache.LangProject.WordformInventoryOA as WordformInventory).ResetConcordanceWordformsAndOccurrences(); bool fDidParse; (m_text1.ContentsOA as StText).LastParsedTimestamp = 0; ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse); pb.ResyncExpectedAnnotationIds(); // first do a basic phrase (without secondary phrases (guesses)), which should not delete "xxxpus" or "xxxyalola" // since they occur later in the text. // [xxxpus xxxyalola] xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira int hvoCba1_0 = tapb.GetSegmentForm(1, 0); // second xxxpus int hvoCba1_1 = tapb.GetSegmentForm(1, 1); // second xxxyalola ICmBaseAnnotation cba1_0 = new CmBaseAnnotation(Cache, hvoCba1_0); ICmBaseAnnotation cba1_1 = new CmBaseAnnotation(Cache, hvoCba1_1); IWfiWordform wf1 = cba1_0.InstanceOfRA as WfiWordform; IWfiWordform wf2 = cba1_0.InstanceOfRA as WfiWordform; tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // after the merge, make sure the wordforms for xxxpus and xxxyalola are still valid Assert.IsTrue(wf1.IsValidObject(), "expected xxxpus to still be valid"); Assert.IsTrue(wf2.IsValidObject(), "expected xxxyalola to still be valid"); tapb.ValidateAnnotations(true); // now break the phrase and make sure we delete this wordform, b/c it is not occurring elsewhere (Cache.LangProject.WordformInventoryOA as WordformInventory).ResetConcordanceWordformsAndOccurrences(); pb.ResyncExpectedAnnotationIds(); // \xxxpus\ \xxxyalola\ xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira int hvoCba0_0 = tapb.GetSegmentForm(0, 0); // xxxpus xxxyalola ICmBaseAnnotation cba0_0 = new CmBaseAnnotation(Cache, hvoCba0_0); IWfiWordform wf3 = cba0_0.InstanceOfRA as WfiWordform; secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsFalse(wf3.IsValidObject(), "expected 'xxxpus xxxyalola' to be deleted."); tapb.ValidateAnnotations(true); // rejoin the first phrase, parse the text, and break the first phrase // [xxxpus xxxyalola] xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira secondaryPathsToJoinWords.Add(new int[2] { 1, 0 }); // {xxxpus xxxyalola} xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); hvoCba0_0 = tapb.GetSegmentForm(0, 0); // xxxpus xxxyalola cba0_0 = new CmBaseAnnotation(Cache, hvoCba0_0); wf1 = cba0_0.InstanceOfRA as WfiWordform; tapb.ReparseParagraph(); // just break the new phrase (and the leave existing guesses) // \xxxpus\ \xxxyalola\ xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira (Cache.LangProject.WordformInventoryOA as WordformInventory).ResetConcordanceWordformsAndOccurrences(); secondaryPathsToJoinWords.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsTrue(wf1.IsValidObject(), "expected 'xxxpus xxxyalola' to still be valid"); tapb.ValidateAnnotations(true); // xxxpus xxxyalola xxxnihimbilira. \xxxpus\ \xxxyalola\ xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira tapb.BreakPhrase(1, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsTrue(wf1.IsValidObject(), "expected 'xxxpus xxxyalola' to still be valid"); tapb.ValidateAnnotations(true); // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. \xxxpus\ \xxxyalola\ xxxnihimbilira tapb.BreakPhrase(2, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsFalse(wf1.IsValidObject(), "expected 'xxxpus xxxyalola' to be deleted"); tapb.ValidateAnnotations(true); // now do two joins, the second resulting in deletion of a wordform. // xxxpus xxxyalola xxxnihimbilira. xxxpus [xxxyalola xxxhesyla] xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira // xxxpus xxxyalola xxxnihimbilira. xxxpus [xxxyalola xxxhesyla xxxnihimbilira]. xxxpus xxxyalola xxxnihimbilira (Cache.LangProject.WordformInventoryOA as WordformInventory).ResetConcordanceWordformsAndOccurrences(); (m_text1.ContentsOA as StText).LastParsedTimestamp = 0; ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse); pb.ResyncExpectedAnnotationIds(); tapb.MergeAdjacentAnnotations(1, 1, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); hvoCba1_1 = tapb.GetSegmentForm(1, 1); // xxxyalola xxxhesyla cba1_1 = new CmBaseAnnotation(Cache, hvoCba1_1); IWfiWordform wf4 = cba1_1.InstanceOfRA as WfiWordform; tapb.MergeAdjacentAnnotations(1, 1, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // this merge should have deleted 'xxxyalola xxxhesyla' Assert.IsFalse(wf4.IsValidObject(), "expected 'xxxyalola xxxhesyla' to be deleted."); tapb.ValidateAnnotations(true); }
public void LT7974_Phrase_MakeAndBreak() { // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); //Thist test proved to be incapable of being Undone, since further tests relied on state this test affected //the following two variables duplicate member variables to isolate changes to this test. XmlDocument donTouchIt = new XmlDocument(); IText noLoToque = LoadTestText( Path.Combine("FDO", Path.Combine("FDOTests", Path.Combine("TestData", "ParagraphParserTestTexts.xml"))), 1, donTouchIt); ParagraphBuilder pb = new ParagraphBuilder(donTouchIt, noLoToque, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); // go ahead and parse the text generating real wordforms to be more like a real user situation (LT-7974) // and reset the concordance to simulate the situation where the user hasn't loaded ConcordanceWords yet. ParagraphParser.ParseText(noLoToque.ContentsOA); pb.ResyncExpectedAnnotationIds(); // first do a basic phrase (without secondary phrases (guesses)), which should not delete "xxxpus" or "xxxyalola" // since they occur later in the text. // [xxxpus xxxyalola] xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira IWfiWordform wf1 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[0].Wordform; IWfiWordform wf2 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[1].Wordform; tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // after the merge, make sure the wordforms for xxxpus and xxxyalola are still valid Assert.IsTrue(wf1.IsValidObject, "expected xxxpus to still be valid"); Assert.IsTrue(wf2.IsValidObject, "expected xxxyalola to still be valid"); tapb.ValidateAnnotations(true); // now break the phrase and make sure we delete this wordform, b/c it is not occurring elsewhere pb.ResyncExpectedAnnotationIds(); // \xxxpus\ \xxxyalola\ xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira IWfiWordform wf3 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[0].Wordform; secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsFalse(wf3.IsValidObject, "expected 'xxxpus xxxyalola' to be deleted."); tapb.ValidateAnnotations(true); // rejoin the first phrase, parse the text, and break the first phrase // [xxxpus xxxyalola] xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira secondaryPathsToJoinWords.Add(new int[2] { 1, 0 }); // {xxxpus xxxyalola} xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); wf1 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[0].Wordform; tapb.ReparseParagraph(); // just break the new phrase (and the leave existing guesses) // \xxxpus\ \xxxyalola\ xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira secondaryPathsToJoinWords.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsTrue(wf1.IsValidObject, "expected 'xxxpus xxxyalola' to still be valid"); tapb.ValidateAnnotations(true); // xxxpus xxxyalola xxxnihimbilira. \xxxpus\ \xxxyalola\ xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira tapb.BreakPhrase(1, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsTrue(wf1.IsValidObject, "expected 'xxxpus xxxyalola' to still be valid"); tapb.ValidateAnnotations(true); // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. \xxxpus\ \xxxyalola\ xxxnihimbilira tapb.BreakPhrase(2, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsFalse(wf1.IsValidObject, "expected 'xxxpus xxxyalola' to be deleted"); tapb.ValidateAnnotations(true); // now do two joins, the second resulting in deletion of a wordform. // xxxpus xxxyalola xxxnihimbilira. xxxpus [xxxyalola xxxhesyla] xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira // xxxpus xxxyalola xxxnihimbilira. xxxpus [xxxyalola xxxhesyla xxxnihimbilira]. xxxpus xxxyalola xxxnihimbilira ParagraphParser.ParseText(noLoToque.ContentsOA); pb.ResyncExpectedAnnotationIds(); tapb.MergeAdjacentAnnotations(1, 1, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); IWfiWordform wf4 = pb.ActualParagraph.SegmentsOS[1].AnalysesRS[1].Wordform; tapb.MergeAdjacentAnnotations(1, 1, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // this merge should have deleted 'xxxyalola xxxhesyla' Assert.IsFalse(wf4.IsValidObject, "expected 'xxxyalola xxxhesyla' to be deleted."); tapb.ValidateAnnotations(true); }
public void SparseTwficAnalyses_NoEdits_MixedCaseWordformsParagraph() { CheckDisposed(); // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MixedCases); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); tapb.ValidateAnnotations(); // set the corresponding annotations to lowercase wordforms. tapb.SetAlternateCase("Xxxpus", 0, StringCaseStatus.allLower); tapb.SetAlternateCase("Xxxnihimbilira", 0, StringCaseStatus.allLower); tapb.SetAlternateCase("Xxxhesyla", 0, StringCaseStatus.allLower); tapb.SetAlternateCase("XXXNIHIMBILIRA", 0, StringCaseStatus.allLower); tapb.ValidateAnnotations(); }
//[Ignore("FWC-16: this test causes NUnit to hang in fixture teardown - need more investigation")] public void Phrase_MakeAndBreak() { // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); // first do a basic phrase (without secondary phrases (guesses)) and break it // [xxxpus xxxyalola] xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(true); // \xxxpus\ \xxxyalola\ xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(true); // make phrases with secondary phrases (guesses). // [xxxpus xxxyalola] xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); secondaryPathsToJoinWords.Add(new int[2] { 1, 0 }); // {xxxpus xxxyalola} xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // then check that the last phrase has been properly annotated. tapb.ValidateAnnotations(); // JohnT: in 6.0, making the larger phrase would apparently get rid of the guessed phrase. // in 7.0+ there's no distinction between a guess and user-made phrase, so once it exists it doesn't go away. // [xxxpus xxxyalola xxxnihimbilira]. [xxxpus xxxyalola] xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira}. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // 7.0+ secondaryPathsToBreakPhrases.Add(new int[2] { 1, 0 }); // \xxxpus\ \xxxyalola\ xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {{xxxpus xxxyalola} xxxnihimbilira} tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // [xxxpus xxxyalola xxxnihimbilira]. [xxxpus xxxyalola] xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira} // 7.0+ nothing to do here; it's in this state after the previous change. //secondaryPathsToJoinWords.Clear(); //secondaryPathsToBreakPhrases.Clear(); //tapb.MergeAdjacentAnnotations(1, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); //tapb.ValidateAnnotations(); // 2. Break Phrases. // [xxxpus xxxyalola xxxnihimbilira]. \xxxpus\ \xxxyalola\ xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira} secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(1, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); // [\xxxpus\ \xxxyalola\ \xxxnihimbilira\]. xxxpus xxxyalola xxxhesyla xxxnihimbilira. {\xxxpus\ \xxxyalola\ \xxxnihimbilira\} secondaryPathsToBreakPhrases.Clear(); // 7.0+ secondaryPathsToBreakPhrases.Add(new int[2] { 2, 0 }); // {\xxxpus\ \xxxyalola\ \xxxnihimbilira\} tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); // 7.0+ breaking the guessed phrase has to be an extra step. tapb.BreakPhrase(2, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); // gloss the second occurrence of xxxyalola and check that we don't overwrite it with a secondary guess. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira tapb.SetDefaultWordGloss("xxxyalola", 1); secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // reparse so that we can 'confirm' "xxxpus xxxyalola" phrase. tapb.SetDefaultWordGloss("xxxpus xxxyalola", 0); // 'confirm' this merge. tapb.ValidateAnnotations(); // join the last occurrence of 'xxxpus xxxyalola xxxnihimbilira' // and check that we don't overwrite the first join of 'xxxpus xxxyalola' with a secondary guess. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. [xxxpus xxxyalola xxxnihimbilira] tapb.MergeAdjacentAnnotations(2, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // reparse so that we can 'confirm' "xxxpus xxxyalola xxxnihimbilira" phrase. tapb.SetDefaultWordGloss("xxxpus xxxyalola xxxnihimbilira", 0); // 'confirm' this merge. tapb.ValidateAnnotations(); // make sure we can break our analysis. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. {\xxxpus\ \xxxyalola\} \xxxnihimbilira\ // In 6.0, apparently we would re-guess the shorter pus yalola phrase. In 7.0+, breaking a phrase does not // produce a new parse and new phrase guesses. Otherwise, if the longer phrase still existed somewhere else, // it would be guessed again! Don't see how this ever worked right, except that after breaking the phrase the // user would usually annotate the parts before there was occasion to re-parse. // 7.0+ secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.BreakPhrase(2, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, "xxxpus xxxyalola"); tapb.ValidateAnnotations(); }
/// <summary> /// /// </summary> /// <param name="para"></param> /// <param name="startingNodeToMoveToNewPara"></param> /// <returns>the XmlNode corresponding to the new paragraph defn</returns> internal XmlNode InsertParagraphBreak(IStTxtPara para, XmlNode startingNodeToMoveToNewPara) { // IStTxtPara/Segments/CmBaseAnnotation[] ParagraphBuilder pb = GetParagraphBuilder(para); // make a new paragraph node after the current one if (pb.ParagraphDefinition != null) { XmlNode newParaDefn = InsertNewParagraphDefn(pb.ParagraphDefinition); ParagraphBuilder pbNew = new ParagraphBuilder(m_cache, m_text.ContentsOA.ParagraphsOS, newParaDefn); // if we are breaking at a segment form, create new segment and move the rest of the segment forms XmlNode startingSegNode = null; if (startingNodeToMoveToNewPara.ParentNode.Name == "SegmentForms37") { pbNew.CreateSegmentNode(); XmlNode newSegForms = pbNew.CreateSegmentForms(); MoveSiblingNodes(startingNodeToMoveToNewPara, newSegForms, null); // get the next segment if any. int iSeg = XmlUtils.GetIndexAmongSiblings(startingNodeToMoveToNewPara.ParentNode.ParentNode); List<XmlNode> segmentNodes = pb.SegmentNodes(); startingSegNode = segmentNodes[iSeg].NextSibling; } else { Debug.Assert(startingNodeToMoveToNewPara.ParentNode.Name == "Segments16"); startingSegNode = startingNodeToMoveToNewPara; } if (startingSegNode != null) { // move all the remaining segments beginning at startingSegNode into the new paragraph. MoveSiblingNodes(startingSegNode, pbNew.ParagraphDefinition.LastChild, null); } return pbNew.ParagraphDefinition; } return null; }
public void SparseSegmentAnalyses_FreeformAnnotations_LT7318() { // Make some analyses linked to the same LexSense. //<!--xxxpus xxxyalola xxxnihimbilira. xxxnihimbilira xxxpus xxxyalola. xxxhesyla xxxnihimbilira.--> ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); var segments = pb.ActualParagraph.SegmentsOS; Assert.AreEqual(3, segments.Count, "Unexpected number of senses."); // Load free form annotations for segments. shouldn't have any. Assert.That(segments[0].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); Assert.That(segments[1].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); Assert.That(segments[2].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); // Try adding some freeform translations to third segment. segments[2].FreeTranslation.AnalysisDefaultWritingSystem = Cache.TsStrFactory.MakeString("Segment2: Freeform translation.", Cache.DefaultAnalWs); segments[2].LiteralTranslation.AnalysisDefaultWritingSystem = Cache.TsStrFactory.MakeString("Segment2: Literal translation.", Cache.DefaultAnalWs); // make sure the other segments don't have freeform annotations. Assert.That(segments[0].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); Assert.That(segments[1].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); // reparse the paragraph and make sure nothing changed. ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); tapb.ReparseParagraph(); segments = (pb.ActualParagraph as IStTxtPara).SegmentsOS; Assert.That(segments[0].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); Assert.That(segments[1].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); Assert.That(segments[2].FreeTranslation.AnalysisDefaultWritingSystem.Text, Is.EqualTo("Segment2: Freeform translation.")); Assert.That(segments[2].LiteralTranslation.AnalysisDefaultWritingSystem.Text, Is.EqualTo("Segment2: Literal translation.")); }
public void NoAnalyses_NoEdits( [Values(Text1ParaIndex.EmptyParagraph, Text1ParaIndex.SimpleSegmentPara, Text1ParaIndex.ComplexPunctuations, Text1ParaIndex.MixedCases, Text1ParaIndex.MultipleWritingSystems)] Text1ParaIndex paraIdx) { var pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)paraIdx); var tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); tapb.ValidateAnnotations(); }
public void SparseAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms() { // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); IWfiGloss gloss_xxxyalola0_1 = tapb.SetDefaultWordGloss("xxxyalola", 0); // gloss first occurrence. IWfiGloss gloss_xxxpus1_1 = tapb.SetDefaultWordGloss("xxxpus", 1); // gloss second occurrence. IWfiGloss gloss_xxxnihimbilira2_1 = tapb.SetDefaultWordGloss("xxxnihimbilira", 2); // gloss third occurrence. pb.ParseParagraph(); var actualAnalysis_xxxyalola0_1 = tapb.GetAnalysis(0, 1); var actualAnalysis_xxxpus1_1 = tapb.GetAnalysis(1, 1); var actualAnalysis_xxxnihimbilira2_1 = tapb.GetAnalysis(2, 1); Assert.AreEqual(gloss_xxxyalola0_1, actualAnalysis_xxxyalola0_1); Assert.AreEqual(gloss_xxxpus1_1, actualAnalysis_xxxpus1_1); Assert.AreEqual(gloss_xxxnihimbilira2_1, actualAnalysis_xxxnihimbilira2_1); // verify the rest tapb.ValidateAnnotations(); // Replace some occurrences of these wordforms from the text to validate the analysis does not show up on the wrong occurrence. // Remove the first occurrence of 'xxxnihimbilira'; the (newly) second occurrence should still have the gloss. pb.ReplaceSegmentForm("xxxnihimbilira", 0, ""); pb.RebuildParagraphContentFromAnnotations(); pb.ParseParagraph(); actualAnalysis_xxxnihimbilira2_1 = tapb.GetAnalysis(2, 1); Assert.AreEqual(gloss_xxxnihimbilira2_1, actualAnalysis_xxxnihimbilira2_1); tapb.ValidateAnnotations(); // Remove first occurrence of 'xxxpus'; the next one should still have the gloss. pb.ReplaceSegmentForm("xxxpus", 0, ""); pb.RebuildParagraphContentFromAnnotations(); pb.ParseParagraph(); actualAnalysis_xxxpus1_1 = tapb.GetAnalysis(1, 1); Assert.AreEqual(gloss_xxxpus1_1, actualAnalysis_xxxpus1_1); tapb.ValidateAnnotations(); }
public void NoAnalyses_NoEdits_PhraseWordforms() { // 1. Setup Tests with a basic phrase ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int) Text1ParaIndex.PhraseWordforms); // first do a basic phrase (without secondary phrases (guesses)) // xxxpus xxxyalola xxxnihimbilira. [xxxpus xxxyalola] xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira pb.MergeAdjacentAnnotations(1, 0); // generate mock ids pb.RebuildParagraphContentFromAnnotations(); // now produce a guess to establish the phrase annotation. var tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); pb.ActualParagraph.SegmentsOS[1].AnalysesRS.RemoveAt(0); // delete "xxxpus" // now replace "xxxyalola" with the new phrase form "xxxpus xxxyalola" IAnalysis beforeParse_phrase1_0 = pb.ExportCbaNodeToReal(1, 0); //string gloss; //IWfiGloss wg_phrase1_0 = tapb.SetDefaultWordGloss(1, 0, out gloss); // NOTE: Precondition checks to make sure we set up the annotation properly // The real test: now parse and verify that we maintained the expected result for the phrase annotation. pb.ParseParagraph(); var afterParse_actualWordform = tapb.GetAnalysis(1, 0); Assert.AreEqual(beforeParse_phrase1_0, afterParse_actualWordform, "word mismatch"); // verify the rest. tapb.ValidateAnnotations(); }
public void SparseAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms_AddWhitespace_LT5313() { // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); pb.ParseParagraph(); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); string gloss; var gloss0_1 = tapb.SetDefaultWordGloss(0, 1, out gloss); // xxxyalola 1 var gloss1_1 = tapb.SetDefaultWordGloss(1, 1, out gloss); // xxxpus 2 var gloss2_1 = tapb.SetDefaultWordGloss(2, 1, out gloss); // xxxnihimbilira 3 tapb.ValidateAnnotations(); // precondition testing. // Append whitespace in the text, and see if the analyses still show up in the right place // (cf. LT-5313). pb.ReplaceTrailingWhitepace(0, 0, 1); pb.RebuildParagraphContentFromAnnotations(); pb.ParseParagraph(); Assert.AreEqual(gloss0_1, tapb.GetAnalysis(0, 1)); Assert.AreEqual(gloss1_1, tapb.GetAnalysis(1, 1)); Assert.AreEqual(gloss2_1, tapb.GetAnalysis(2, 1)); tapb.ValidateAnnotations(); }
public void NoAnalyses_NoEdits_MultipleWritingSystemsParagraph_LT5379() { var pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MultipleWritingSystems); var tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); tapb.ValidateAnnotations(); }
public void SparseAnalyses_NoEdits_SimpleSegmentParagraph() { // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); string gloss; IWfiGloss gloss_xxxyalola1_2 = tapb.SetDefaultWordGloss(1, 2, out gloss); IWfiGloss gloss_xxxnihimbilira2_1 = tapb.SetDefaultWordGloss(2, 1, out gloss); // now parse through the text and make sure our two glosses are maintained. pb.ParseParagraph(); Assert.AreEqual(gloss_xxxyalola1_2, tapb.GetAnalysis(1, 2)); Assert.AreEqual(gloss_xxxnihimbilira2_1, tapb.GetAnalysis(2, 1)); // validate the rest of the stuff. tapb.ValidateAnnotations(); }
public void NoAnalyses_SimpleEdits_MultipleWritingSystemsParagraph() { CheckDisposed(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MultipleWritingSystems); pb.ParseParagraph(true, true); // xxxpus xxes xxxnihimbilira. xxfr xxen xxxnihimbilira xxxpus xxde. xxkal xxkal xxxxhesyla xxxxhesyla. // xxkal: German (de) -- occurrence 0 // xxkal: Kalaba (xkal) -- occurrence 1 Dictionary<string, int> expectedOccurrences = pb.ExpectedWordformsAndOccurrences; WordformInventory wfi = Cache.LangProject.WordformInventoryOA as WordformInventory; CheckExpectedWordformsAndOccurrences(wfi, expectedOccurrences); // replace the german occurrence of "xxkal" with a xkal version. int hvoSeg2 = pb.ActualParagraph.Segments[2]; int hvoSegForm2_0 = pb.ActualParagraph.SegmentForms(hvoSeg2)[0]; StTxtPara.TwficInfo ti2_0 = new StTxtPara.TwficInfo(Cache, hvoSegForm2_0); int wsDe = StringUtils.GetWsAtOffset(pb.ActualParagraph.Contents.UnderlyingTsString, ti2_0.Object.BeginOffset); int wsVernDef = Cache.DefaultVernWs; Assert.AreNotEqual(wsVernDef, wsDe, "did not expect to have a default vern ws."); pb.ReplaceSegmentForm(2, 0, "xxkal", wsVernDef); expectedOccurrences.Remove("xxkal" + wsDe.ToString()); expectedOccurrences["xxkal" + wsVernDef.ToString()] += 1; pb.RebuildParagraphContentFromAnnotations(true, true); CheckExpectedWordformsAndOccurrences(wfi, expectedOccurrences); }
internal ConceptualModelXmlParagraphValidator(ParagraphBuilder pb) : base (pb.ActualParagraph) { m_pb = pb; }
internal FDO.IText BuildText(XmlNode textDefn) { if (textDefn.Name != "Text") return null; m_textDefn = textDefn; // 1. Create the new text and give it an owner. m_text = this.CreateText(); textDefn.Attributes["id"].Value = m_text.Hvo.ToString(); XmlNode name = textDefn.SelectSingleNode("Name5/AUni"); // 2. If we have a name, set it. if (name != null && name.InnerText.Length > 0) { string wsAbbr = XmlUtils.GetOptionalAttributeValue(name, "ws"); int ws = 0; if (wsAbbr != null) ws = m_cache.ServiceLocator.WritingSystemManager.GetWsFromStr(wsAbbr); if (ws == 0) ws = m_cache.DefaultVernWs; this.SetName(name.InnerText, ws); } // 3. Create a body for the text; XmlNode contents = textDefn.SelectSingleNode("Contents5054/StText"); if (contents == null) return m_text; IStText body = this.CreateContents(m_text); // 4. Create each paragraph for the text. XmlNodeList paragraphs = contents.SelectNodes("Paragraphs14/StTxtPara"); if (paragraphs != null) { foreach (XmlNode paraDef in paragraphs) { ParagraphBuilder pb = new ParagraphBuilder(m_cache, m_text.ContentsOA.ParagraphsOS); IStTxtPara realPara = pb.BuildParagraphContent(paraDef); } } return m_text; }
/// <summary> /// /// </summary> /// <param name="paragraphDefnToInsertAfter"></param> /// <returns></returns> public IStTxtPara InsertNewParagraphAfter(XmlNode paragraphDefnToInsertAfter) { ParagraphBuilder pb = new ParagraphBuilder(m_cache, m_text.ContentsOA.ParagraphsOS); IStTxtPara newPara = null; if (m_textDefn != null) { // Append insert a new paragraph node. XmlElement newParaDefn = InsertNewParagraphDefn(paragraphDefnToInsertAfter); newPara = pb.CreateNewParagraph(newParaDefn); } else { newPara = pb.AppendParagraph(); } return newPara; }
public void SparseTwficAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms_AddWhitespace_LT5313() { CheckDisposed(); // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); tapb.SetDefaultWordGloss("xxxyalola", 0); // gloss first occurrence. tapb.SetDefaultWordGloss("xxxpus", 1); // gloss second occurrence. tapb.SetDefaultWordGloss("xxxnihimbilira", 2); // gloss third occurrence. tapb.ValidateAnnotations(); // Append whitespace in the text, and see if the analyses still show up in the right place // (cf. LT-5313). pb.ReplaceTrailingWhitepace(0, 0, 1); pb.RebuildParagraphContentFromAnnotations(); tapb.ValidateAnnotations(); }