Esempio n. 1
0
        static void csb_NactenyRadek(object sender, RadekEventArgs ev)
        {
            HesloInfo hi = new HesloInfo(ev.Text);

            sglsHesloInfo.Add(hi);
        }
Esempio n. 2
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;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
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
                }
            }
        }