Exemple #1
0
        //overload that takes string[]
        public static void EncodeTextFile(string saveFileName, HeaderInformation info,
                                          string[] paragraphs, bool tagPunctuation)
        {
            //creating xml file
            xmlWriter = new XmlTextWriter(saveFileName, Encoding.UTF8);

            //starting the document (intro)
            WriteDocIntro(saveFileName);

            //process header
            EncodeHeader(info);

            //process text
            xmlWriter.WriteStartElement("text");  //<text>
            xmlWriter.WriteStartElement("group"); //<group>
            xmlWriter.WriteStartElement("body");  //<body>

            EncodeSentencesOrParagraphs(paragraphs, tagPunctuation, false);

            xmlWriter.WriteEndElement(); //closing <body>
            xmlWriter.WriteEndElement(); //closing <group>
            xmlWriter.WriteEndElement(); //closing <text>

            //ending the document (outro)
            xmlWriter.WriteEndElement();//closing <TEI.2>
            xmlWriter.Close();
        }
        //overload that takes string[]
        public static void EncodeTextFile(string saveFileName, HeaderInformation info,
           string[] paragraphs, bool tagPunctuation)
        {
            //creating xml file
            xmlWriter = new XmlTextWriter(saveFileName, Encoding.UTF8);

            //starting the document (intro)
            WriteDocIntro(saveFileName);

            //process header
            EncodeHeader(info);

            //process text
            xmlWriter.WriteStartElement("text"); //<text>
            xmlWriter.WriteStartElement("group"); //<group>
            xmlWriter.WriteStartElement("body"); //<body>

            EncodeSentencesOrParagraphs(paragraphs, tagPunctuation, false);

            xmlWriter.WriteEndElement();//closing <body>
            xmlWriter.WriteEndElement();//closing <group>
            xmlWriter.WriteEndElement();//closing <text>

            //ending the document (outro)
            xmlWriter.WriteEndElement();//closing <TEI.2>
            xmlWriter.Close();
        }
Exemple #3
0
        private void btnEncode_Click(object sender, EventArgs e)
        {
            //null, emptyString and whiteSpace check
            if (string.IsNullOrWhiteSpace(InputBox.Text))
            {
                MessageBox.Show("There is no text.", "Text Encoder", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //creating error tracking variable
            bool resultOK = true;

            // creating save dialog
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = ".xml File|*.xml";
            dialog.Title = "Save XML file";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                //packing all text description info into one class
                HeaderInformation info = new HeaderInformation
                {
                    //page1 -- TitleStmt and PubStmt
                    Author = textBoxAuthor.Text,
                    Title = textBoxTitle.Text,
                    Publisher = textBoxPublisher.Text,
                    PublishDate = textBoxDate.Text,
                    PublishAddress = textBoxAddress.Text,
                    Distributor = textBoxDistr.Text,
                    PublisherPlace = textBoxPublisherPlace.Text,

                    //page2 -- sourceDesc
                    BiblCitation = textBoxBiblCitation.Text,
                    TitleSrc = textBoxTitleSrc.Text,
                    AuthorSrc = textBoxAuthorSrc.Text,
                    EditionSrc = textBoxEditionSrc.Text,
                    Analytic = textBoxAnalytic.Text,
                    DateSrc = textBoxDateSrc.Text
                };

                try
                {
                    if (checkBoxSentences.Checked)
                    {
                        //if sentence encoding is included
                        //text is spitted to paragraphs and sentences
                        List<string[]> paragraphsNSentences = SimpleTextSplitter.SplitToParagraphsWithSentences(InputBox.Text);

                        //then encoded using first overload ( List<string[]> )
                        XmlEncoder.EncodeTextFile(dialog.FileName, info, paragraphsNSentences, checkBoxPunc.Checked);
                    }
                    else
                    {
                        //usual split
                        string[] paragraphs = InputBox.Text.Split(new string[] { " \n", "\n", }, StringSplitOptions.RemoveEmptyEntries);

                        //encoded using second overload ( string[] )
                        XmlEncoder.EncodeTextFile(dialog.FileName, info, paragraphs, checkBoxPunc.Checked);
                    }

                }
                catch (Exception ex)
                {
                    resultOK = false;
                    MessageBox.Show(ex.Message, "Text Encoder", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    if (resultOK)
                    {
                        if (checkBoxOpen.Checked) System.Diagnostics.Process.Start(dialog.FileName);
                        else MessageBox.Show("Operation complete", "Text Encoder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

            }//end if
        }
Exemple #4
0
        private static void EncodeHeader(HeaderInformation info)
        {
            xmlWriter.WriteStartElement("teiHeader"); //<teiHeader>
            xmlWriter.WriteStartElement("fileDesc");  //<fileDesc>

            xmlWriter.WriteComment("Description is managed by the operator");

            //titleStmt info
            #region
            if (info.Title != string.Empty || info.Author != string.Empty)
            {
                xmlWriter.WriteStartElement("titleStmt");//<titleStmt>

                if (info.Title != string.Empty)
                {
                    xmlWriter.WriteElementString("title", info.Title);
                }

                if (info.Author != string.Empty)
                {
                    xmlWriter.WriteElementString("author", info.Author);
                }

                xmlWriter.WriteEndElement();//closing <titleStmt>
            }
            #endregion

            //pubStmt info
            #region
            if (info.Publisher != string.Empty || info.PublisherPlace != string.Empty ||
                info.PublishDate != string.Empty || info.PublishAddress != string.Empty ||
                info.Distributor != string.Empty)
            {
                xmlWriter.WriteStartElement("pubStmt");//<pubStmt>

                if (info.Publisher != string.Empty)
                {
                    xmlWriter.WriteElementString("publisher", info.Publisher);
                }

                if (info.PublisherPlace != string.Empty)
                {
                    xmlWriter.WriteElementString("pubPlace", info.PublisherPlace);
                }

                if (info.PublishAddress != string.Empty)
                {
                    xmlWriter.WriteElementString("address", info.PublishAddress);
                }

                if (info.PublishDate != string.Empty)
                {
                    xmlWriter.WriteElementString("date", info.PublishDate);
                }

                if (info.Distributor != string.Empty)
                {
                    xmlWriter.WriteElementString("distributor", info.Distributor);
                }

                xmlWriter.WriteEndElement();//closing <pubStmt>
            }
            #endregion

            //sourceDesc info
            #region
            if (info.BiblCitation != string.Empty || info.TitleSrc != string.Empty || info.AuthorSrc != string.Empty ||
                info.EditionSrc != string.Empty || info.Analytic != string.Empty || info.DateSrc != string.Empty)
            {
                xmlWriter.WriteStartElement("sourceDesc"); //<sourceDesc>

                if (info.BiblCitation != string.Empty)
                {
                    xmlWriter.WriteElementString("Bibl", info.BiblCitation);
                }

                if (info.TitleSrc != string.Empty)
                {
                    xmlWriter.WriteElementString("title", info.TitleSrc);
                }

                if (info.AuthorSrc != string.Empty)
                {
                    xmlWriter.WriteElementString("author", info.AuthorSrc);
                }

                if (info.EditionSrc != string.Empty)
                {
                    xmlWriter.WriteElementString("edition", info.EditionSrc);
                }

                if (info.Analytic != string.Empty)
                {
                    xmlWriter.WriteElementString("analytic", info.Analytic);
                }

                if (info.DateSrc != string.Empty)
                {
                    xmlWriter.WriteElementString("date", info.DateSrc);
                }

                xmlWriter.WriteEndElement();//closing <sourceDesc>
            }
            #endregion

            xmlWriter.WriteEndElement(); //closing <fileDesc>
            xmlWriter.WriteEndElement(); //closing <teiHeader>
        }
        private static void EncodeHeader(HeaderInformation info)
        {
            xmlWriter.WriteStartElement("teiHeader");//<teiHeader>
            xmlWriter.WriteStartElement("fileDesc");//<fileDesc>

            xmlWriter.WriteComment("Description is managed by the operator");

            //titleStmt info
            #region
            if (info.Title != string.Empty || info.Author != string.Empty)
            {
                xmlWriter.WriteStartElement("titleStmt");//<titleStmt>

                if (info.Title != string.Empty)
                    xmlWriter.WriteElementString("title", info.Title);

                if (info.Author != string.Empty)
                    xmlWriter.WriteElementString("author", info.Author);

                xmlWriter.WriteEndElement();//closing <titleStmt>
            }
            #endregion

            //pubStmt info
            #region
            if (info.Publisher != string.Empty || info.PublisherPlace != string.Empty ||
                info.PublishDate != string.Empty || info.PublishAddress != string.Empty ||
                info.Distributor != string.Empty)
            {
                xmlWriter.WriteStartElement("pubStmt");//<pubStmt>

                if (info.Publisher != string.Empty)
                    xmlWriter.WriteElementString("publisher", info.Publisher);

                if (info.PublisherPlace != string.Empty)
                    xmlWriter.WriteElementString("pubPlace", info.PublisherPlace);

                if (info.PublishAddress != string.Empty)
                    xmlWriter.WriteElementString("address", info.PublishAddress);

                if (info.PublishDate != string.Empty)
                    xmlWriter.WriteElementString("date", info.PublishDate);

                if (info.Distributor != string.Empty)
                    xmlWriter.WriteElementString("distributor", info.Distributor);

                xmlWriter.WriteEndElement();//closing <pubStmt>
            }
            #endregion

            //sourceDesc info
            #region
            if (info.BiblCitation != string.Empty || info.TitleSrc != string.Empty || info.AuthorSrc != string.Empty ||
                info.EditionSrc != string.Empty || info.Analytic != string.Empty || info.DateSrc != string.Empty)
            {
                xmlWriter.WriteStartElement("sourceDesc"); //<sourceDesc>

                if (info.BiblCitation != string.Empty)
                    xmlWriter.WriteElementString("Bibl", info.BiblCitation);

                if (info.TitleSrc != string.Empty)
                    xmlWriter.WriteElementString("title", info.TitleSrc);

                if (info.AuthorSrc != string.Empty)
                    xmlWriter.WriteElementString("author", info.AuthorSrc);

                if (info.EditionSrc != string.Empty)
                    xmlWriter.WriteElementString("edition", info.EditionSrc);

                if (info.Analytic != string.Empty)
                    xmlWriter.WriteElementString("analytic", info.Analytic);

                if (info.DateSrc != string.Empty)
                    xmlWriter.WriteElementString("date", info.DateSrc);

                xmlWriter.WriteEndElement();//closing <sourceDesc>
            }
            #endregion

            xmlWriter.WriteEndElement();//closing <fileDesc>
            xmlWriter.WriteEndElement();//closing <teiHeader>
        }
Exemple #6
0
        private void btnEncode_Click(object sender, EventArgs e)
        {
            //null, emptyString and whiteSpace check
            if (string.IsNullOrWhiteSpace(InputBox.Text))
            {
                MessageBox.Show("There is no text.", "Text Encoder", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //creating error tracking variable
            bool resultOK = true;

            // creating save dialog
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter = ".xml File|*.xml";
            dialog.Title  = "Save XML file";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                //packing all text description info into one class
                HeaderInformation info = new HeaderInformation
                {
                    //page1 -- TitleStmt and PubStmt
                    Author         = textBoxAuthor.Text,
                    Title          = textBoxTitle.Text,
                    Publisher      = textBoxPublisher.Text,
                    PublishDate    = textBoxDate.Text,
                    PublishAddress = textBoxAddress.Text,
                    Distributor    = textBoxDistr.Text,
                    PublisherPlace = textBoxPublisherPlace.Text,

                    //page2 -- sourceDesc
                    BiblCitation = textBoxBiblCitation.Text,
                    TitleSrc     = textBoxTitleSrc.Text,
                    AuthorSrc    = textBoxAuthorSrc.Text,
                    EditionSrc   = textBoxEditionSrc.Text,
                    Analytic     = textBoxAnalytic.Text,
                    DateSrc      = textBoxDateSrc.Text
                };

                try
                {
                    if (checkBoxSentences.Checked)
                    {
                        //if sentence encoding is included
                        //text is spitted to paragraphs and sentences
                        List <string[]> paragraphsNSentences = SimpleTextSplitter.SplitToParagraphsWithSentences(InputBox.Text);

                        //then encoded using first overload ( List<string[]> )
                        XmlEncoder.EncodeTextFile(dialog.FileName, info, paragraphsNSentences, checkBoxPunc.Checked);
                    }
                    else
                    {
                        //usual split
                        string[] paragraphs = InputBox.Text.Split(new string[] { " \n", "\n", }, StringSplitOptions.RemoveEmptyEntries);

                        //encoded using second overload ( string[] )
                        XmlEncoder.EncodeTextFile(dialog.FileName, info, paragraphs, checkBoxPunc.Checked);
                    }
                }
                catch (Exception ex)
                {
                    resultOK = false;
                    MessageBox.Show(ex.Message, "Text Encoder", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    if (resultOK)
                    {
                        if (checkBoxOpen.Checked)
                        {
                            System.Diagnostics.Process.Start(dialog.FileName);
                        }
                        else
                        {
                            MessageBox.Show("Operation complete", "Text Encoder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }//end if
        }