Exemplo n.º 1
0
        public void VypisCharakteristiku()
        {
            if (base.VstupniSoubor == null || base.VystupniSoubor == null)
            {
                throw new ArgumentNullException("Nebyly zadány vhodné názvy vstupního nebo výstupního souboru.");
            }
            using (XmlReader r = Objekty.VytvorXmlReader(base.VstupniSoubor))
            {
                using (XmlWriter xw = Objekty.VytvorXmlWriter(base.VystupniSoubor))
                {
                    xw.WriteStartDocument(true);
                    xw.WriteStartElement("entries");
                    while (r.Read())
                    {
                        if (r.NodeType == XmlNodeType.Element)
                        {
                            switch (r.Name)
                            {
                            case "entryhead":
                                XmlDocument xd = new XmlDocument();
                                xd.LoadXml(r.ReadOuterXml());
                                if (xd.DocumentElement.InnerXml.Contains("<pos>"))
                                {
                                    xw.WriteStartElement("entryhead");
                                    foreach (XmlNode xn in xd.DocumentElement.ChildNodes)
                                    {
                                        if (xn.Name == "pos")
                                        {
                                            xn.WriteTo(xw);
                                            xw.WriteEndElement();
                                            break;
                                        }
                                        xn.WriteTo(xw);
                                    }
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    xw.WriteEndElement();
                }
            }
        }
Exemplo n.º 2
0
        public static void ExtrahovatSeznamXml(string strVstupniSoubor, string strVystupniSoubor, string strZdroj)
        {
            using (XmlReader r = Objekty.VytvorXmlReader(strVstupniSoubor)) {
                using (XmlWriter xw = Objekty.VytvorXmlWriter(strVystupniSoubor)) {
                    string sHeslo = null;
                    xw.WriteStartElement("xrefs");
                    xw.WriteAttributeString("source", strZdroj);
                    while (r.Read())
                    {
                        if (r.NodeType == XmlNodeType.Element)
                        {
                            switch (r.Name)
                            {
                            case "entry":
                                sHeslo = r.GetAttribute("defaulthw");
                                break;

                            case "xref":
                                XmlDocument xd = new XmlDocument();
                                XmlNode     xn = xd.ReadNode(r);
                                if (xn != null)
                                {
                                    xd.AppendChild(xn);
                                    XmlAttribute xa = xd.CreateAttribute("defaulthw");
                                    xa.Value = sHeslo;
                                    xd.DocumentElement.Attributes.Append(xa);
                                }

                                if (xd.DocumentElement != null)
                                {
                                    xd.WriteContentTo(xw);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    xw.WriteEndElement();                     //xrefs
                }
            }
        }
Exemplo n.º 3
0
        public static void VytvoritSeznamText(string strVstupniSoubor, string strVystupniSoubor, bool blnSeradit, bool blnBezDuplicit)
        {
            List <OdkazInfo> glsOdkazy = new List <OdkazInfo>();

            using (XmlReader r = Objekty.VytvorXmlReader(strVstupniSoubor)) {
                string sZdroj = null;
                while (r.Read())
                {
                    if (r.NodeType == XmlNodeType.Element && r.Name == "xrefs")
                    {
                        sZdroj = r.GetAttribute("source");
                    }
                    if (r.NodeType == XmlNodeType.Element && r.Name == "xref")
                    {
                        OdkazInfo o = new OdkazInfo(r.GetAttribute("prefix"), r.GetAttribute("hw"), r.GetAttribute("hom"), sZdroj, r.GetAttribute("source"), r.GetAttribute("target"), r.GetAttribute("defaulthw"), r.ReadString().Trim());
                        glsOdkazy.Add(o);
                    }
                }
            }

            if (blnSeradit)
            {
                glsOdkazy.Sort();
            }

            using (StreamWriter sw = new StreamWriter(strVystupniSoubor, false, System.Text.Encoding.Unicode)) {
                foreach (OdkazInfo o in glsOdkazy)
                {
                    sw.WriteLine(o.Zaznam());
                }
            }


            if (blnBezDuplicit)
            {
                CteckaSouboru csb = new CteckaSouboru(strVystupniSoubor);
                csb.OdstranDuplicitniRadky(true);
                csb = null;
            }
        }
Exemplo n.º 4
0
        public void VypisHeslaTypeUse()
        {
            if (base.VstupniSoubor == null || base.VystupniSoubor == null)
            {
                throw new ArgumentNullException("Nebyly zadány vhodné názvy vstupního nebo výstupního souboru.");
            }
            using (XmlReader r = Objekty.VytvorXmlReader(base.VstupniSoubor))
            {
                using (XmlWriter xw = Objekty.VytvorXmlWriter(base.VystupniSoubor))
                {
                    xw.WriteStartDocument(true);
                    xw.WriteStartElement("entries");
                    while (r.Read())
                    {
                        if (r.NodeType == XmlNodeType.Element)
                        {
                            switch (r.Name)
                            {
                            case "entry":
                                string sUse  = r.GetAttribute("use");
                                string sType = r.GetAttribute("type");
                                if (sUse == "public" && sType == "excl")
                                {
                                    DPXT.SerializeNode(r, xw);
                                    xw.WriteEndElement();
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    xw.WriteEndElement();
                }
            }
        }
Exemplo n.º 5
0
        public override void KonsolidovatHeslovouStat(string inputFile, string outputFile)
        {
            int    iEntry  = 0;
            string sSource = null;

            using (XmlReader r = Objekty.VytvorXmlReader(inputFile)) {
                using (XmlWriter xw = Objekty.VytvorXmlWriter(outputFile)) {
                    xw.WriteStartDocument(true);

                    while (r.Read())
                    {
                        if (r.NodeType == XmlNodeType.Element)
                        {
                            switch (r.Name)
                            {
                            case "entry":
                                XmlDocument xd = new XmlDocument();
                                XmlNode     xn = xd.ReadNode(r);
                                if (xn != null)
                                {
                                    xd.AppendChild(xn);
                                }
                                if (xd.DocumentElement != null)
                                {
                                    if (!xd.DocumentElement.IsEmpty)
                                    {
                                        if (ZkonsolidujEntry(ref xd, sSource, ++iEntry))
                                        {
                                            xd.WriteContentTo(xw);
                                        }
                                    }
                                }

                                break;

                            case "dictionary":
                                sSource = r.GetAttribute("name");
                                goto default;

                            default:
                                Transformace.SerializeNode(r, xw);
                                break;
                            }
                        }
                        else if (r.NodeType == XmlNodeType.EndElement)
                        {
                            switch (r.Name)
                            {
                            case "entry":
                                break;

                            default:
                                Transformace.SerializeNode(r, xw);
                                break;
                            }
                        }
                        else
                        {
                            Transformace.SerializeNode(r, xw);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Upraví hranice heslové stati. Ohraničí jednotlivé části značkou &lt;entry&gt; a v rámci heslové stati seskupí významy podřazené značce &lt;senseGrp&gt;.
        /// </summary>
        public override void UpravitHraniceHesloveStati(string inputFile, string outputFile)
        {
            if (inputFile == null || outputFile == null)
            {
                throw new ArgumentNullException("Nebyly zadány vhodné názvy vstupního nebo výstupního souboru.");
            }
            using (XmlReader r = Objekty.VytvorXmlReader(inputFile))
            {
                using (XmlWriter xw = Objekty.VytvorXmlWriter(outputFile))
                {
                    xw.WriteStartDocument(true);
                    bool           blnPrvniEntryhead          = true;
                    bool           blnVyskytlySeVyznamy       = false;
                    string         strTypSenseGrp             = null;
                    Stack <string> gstTypSenseGrp             = new Stack <string>();
                    int            intPocetOtevrenychSenseGrp = 0;
                    bool           blnPrvniVyznam             = false;
                    int            xmlReaderDepp = 0;
                    int            xmlWriterDeep = 0;

                    while (r.Read())
                    {
                        //Console.WriteLine("Reader: {0}, Writer: {1}", xmlReaderDepp, xmlWriterDeep);
                        if (r.NodeType == XmlNodeType.Element)
                        {
                            xmlReaderDepp++;
                            if (r.IsEmptyElement)
                            {
                                xmlReaderDepp--;
                            }
                            if (r.Name == "div1")
                            {
                                string name = r.Name;
                            }
                            switch (r.Name)
                            {
                            case "entryhead":
                                if (blnPrvniVyznam)
                                {
                                    WriteEndElement(xw, ref xmlWriterDeep);                                              //senses
                                    xw.WriteWhitespace("\r\n");
                                }
                                blnPrvniVyznam       = false;
                                blnVyskytlySeVyznamy = false;
                                int iPocetSenseGrp = gstTypSenseGrp.Count;
                                if (iPocetSenseGrp > 0)
                                {
                                    for (int i = 1; i < iPocetSenseGrp; i++)
                                    {
                                        intPocetOtevrenychSenseGrp--;
                                        WriteEndElement(xw, ref xmlWriterDeep);                                                  //senseGrp
                                        xw.WriteWhitespace("\r\n");
                                    }
                                    gstTypSenseGrp.Clear();
                                }
                                while (intPocetOtevrenychSenseGrp > 0)
                                {
                                    WriteEndElement(xw, ref xmlWriterDeep);
                                    xw.WriteWhitespace("\r\n");
                                    intPocetOtevrenychSenseGrp--;
                                }
                                if (!blnPrvniEntryhead)
                                {
                                    WriteEndElement(xw, ref xmlWriterDeep);                                             //entry
                                    xw.WriteWhitespace("\r\n");
                                }
                                else
                                {
                                    blnPrvniEntryhead = false;
                                }
                                WriteStartElement(xw, "entry", ref xmlWriterDeep);

                                xw.WriteWhitespace("\r\n");
                                goto default;

                            case "senseGrp":
                                strTypSenseGrp = r.GetAttribute("type");
                                intPocetOtevrenychSenseGrp++;
                                if (gstTypSenseGrp.Count > 0)
                                {
                                    if (strTypSenseGrp == gstTypSenseGrp.Peek())
                                    {
                                        WriteEndElement(xw, ref xmlWriterDeep);                                                  //senseGrp
                                        xw.WriteWhitespace("\r\n");
                                        intPocetOtevrenychSenseGrp--;
                                    }
                                    else
                                    {
                                        if (blnVyskytlySeVyznamy)
                                        {
                                            WriteEndElement(xw, ref xmlWriterDeep);
                                            xw.WriteWhitespace("\r\n");
                                            intPocetOtevrenychSenseGrp--;
                                        }
                                        else
                                        {
                                            gstTypSenseGrp.Push(strTypSenseGrp);
                                        }
                                    }
                                }
                                else
                                {
                                    gstTypSenseGrp.Push(strTypSenseGrp);
                                }
                                blnVyskytlySeVyznamy = false;
                                goto default;

                            case "sense":
                                if (!blnPrvniVyznam)
                                {
                                    WriteStartElement(xw, "senses", ref xmlWriterDeep);                                             //xw.WriteStartElement("senses");
                                    xw.WriteWhitespace("\r\n");
                                    blnPrvniVyznam = true;
                                }
                                blnVyskytlySeVyznamy = true;
                                goto default;

                            case "note":
                            case "appendix":
                                if (r.IsEmptyElement)
                                {
                                    goto default;
                                }
                                while (gstTypSenseGrp.Count > 0)
                                {
                                    //xw.WriteEndElement();
                                    WriteEndElement(xw, ref xmlWriterDeep);
                                    xw.WriteWhitespace("\r\n");
                                    intPocetOtevrenychSenseGrp--;
                                    gstTypSenseGrp.Pop();
                                }
                                if (blnPrvniVyznam)
                                {
                                    //xw.WriteEndElement(); //senses
                                    WriteEndElement(xw, ref xmlWriterDeep);
                                    xw.WriteWhitespace("\r\n");
                                    blnPrvniVyznam = false;
                                }
                                goto default;

                            default:
                                if (!r.IsEmptyElement)
                                {
                                    xmlWriterDeep++;
                                }
                                DPXT.SerializeNode(r, xw);
                                break;
                            }
                        }
                        else
                        {
                            if (r.NodeType == XmlNodeType.EndElement)
                            {
                                xmlReaderDepp--;
                                switch (r.Name)
                                {
                                case "senseGrp":
                                    if (blnPrvniVyznam)
                                    {
                                        //xw.WriteEndElement(); //senses
                                        WriteEndElement(xw, ref xmlWriterDeep);
                                        xw.WriteWhitespace("\r\n");
                                        blnPrvniVyznam = false;
                                    }
                                    break;

                                case "div1":
                                    //xw.WriteEndElement(); //entry
                                    while (xmlWriterDeep > xmlReaderDepp + 1)
                                    {
                                        WriteEndElement(xw, ref xmlWriterDeep);
                                    }

                                    blnPrvniEntryhead = true;
                                    blnPrvniVyznam    = false;
                                    goto default;

                                default:
                                    xmlWriterDeep--;
                                    DPXT.SerializeNode(r, xw);
                                    break;
                                }
                            }
                            //else if (r.NodeType == XmlNodeType.XmlDeclaration && r.Name == "xml") {
                            //  //nedělat nic, jde o začátek dokumentu; genruje cyhbu: nelze zapsat deklaraci, dokument již byl započat
                            //}

                            else
                            {
                                DPXT.SerializeNode(r, xw);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Upraví hranice heslové stati, seskupí všechny prvky heslové stati do elementu &lt;entry&gt;. Využívá při tom značku &lt;entryend&gt;
        /// </summary>
        /// <exception cref="ArgumentNullException">Vyvolá výjimku, pokud nejsou zadány vstupní nebo výstupní soubor.</exception>
        public override void UpravitHraniceHesloveStati(string inputFile, string outputFile)
        {
            //výchozí imnplementace se hodí pro ESSČ
            string sChyba = null;

            if (inputFile == null || outputFile == null)
            {
                throw new ArgumentNullException("Nebyly zadány vhodné názvy vstupního nebo výstupního souboru.");
            }
            using (XmlReader r = Objekty.VytvorXmlReader(inputFile))
            {
                using (XmlWriter xw = Objekty.VytvorXmlWriter(outputFile))
                {
                    /*
                     * string strTypSenseGrp = null;
                     * Stack<string> gstTypSenseGrp = new Stack<string>();
                     * int intPocetOtevrenychSenseGrp = 0;
                     * bool blnVyskytlySeVyznamy = false;
                     */
                    bool blnJeSenseGrp = false;
                    bool blnJeSense    = false;

                    xw.WriteStartDocument(true);
                    bool blnPrvniEntryhead = true;
                    try
                    {
                        while (r.Read())
                        {
                            if (r.NodeType == XmlNodeType.Element)
                            {
                                switch (r.Name)
                                {
                                case "entryhead":
                                    if (blnPrvniEntryhead)
                                    {
                                        xw.WriteStartElement("entry");
                                        xw.WriteWhitespace("\r\n");
                                        blnPrvniEntryhead = false;
                                    }
                                    DPXT.SerializeNode(r, xw);
                                    blnJeSenseGrp = blnJeSense = false;

                                    break;

                                case "entryend":
                                    xw.WriteEndElement();                                             //entry
                                    xw.WriteWhitespace("\r\n");
                                    blnPrvniEntryhead = true;

                                    break;

                                case "senseGrp":
                                    if (blnJeSense)
                                    {
                                        xw.WriteEndElement();                                                 //senses
                                    }
                                    if (blnJeSenseGrp)
                                    {
                                        xw.WriteEndElement();                                                 //senseGrp
                                    }
                                    blnJeSenseGrp = true;
                                    blnJeSense    = false;

                                    goto default;

                                case "sense":
                                    if (!blnJeSense)
                                    {
                                        xw.WriteStartElement("senses");
                                    }
                                    blnJeSense = true;

                                    goto default;

                                default:
                                    if (blnJeSense && r.Depth == 2 && !(r.Name == "sense"))
                                    {
                                        xw.WriteEndElement();                                                 //senses
                                        blnJeSense = false;
                                    }
                                    if (blnJeSenseGrp && r.Depth == 2 && !r.Name.StartsWith("sense"))
                                    {
                                        blnJeSenseGrp = false;
                                        xw.WriteEndElement();                                                 //senseGrp
                                    }
                                    DPXT.SerializeNode(r, xw);
                                    break;
                                }
                            }
                            else if (r.NodeType == XmlNodeType.EndElement)
                            {
                                if (r.Depth == 2)
                                {
                                    switch (r.Name)
                                    {
                                    case "senseGrp":
                                        /*
                                         * if (blnJeSense)
                                         * {
                                         *      xw.WriteEndElement(); //senseGrp
                                         *      blnJeSenseGrp = false;
                                         * }
                                         */
                                        //DPXT.SerializeNode(r, xw);
                                        break;

                                    case "sense":
                                        DPXT.SerializeNode(r, xw);
                                        break;

                                    default:
                                        if (blnJeSense)
                                        {
                                            xw.WriteEndElement();                                                     //senses
                                            blnJeSense = false;
                                        }
                                        DPXT.SerializeNode(r, xw);
                                        break;
                                    }
                                }
                                else
                                {
                                    DPXT.SerializeNode(r, xw);
                                }
                            }
                            else
                            {
                                DPXT.SerializeNode(r, xw);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        sChyba = ex.Message;
                        sChyba = r.ReadInnerXml();
                        while (sChyba.Trim().Length == 0)
                        {
                            if (r.Read())
                            {
                                sChyba = r.ReadInnerXml();
                            }
                            else
                            {
                                sChyba = "XmlReader je na konci souboru.";
                            }
                        }
                        Console.WriteLine(sChyba);
                    }
                    finally
                    {
                        if (xw.WriteState != WriteState.Error && xw.WriteState != WriteState.Closed)
                        {
                            xw.WriteEndDocument();
                        }
                        xw.Flush();
                        xw.Close();
                    }
                }
            }
        }
Exemplo n.º 8
0
        public static void HeslarText(string strVstupniSoubor, string sVystupniSoubor)
        {
            string sSubVoce   = null;
            string sSubVoceId = null;
            //string sHeslo = null;
            //string sId = null;
            //string sType = null;
            string sHeslovaStatTyp = null;
            string sHeslovaStatID  = null;
            //string sHomonymum = null;
            //string sRetrograd = null;
            string sPismeno = null;
            string sZdroj   = null;
            string sPouziti = null;

            using (XmlReader r = Objekty.VytvorXmlReader(strVstupniSoubor)) {
                using (StreamWriter sw = new StreamWriter(sVystupniSoubor, false, System.Text.Encoding.Unicode)) {
                    while (r.Read())
                    {
                        if (r.NodeType == XmlNodeType.Element)
                        {
                            switch (r.Name)
                            {
                            case "hw":
                                string[]  asVlastnosti = new string[20];
                                HesloInfo hi           = new HesloInfo();

                                string sRef     = r.GetAttribute("ref");
                                string sZdrojHW = r.GetAttribute("source");
                                string sZdrojID = r.GetAttribute("target");
                                string sPrefix  = r.GetAttribute("pref");
                                //if(r.GetAttribute("id") == "en000040.hw3")
                                // sPrefix = r.GetAttribute("pref");
                                string strTyp = r.GetAttribute("type");

                                //asVlastnosti[0] = ""; //prefix
                                //asVlastnosti[1] = ""; //hesloveSlovo
                                //asVlastnosti[2] = ""; //postfix

                                /*
                                 * asVlastnosti[3] = r.GetAttribute("hom");
                                 * asVlastnosti[4] = ""; //slovní druh
                                 * asVlastnosti[5] = ""; //další informace
                                 * asVlastnosti[6] = ""; //varianta
                                 *
                                 * asVlastnosti[7] = r.GetAttribute("id");
                                 * asVlastnosti[8] = r.GetAttribute("form");
                                 * asVlastnosti[9] = strTyp; //substandard
                                 * asVlastnosti[10] = r.GetAttribute("xml:lang");
                                 * asVlastnosti[11] = sHeslovaStatID;
                                 * asVlastnosti[12] = ""; //heslová stať
                                 * asVlastnosti[13] = sHeslovaStatTyp;
                                 * asVlastnosti[14] = sPismeno;
                                 * asVlastnosti[15] = sZdroj;
                                 */


                                hi.Homonymum         = r.GetAttribute("hom");
                                hi.SlovniDruh        = "";
                                hi.DalsiInformace    = "";
                                hi.Varianta          = "";
                                hi.Id                = r.GetAttribute("id");
                                hi.Forma             = r.GetAttribute("form");
                                hi.TypHeslovehoSlova = strTyp;   //substandard
                                hi.Lang              = r.GetAttribute("xml:lang");
                                hi.HeslovaStatId     = sHeslovaStatID;
                                hi.HeslovaStat       = ""; //heslová stať
                                hi.HeslovaStatTyp    = sHeslovaStatTyp;
                                hi.Pismeno           = sPismeno;
                                hi.ZkratkaZdroje     = sZdroj;
                                hi.JeRef             = sRef;


                                if (strTyp == "substandard" && sZdroj == "ESSC")   // hi.TypHeslovehoSlova == "1"
                                {
                                    break;
                                }

                                /*
                                 * if (asVlastnosti[9] == "substandard" && sZdroj == "ESSC") {
                                 *      break;
                                 * }
                                 */


                                if (sZdrojHW == "HesStcS")
                                {
                                    hi.HesStcSIdRef = sZdrojID;
                                }

                                /*
                                 * if (sZdrojHW == "HesStcS") {
                                 *      asVlastnosti[19] = sZdrojID;
                                 * }
                                 */

                                //if (asVlastnosti[3] == null)
                                //   asVlastnosti[3] = "";

                                hi.ZpusobVyuziti = sPouziti;

                                //if (sPouziti == "internal")
                                // hi.FormId = 1;

                                /*
                                 * if (sPouziti == "internal")
                                 *      asVlastnosti[18] = "1";
                                 */


                                //logika součást get

                                /*
                                 * switch (asVlastnosti[8]) {
                                 *      case "short":
                                 *              asVlastnosti[8] = "4";
                                 *              break;
                                 *      case "restored":
                                 *              asVlastnosti[8] = "2";
                                 *              break;
                                 *      default:
                                 *              asVlastnosti[8] = "1";
                                 *              break;
                                 * }
                                 *
                                 * if (asVlastnosti[9] == null)
                                 *      asVlastnosti[9] = "0";
                                 * else
                                 *      asVlastnosti[9] = "1";
                                 *
                                 * if (asVlastnosti[10] == null) {
                                 *      asVlastnosti[10] = "1";
                                 * }
                                 *
                                 * switch (sHeslovaStatTyp) {
                                 *      case "ref":
                                 *              asVlastnosti[13] = "4";
                                 *              break;
                                 *      case "full":
                                 *              asVlastnosti[13] = "2";
                                 *              break;
                                 *      case "excl": //v ESSČ
                                 *              asVlastnosti[13] = "8";
                                 *              break;
                                 *      default:
                                 *              asVlastnosti[13] = "1";
                                 *              break;
                                 * }
                                 * if (sRef == "true") {
                                 *      asVlastnosti[13] = "4";
                                 * }
                                 *
                                 *
                                 * switch (sZdroj) {
                                 *      case "MSS":
                                 *              asVlastnosti[15] = "2";
                                 *              break;
                                 *      case "ESSC":
                                 *              asVlastnosti[15] = "4";
                                 *              break;
                                 *      case "GbSlov":
                                 *              asVlastnosti[15] = "8";
                                 *              break;
                                 *      case "StcS":
                                 *      case "StcSSlov":
                                 *              asVlastnosti[15] = "16";
                                 *              break;
                                 *      case "SimekSlov":
                                 *              asVlastnosti[15] = "32";
                                 *              break;
                                 *      case "HesStcS":
                                 *      case "StcSMat":
                                 *              asVlastnosti[15] = "1";
                                 *              break;
                                 *      default:
                                 *              break;
                                 * }
                                 */

                                string sObsahElementu = r.ReadElementString();

                                if (!hi.ZpracujHesloveSlovo(sObsahElementu, sPrefix))
                                {
                                    break;
                                }

                                /*
                                 * if (hi.HesloveSlovo == "žižň")
                                 * {
                                 *      string d = hi.HesloveSlovo;
                                 * }
                                 */
                                /*
                                 * asVlastnosti[1] = sObsahElementu;
                                 * if (!String.IsNullOrEmpty(sPrefix)) {
                                 *      asVlastnosti[0] = sPrefix;
                                 *      asVlastnosti[1] = asVlastnosti[1].Substring(sPrefix.Length);
                                 * }
                                 *
                                 *
                                 * if (asVlastnosti[1].Contains("(?)")) {
                                 *      asVlastnosti[1] = asVlastnosti[1].Replace("(?)", "").TrimEnd();
                                 * }
                                 * int i = 0;
                                 * //while (!Char.IsLetter(asVlastnosti[1], i))
                                 * //{
                                 * //   asVlastnosti[0] += asVlastnosti[1][i].ToString();
                                 * //   asVlastnosti[1] = asVlastnosti[1].Substring(1);
                                 * //   //i++;
                                 * //}
                                 *
                                 * i = asVlastnosti[1].Length - 1;
                                 * if (i == -1) {
                                 *      break;
                                 * }
                                 * while (!Char.IsLetter(asVlastnosti[1], i)) {
                                 *      if (asVlastnosti[1][i] == ')' || asVlastnosti[1][i] == '-')
                                 *              break;
                                 *      asVlastnosti[2] += asVlastnosti[1][i].ToString();
                                 *      asVlastnosti[1] = asVlastnosti[1].Substring(0, i);
                                 *      i--;
                                 *      if (i == -1) {
                                 *              break;
                                 *      }
                                 * }
                                 * if (i == -1) {
                                 *      break;
                                 * }
                                 * sRetrograd = Text.Retrograd(asVlastnosti[1], true);
                                 *
                                 * if (sRetrograd.IndexOf(" ") > 0 && !(sRetrograd.Contains(" – ") || sRetrograd.Contains(" - "))) {
                                 *      asVlastnosti[16] = sRetrograd.Substring(sRetrograd.LastIndexOf(" ") + 1);
                                 *      asVlastnosti[17] = sRetrograd.Substring(0, sRetrograd.LastIndexOf(" "));
                                 * }
                                 * else
                                 *      asVlastnosti[16] = sRetrograd;
                                 */

                                if (sSubVoceId == null)
                                {
                                    //sSubVoce = sHeslo;
                                    sSubVoceId = hi.Id;
                                }

                                /*
                                 * if (sSubVoceId == null) {
                                 *      //sSubVoce = sHeslo;
                                 *      sSubVoceId = asVlastnosti[7];
                                 * }
                                 */

                                //if (sType == null)
                                //    sType = "";

                                //sw.WriteLine(String.Join("|", asVlastnosti));

                                /*
                                 * if (hi.HesloveSlovo == "Žižka") {
                                 *      string sT = hi.HesloveSlovo;
                                 *      bool b = hi.JeInterni;
                                 * }
                                 * */

                                sw.WriteLine(hi.Zaznam());


                                break;

                            case "heslovaStat":
                                sHeslovaStatTyp = r.GetAttribute("type");
                                sHeslovaStatID  = r.GetAttribute("id");
                                sSubVoce        = r.GetAttribute("defaulthw");
                                sPouziti        = r.GetAttribute("use"); //internal, public

                                sSubVoceId = null;
                                break;

                            case "pismeno":
                                sPismeno = r.GetAttribute("id");
                                break;

                            case "heslar":
                                sZdroj = r.GetAttribute("dictionary");
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        public static void HeslarXml(string strVstupniSoubor, string strVystupniSoubor)
        {
            char[] chIndexy     = schIndexy;
            char[] chSeparatory = schSeparatory;

            using (XmlReader r = Objekty.VytvorXmlReader(strVstupniSoubor)) {
                using (XmlWriter xwHeslar = Objekty.VytvorXmlWriter(strVystupniSoubor)) {
                    xwHeslar.WriteStartDocument(true);
                    xwHeslar.WriteStartElement("heslar");

                    #region WHILE
                    while (r.Read())
                    {
                        if (r.NodeType == XmlNodeType.Element)
                        {
                            #region SWITCH
                            switch (r.Name)
                            {
                            case "dictionary":
                                string sSource = r.GetAttribute("name");
                                xwHeslar.WriteAttributeString("dictionary", sSource);
                                break;

                            case "div1":
                                xwHeslar.WriteStartElement("pismeno");
                                xwHeslar.WriteAttributeString("id", r.GetAttribute("id"));
                                xwHeslar.WriteAttributeString("text", r.GetAttribute("text"));
                                break;

                            /*
                             * case "entryref":
                             *       iHw = 0;
                             *       xwHeslar.WriteStartElement("heslovaStat");
                             *       sIdEntry = r.GetAttribute("id");
                             *       xwHeslar.WriteAttributeString("id", sIdEntry);
                             *       xwHeslar.WriteAttributeString("type", "ref");
                             *       break;
                             */
                            case "entry":
                                //iHw = 0;
                                xwHeslar.WriteStartElement("heslovaStat");
                                Transformace.SerializeAttributes(r, xwHeslar, false);
                                //sIdEntry = r.GetAttribute("id");
                                //xwHeslar.WriteAttributeString("id", sIdEntry);
                                //string sTypEntry = r.GetAttribute("type");
                                //if (null != sTypEntry)
                                //    xwHeslar.WriteAttributeString("type", sTypEntry);
                                break;

                            case "hwo":
                            case "hw":
                                //zkontrolovat, jestli odstavec obsahuje "nenáležitá podoba" - a pak heslo vyřadit/označit jako interní
                                //jenže akce následuje až za heslovým slovem
                                string sForma = r.GetAttribute("form");
                                string sHom   = r.GetAttribute("hom");
                                Transformace.SerializeNode(r, xwHeslar);
                                string strHeslo = r.ReadString();
                                strHeslo = strHeslo.Trim();
                                for (int i = 0; i < chIndexy.Length; i++)
                                {
                                    if (strHeslo.Contains(chIndexy[i].ToString()))
                                    {
                                        strHeslo = strHeslo.Remove(strHeslo.IndexOf(chIndexy[i]), 1);
                                        if (sHom == null)
                                        {
                                            xwHeslar.WriteAttributeString("hom", chIndexy[i].ToString());     //je potřeba to zapisovat, nebo ne?
                                        }
                                        break;
                                    }
                                }
                                if (strHeslo.IndexOf('-') == strHeslo.Length - 1 || strHeslo.IndexOf('-') == 0)
                                {
                                    if (sForma == null)
                                    {
                                        xwHeslar.WriteAttributeString("form", "short");
                                    }
                                }
                                if (strHeslo.Contains("(?)"))
                                {
                                    strHeslo = strHeslo.Replace("(?)", "");     //otazník v závorce za heslem
                                }
                                strHeslo = strHeslo.TrimEnd(chSeparatory);
                                strHeslo = strHeslo.TrimEnd();
                                //strHeslo = strHeslo.TrimEnd(chIndexy);
                                if (strHeslo.Length > 0)
                                {
                                    char chPismeno = strHeslo[0];
                                    if (chPismeno == '*' || chPismeno == '\u02E3')        //  || chPismeno == '\u02DF')  - zobrazovalo se špatně v IE
                                    //nemělo by se takové heslo upravit tak, že se odstraní první znak?
                                    {
                                        xwHeslar.WriteAttributeString("pref", strHeslo.Substring(0, 1));
                                    }

                                    xwHeslar.WriteString(strHeslo);
                                }

                                /*
                                 * while (r.Name != "")
                                 * {
                                 *       r.Read();
                                 * }
                                 *       SerializeNode(r, xwHeslar);
                                 */
                                /*
                                 * string sTyp = r.GetAttribute("type");
                                 * string strHeslo = r.ReadString();
                                 * strHeslo = strHeslo.Trim();
                                 * strHeslo = strHeslo.TrimEnd(chSeparatory);
                                 * strHeslo = strHeslo.TrimEnd();
                                 * string[] aHesla = strHeslo.Split(chSeparatory);
                                 * foreach (string s in aHesla) {
                                 *       string sText = s.Trim();
                                 *       if (s.Length > 0) {
                                 *                    xwHeslar.WriteStartElement("hw");
                                 *                    if (sTyp != null)
                                 *                              xwHeslar.WriteAttributeString("type",sTyp);
                                 ++iHw;
                                 *                    xwHeslar.WriteAttributeString("id", sIdEntry + ".hw" + iHw.ToString());
                                 *
                                 *                    xwHeslar.WriteString(sText);
                                 *                    xwHeslar.WriteEndElement();
                                 *       }
                                 * }
                                 */
                                break;
                            }
                            #endregion
                        }
                        #region IF2
                        if (r.NodeType == XmlNodeType.EndElement)
                        {
                            switch (r.Name)
                            {
                            case "div1":
                                xwHeslar.WriteEndElement();
                                break;

                            case "entry":
                                xwHeslar.WriteEndElement();
                                break;

                            case "hwo":
                            case "hw":
                                xwHeslar.WriteEndElement();
                                break;
                            }
                        }
                        #endregion
                    }
                    #endregion
                }
            }
        }
Exemplo n.º 10
0
        public static void HeslarXml(string strVstupniSoubor, string strVystupniSoubor, Dictionary <string, ZpracovatTagProHeslarXml> gztTagyZpracovani)
        {
            char[] chIndexy     = schIndexy;
            char[] chSeparatory = schSeparatory;

            using (XmlReader r = Objekty.VytvorXmlReader(strVstupniSoubor)) {
                using (XmlWriter xwHeslar = Objekty.VytvorXmlWriter(strVystupniSoubor)) {
                    xwHeslar.WriteStartDocument(true);
                    xwHeslar.WriteStartElement("heslar");
                    string          strNazevTagu   = null;
                    HesloInfo       hiHeslo        = null;
                    PismenoInfo     piPismeno      = null;
                    HeslovaStatInfo hsiHeslovaStat = null;

                    #region WHILE
                    while (r.Read())
                    {
                        strNazevTagu = r.Name;
                        if (r.NodeType == XmlNodeType.Element)
                        {
                            if (gztTagyZpracovani != null && gztTagyZpracovani.ContainsKey(strNazevTagu))
                            {
                                gztTagyZpracovani[strNazevTagu](r, xwHeslar, piPismeno, hsiHeslovaStat, hiHeslo);
                            }
                            else
                            {
                                #region SWITCH
                                switch (r.Name)
                                {
                                case "dictionary":
                                    string sSource = r.GetAttribute("name");
                                    xwHeslar.WriteAttributeString("dictionary", sSource);
                                    break;

                                case "div1":
                                    piPismeno      = new PismenoInfo();
                                    piPismeno.Id   = r.GetAttribute("id");
                                    piPismeno.Text = r.GetAttribute("text");

                                    VypisZacatekPismene(xwHeslar, piPismeno);
                                    break;

                                /*
                                 * case "entryref":
                                 *       iHw = 0;
                                 *       xwHeslar.WriteStartElement("heslovaStat");
                                 *       sIdEntry = r.GetAttribute("id");
                                 *       xwHeslar.WriteAttributeString("id", sIdEntry);
                                 *       xwHeslar.WriteAttributeString("type", "ref");
                                 *       break;
                                 */
                                case "entry":
                                    //iHw = 0;
                                    hsiHeslovaStat     = new HeslovaStatInfo();
                                    hsiHeslovaStat.Id  = r.GetAttribute("id");
                                    hsiHeslovaStat.Typ = r.GetAttribute("type");
                                    xwHeslar.WriteStartElement("heslovaStat");
                                    Transformace.SerializeAttributes(r, xwHeslar, false);
                                    //sIdEntry = r.GetAttribute("id");
                                    //xwHeslar.WriteAttributeString("id", sIdEntry);
                                    //string sTypEntry = r.GetAttribute("type");
                                    //if (null != sTypEntry)
                                    //    xwHeslar.WriteAttributeString("type", sTypEntry);
                                    break;

                                case "hw":
                                    //zkontrolovat, jestli odstavec obsahuje "nenáležitá podoba" - a pak heslo vyřadit/označit jako interní
                                    //jenže akce následuje až za heslovým slovem
                                    string sForma = r.GetAttribute("form");
                                    Transformace.SerializeNode(r, xwHeslar);
                                    string strHeslo = r.ReadString();
                                    strHeslo = strHeslo.Trim();
                                    for (int i = 0; i < chIndexy.Length; i++)
                                    {
                                        if (strHeslo.Contains(chIndexy[i].ToString()))
                                        {
                                            strHeslo = strHeslo.Remove(strHeslo.IndexOf(chIndexy[i]), 1);
                                            //xwHeslar.WriteAttributeString("hom", chIndexy[i].ToString());
                                            break;
                                        }
                                    }
                                    if (strHeslo.IndexOf('-') == strHeslo.Length - 1 || strHeslo.IndexOf('-') == 0)
                                    {
                                        if (sForma == null)
                                        {
                                            xwHeslar.WriteAttributeString("form", "short");
                                        }
                                    }
                                    if (strHeslo.Contains("(?)"))
                                    {
                                        strHeslo = strHeslo.Replace("(?)", "");   //otazník v závorce za heslem
                                    }
                                    strHeslo = strHeslo.TrimEnd(chSeparatory);
                                    strHeslo = strHeslo.TrimEnd();
                                    //strHeslo = strHeslo.TrimEnd(chIndexy);
                                    if (strHeslo.Length > 0)
                                    {
                                        char chPismeno = strHeslo[0];
                                        if (chPismeno == '*' || chPismeno == '\u02E3')      //  || chPismeno == '\u02DF')  - zobrazovalo se špatně v IE
                                        //nemělo by se takové heslo upravit tak, že se odstraní první znak?
                                        {
                                            xwHeslar.WriteAttributeString("pref", strHeslo.Substring(0, 1));
                                        }

                                        xwHeslar.WriteString(strHeslo);
                                    }
                                    break;
                                }
                                #endregion
                            }
                        }
                        #region IF2
                        if (r.NodeType == XmlNodeType.EndElement)
                        {
                            if (gztTagyZpracovani != null && gztTagyZpracovani.ContainsKey(strNazevTagu))
                            {
                                gztTagyZpracovani[strNazevTagu](r, xwHeslar, piPismeno, hsiHeslovaStat, hiHeslo);
                            }
                            else
                            {
                                switch (r.Name)
                                {
                                case "div1":
                                    xwHeslar.WriteEndElement();
                                    break;

                                case "entry":
                                    xwHeslar.WriteEndElement();
                                    break;

                                case "hw":
                                    xwHeslar.WriteEndElement();
                                    break;
                                }
                            }
                        }
                        #endregion
                    }
                    #endregion
                }
            }
        }