コード例 #1
0
ファイル: psdxTools.cs プロジェクト: ErwinKomen/subtiel
 // =========================================================================================================
 public psdxTools(ErrHandle objErr, XmlDocument pdxThis)
 {
     this.errHandle = objErr;
       oXmlTools = new xmlTools(objErr);
       oXmlTools.SetXmlDocument(pdxThis);
       pdxCurrentFile = pdxThis;
 }
コード例 #2
0
ファイル: psdxTools.cs プロジェクト: ErwinKomen/subtiel
 // =========================================================================================================
 public psdxTools(ErrHandle objErr, XmlDocument pdxThis)
 {
     this.errHandle = objErr;
     oXmlTools      = new xmlTools(objErr);
     oXmlTools.SetXmlDocument(pdxThis);
     pdxCurrentFile = pdxThis;
 }
コード例 #3
0
ファイル: opsConv.cs プロジェクト: ErwinKomen/subtiel
        /// <summary>
        /// FlushOpsToFolia --
        ///     Write sentences 0 until iCount-1 from the @lSentBuf to wrFolia
        ///     Add the ending time whereever this is needed
        ///
        /// </summary>
        /// <param name="lSentBuf"></param>
        /// <param name="wrFolia"></param>
        /// <param name="iCount"></param>
        /// <param name="sTimeEnd"></param>
        /// <param name="sTimeBkup"></param>
        /// <returns></returns>
        private bool FlushOpsToFolia(ref List <Sent> lSentBuf, ref XmlWriter wrFolia, int iCount, String sTimeEnd, String sTimeBkup)
        {
            try {
                // Validate
                if (iCount == 0)
                {
                    return(true);
                }
                // Walk all the sentences preceding the current one
                for (int j = 0; j < iCount; j++)
                {
                    String sClause = ""; String sBegin = ""; String sEnd = "";

                    // Retrieve this sentence's buffer
                    Sent oSentThis = lSentBuf[j];
                    // Validate: length of sentence buffer must be larger than 0
                    if (oSentThis.words.Count == 0)
                    {
                        continue;
                    }

                    // Start producing output for this sentence
                    XmlDocument   pdxTmp = new XmlDocument();
                    util.xmlTools oTool  = new util.xmlTools(this.errHandle);
                    oTool.SetXmlDocument(pdxTmp);
                    XmlNode ndS = oTool.AddXmlChild(null, "s",
                                                    "xml:id", oSentThis.id, "attribute",
                                                    "begintime", "", "attribute",
                                                    "endtime", "", "attribute",
                                                    "xmlns", "http://ilk.uvt.nl/folia", "attribute");

                    // Process all the words in this sentence
                    List <WordBuf> lSentWrds = oSentThis.words;
                    for (int k = 0; k < lSentWrds.Count; k++)
                    {
                        if (lSentWrds[k].e == "")
                        {
                            lSentWrds[k].e = sTimeEnd;
                        }
                        XmlNode ndW = oTool.AddXmlChild(ndS, "w",
                                                        "xml:id", oSentThis.id + ".w." + (k + 1), "attribute",
                                                        "class", lSentWrds[k].c, "attribute",
                                                        "t", lSentWrds[k].w, "child");
                        // Build the clause
                        if (sClause != "")
                        {
                            sClause += " ";
                        }
                        sClause += lSentWrds[k].w;
                        if (lSentWrds[k].bStart)
                        {
                            // Adapt the begin
                            sBegin = lSentWrds[k].s.Replace(',', '.');
                            // Prevent empty-time-errors
                            if (sBegin == "")
                            {
                                sBegin = sTimeBkup.Replace(",", ".");
                            }
                            // Validate one last time
                            sBegin = correctTime(sBegin);
                            // Add the modification as feature to this node
                            oTool.AddXmlChild(ndW, "feat", "subset", "begintime", "attribute", "class", sBegin, "attribute");
                            oTool.AddXmlChild(ndW, "feat", "subset", "n", "attribute", "class", lSentWrds[k].n, "attribute");
                        }
                        if (lSentWrds[k].bEnd)
                        {
                            // Adapt the begin
                            sEnd = lSentWrds[k].e.Replace(',', '.');
                            // Prevent empty-time-errors
                            if (sEnd == "")
                            {
                                sEnd = sTimeBkup.Replace(",", ".");
                            }
                            // Add the modification as feature to this node
                            oTool.AddXmlChild(ndW, "feat", "subset", "endtime", "attribute", "class", sEnd, "attribute");
                        }
                    }
                    XmlNode ndT_nl = oTool.AddXmlChild(ndS, "t", "class", "nld", "attribute");
                    ndT_nl.InnerText = sClause;

                    /*
                     * // Helaas wordt dit niet in dank afgenomen
                     * XmlNode ndT_or = oTool.AddXmlChild(ndS, "t", "class", "original", "attribute");
                     */
                    // Add the @begintime and @endtime values for this sentence
                    sBegin = lSentWrds[0].s.Replace(',', '.');
                    // Prevent empty-time-errors
                    if (sBegin == "")
                    {
                        sBegin = sTimeBkup.Replace(",", ".");
                    }
                    // Get the end-time
                    sEnd = lSentWrds[lSentWrds.Count - 1].e.Replace(',', '.');
                    if (sEnd == "")
                    {
                        sEnd = sBegin;
                    }
                    // Validate begintime and endtime
                    sBegin = correctTime(sBegin);
                    sEnd   = correctTime(sEnd);
                    // Only now write them away
                    ndS.Attributes["begintime"].Value = sBegin;
                    ndS.Attributes["endtime"].Value   = sEnd;
                    // The content of this sentence can now be output
                    wrFolia.WriteNode(XmlReader.Create(new StringReader(pdxTmp.OuterXml)), true);
                }
                // Remove everything we flushed from the sentence buffer
                for (int j = iCount - 1; j >= 0; j--)
                {
                    lSentBuf.RemoveAt(j);
                }

                // Return positively
                return(true);
            } catch (Exception ex) {
                errHandle.DoError("opsConv/FlushOpsToFolia", ex); // Provide standard error message
                return(false);
            }
        }