Beispiel #1
0
 private static void VypsatKompletniEntry(XmlWriter xw, string strRadek, HeslovaSlova glsHeslovaSlova, int iPoradi)
 {
     xw.WriteStartElement("entry");
     xw.WriteAttributeString("source", csZkratkaSlovniku);
     xw.WriteAttributeString("id", "h" + iPoradi.ToString("000000"));
     xw.WriteElementString("original", strRadek);
     VypsatJednotlivaHeslovaSlova(xw, glsHeslovaSlova, iPoradi);
     xw.WriteEndElement();             //entry
 }
Beispiel #2
0
        private static void VypsatJednotlivaHeslovaSlova(XmlWriter xw, HeslovaSlova glsHeslovaSlova, int iPoradi)
        {
            int iPodporadi = 0;

            foreach (HesloveSlovo hs in glsHeslovaSlova)
            {
                if (!hs.Odkaz && !hs.Transliterace && !String.IsNullOrEmpty(hs.Heslo))
                {
                    iPodporadi++;
                    xw.WriteStartElement("hw");
                    xw.WriteAttributeString("id", String.Format("h{0:000000}.{1}", iPoradi, iPodporadi));
                    xw.WriteAttributeString("source", csZkratkaSlovniku);
                    if (hs.Varianta)
                    {
                        xw.WriteAttributeString("var", "true");
                    }
                    if (hs.Odkaz)
                    {
                        xw.WriteAttributeString("xref", "true");
                    }
                    if (hs.ZenskaPodoba)
                    {
                        xw.WriteAttributeString("fem", "true");
                    }
                    if (hs.RekonstruovanoZMistnihoJmena)
                    {
                        xw.WriteAttributeString("type", "reconstr");
                    }
                    if (hs.Transliterace)
                    {
                        xw.WriteAttributeString("form", "trsl");
                    }
                    if (hs.NejisteZneni)
                    {
                        xw.WriteAttributeString("cert", "uncertain");
                    }
                    if (hs.NejistyPramen)
                    {
                        xw.WriteAttributeString("sourceCert", "uncertain");
                    }
                    if (hs.JineCteni)
                    {
                        xw.WriteAttributeString("reading", "other");
                    }
                    if (hs.VychoziPodoba)
                    {
                        xw.WriteAttributeString("sourceForm", "true");
                    }
                    if (hs.ZmenenaPdodoba)
                    {
                        xw.WriteAttributeString("changedForm", "true");
                    }
                    if (hs.Rod != null)
                    {
                        xw.WriteAttributeString("gender", hs.Rod);
                    }

                    xw.WriteString(hs.Heslo);
                    xw.WriteEndElement();                    //hw
                }
            }
        }
Beispiel #3
0
        private static void VytvoritJednotlivaHeslovaSlova(XmlDocument xd, HeslovaSlova glsHeslovaSlova, int iPoradi)
        {
            int iPodporadi = 0;
            //xd.DocumentElement.RemoveChild(xd.DocumentElement.SelectSingleNode("//hw"));
            XmlNode xe = xd.DocumentElement.SelectSingleNode("//hw");

            xe = Index.RenameNode(xe, "", "hwo");             //hwo = headword original
            bool bInterni = (glsHeslovaSlova.Count == 1 && glsHeslovaSlova[0].Heslo == xe.InnerText);
            //if (glsHeslovaSlova.Count == 1 && glsHeslovaSlova[0].Heslo == xe.InnerText)
            //  return;
            XmlNode xhwg = xd.CreateElement("hwGrp");

            foreach (HesloveSlovo hs in glsHeslovaSlova)
            {
                if (!hs.Odkaz && !hs.Transliterace && !String.IsNullOrEmpty(hs.Heslo))
                {
                    iPodporadi++;
                    XmlNode xnhw = xd.CreateElement("hw");
                    PripojitAtribut(xd, xnhw, "id", String.Format("h{0:000000}.{1}", iPoradi, iPodporadi));
                    //PripojitAtribut(xd, xnhw, "source", csZkratkaSlovniku)
                    if (hs.Varianta)
                    {
                        //PripojitAtribut(xd, xnhw, "variant", "true");
                        PripojitAtribut(xd, xnhw, "variant", hs.TypVarianty);
                    }
                    if (hs.Odkaz)
                    {
                        PripojitAtribut(xd, xnhw, "xref", "true");
                    }
                    if (hs.ZenskaPodoba)
                    {
                        PripojitAtribut(xd, xnhw, "fem", "true");
                    }
                    if (hs.RekonstruovanoZMistnihoJmena)
                    {
                        PripojitAtribut(xd, xnhw, "type", "reconstr");
                    }
                    if (hs.Transliterace)
                    {
                        PripojitAtribut(xd, xnhw, "form", "trsl");
                    }
                    if (hs.NejisteZneni)
                    {
                        PripojitAtribut(xd, xnhw, "cert", "uncertain");
                    }
                    if (hs.NejistyPramen)
                    {
                        PripojitAtribut(xd, xnhw, "sourceCert", "uncertain");
                    }
                    if (hs.JineCteni)
                    {
                        PripojitAtribut(xd, xnhw, "reading", "other");
                    }
                    if (hs.VychoziPodoba)
                    {
                        PripojitAtribut(xd, xnhw, "sourceForm", "true");
                    }
                    if (hs.ZmenenaPdodoba)
                    {
                        PripojitAtribut(xd, xnhw, "changedForm", "true");
                    }
                    if (hs.Rod != null)
                    {
                        PripojitAtribut(xd, xnhw, "gender", hs.Rod);
                    }
                    if (hs.RozepsanaForma)
                    {
                        PripojitAtribut(xd, xnhw, "form", "restored");
                    }
                    if (hs.ZkracenaForma)
                    {
                        PripojitAtribut(xd, xnhw, "form", "short");
                    }
                    if (bInterni)
                    {
                        PripojitAtribut(xd, xnhw, "use", "internal");
                    }
                    xnhw.InnerText = hs.Heslo;
                    xhwg.AppendChild(xnhw);
                }
                xd.DocumentElement.AppendChild(xhwg);
            }
        }
Beispiel #4
0
        internal HeslovaSlova AnalyzujHeslo(XmlWriter xw, string strRadek, ref int iPoradi)
        {
            char[] cchOddelovaceHesel = new char[] { '/', '>', ',' };
            //1. rozdělit řádek na hesla
            //2. analyzovat jednotlivá hesla
            HeslovaSlova glsHeslovaSlova = new HeslovaSlova(strRadek);

            char[] chZnaky = new char[] { ' ', '-', '!', '(', ')', '*', ',', '.', '/', ':', '?', '[', ']', '_', '>' };
            if (strRadek.IndexOfAny(cchOddelovaceHesel) > -1)
            {
                FrekvenceZnaku fz = new FrekvenceZnaku(chZnaky, strRadek.Trim(), true);
                fz.SpocitejFrekvenci();
                if (fz.PoradiZnaku.Contains('>'))
                {
                    string[] asHesla = strRadek.Split(cchOddelovaceHesel, StringSplitOptions.RemoveEmptyEntries);
                    glsHeslovaSlova.Add((new HesloveSlovo(asHesla[0].Trim(), true, false)));
                    glsHeslovaSlova.Add((new HesloveSlovo(asHesla[1].Trim(), false, true)));
                }
                else if (fz.PoradiZnaku == "(/)")
                {
                    string[] asHesla = strRadek.Split(cchOddelovaceHesel, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string sHeslo in asHesla)
                    {
                        if (sHeslo.StartsWith("("))
                        {
                            glsHeslovaSlova.Add((new HesloveSlovo(true, sHeslo.Trim() + ")", "/")));
                        }
                        else
                        {
                            glsHeslovaSlova.Add((new HesloveSlovo(true, "(" + sHeslo.Trim(), "/")));
                        }
                    }
                }
                else if (fz.PoradiZnaku == " (., . ?)")
                {
                    glsHeslovaSlova.Add((new HesloveSlovo(true, strRadek.Trim())));
                }
                else
                {
                    string strOddelovac = ",";
                    if (fz.PoradiZnaku.IndexOf('/') > -1)
                    {
                        strOddelovac = "/";
                    }
                    else if (fz.PoradiZnaku.IndexOf(',') > -1)
                    {
                        strOddelovac = ",";
                    }
                    else
                    {
                        strOddelovac = "";
                    }
                    string[] asHesla = strRadek.Split(cchOddelovaceHesel, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string sHeslo in asHesla)
                    {
                        glsHeslovaSlova.Add((new HesloveSlovo(true, sHeslo.Trim(), strOddelovac)));
                    }
                }
            }
            else
            {
                glsHeslovaSlova.Add(new HesloveSlovo(strRadek));
            }
            glsHeslovaSlova.KonsolidujHesla();

            if (strRadek.IndexOfAny(new char[] { '_', ':' }) == -1)
            {
                VypsatKompletniEntry(xw, strRadek, glsHeslovaSlova, ++iPoradi);
                return(glsHeslovaSlova);
            }
            else
            {
                return(new HeslovaSlova(strRadek));
            }
        }
Beispiel #5
0
        public void PrevestTxtNaXml()
        {
            List <string> glsVsechnaHesla = new List <string>(18000);
            Dictionary <string, List <HeslovaSlova> > gdcHeslovaSlova = new Dictionary <string, List <HeslovaSlova> >();
            XmlWriterSettings xws = new XmlWriterSettings();

            xws.Indent      = true;
            xws.IndentChars = " ";
            Dictionary <string, HeslovaSlova> glsDuplicitniHesla = new Dictionary <string, HeslovaSlova>();

            using (StreamReader sr = new StreamReader(base.VstupniSoubor)) {
                using (XmlWriter xw = XmlWriter.Create(base.VystupniSoubor, xws)) {
                    xw.WriteStartDocument(true);
                    xw.WriteStartElement("dictionary");
                    xw.WriteAttributeString("name", csZkratkaSlovniku);
                    string sRadek;
                    int    i = 0;
                    while ((sRadek = sr.ReadLine()) != null)
                    {
                        if (sRadek[sRadek.Length - 1] != '-')
                        {
                            HeslovaSlova hss = AnalyzujHeslo(xw, sRadek, ref i);
                            foreach (HesloveSlovo hs in hss)
                            {
                                if (!String.IsNullOrEmpty(hs.Heslo))
                                {
                                    string sIdHeslo = hs.Heslo + " " + hs.Rod;
                                    if (gdcHeslovaSlova.ContainsKey(sIdHeslo))
                                    {
                                        gdcHeslovaSlova[sIdHeslo].Add(hss);
                                    }
                                    else
                                    {
                                        gdcHeslovaSlova.Add(sIdHeslo, new List <HeslovaSlova>(new HeslovaSlova[] { hss }));
                                    }
                                    if (glsVsechnaHesla.Contains(sIdHeslo))
                                    {
                                        glsDuplicitniHesla.Add(sIdHeslo, hss);
                                    }
                                    else
                                    {
                                        glsVsechnaHesla.Add(sIdHeslo);
                                    }
                                }
                            }
                        }
                    }
                    xw.WriteEndElement();                     //dictionary
                    xw.WriteEndDocument();
                }
            }
            Console.WriteLine("Duplicitní hesla:");

            using (XmlWriter xw = XmlWriter.Create(base.VystupniSoubor.Replace(".xml", "_dupl.xml"), xws)) {
                xw.WriteStartDocument(true);
                xw.WriteStartElement("dictionary");
                xw.WriteAttributeString("name", csZkratkaSlovniku);
                xw.WriteAttributeString("duplicity", "true");

                foreach (KeyValuePair <string, List <HeslovaSlova> > kvp in gdcHeslovaSlova)
                {
                    if (kvp.Value.Count > 1)
                    {
                        xw.WriteStartElement("duplicita");
                        xw.WriteAttributeString("heslo", kvp.Key);
                        foreach (HeslovaSlova hs in kvp.Value)
                        {
                            VypsatKompletniEntry(xw, hs.OriginalniPodoba, hs, 0);
                        }

                        xw.WriteEndElement();
                    }
                }

                //foreach (KeyValuePair<string, HeslovaSlova> kvp in glsDuplicitniHesla) {
                //  xw.WriteStartElement("duplicita");
                //  xw.WriteAttributeString("heslo", kvp.Key);
                //  VypsatKompletniEntry(xw, kvp.Key, kvp.Value);
                //  xw.WriteEndElement();
                //}
                xw.WriteFullEndElement();
                xw.WriteEndDocument();
            }
        }