Exemple #1
0
            /// <summary>
            /// Loads a language from the provided XML document reference.
            /// </summary>
            /// <param name="xml">A reference to the transliterations XML document.</param>
            public void Load(ref XmlDocument xml)
            {
                if (!loaded)
                {
                    XmlNode languageNode=xml.SelectSingleNode(string.Format(languageXPath,name));
                    XmlNodeList ipaMatches = languageNode.SelectNodes(transcriptionXPath);
                    XmlNodeList romanizationMatches = languageNode.SelectNodes(romanizationXPath);
                    XmlNodeList decompositionMatches = languageNode.SelectNodes(decompositionXPath);

                    foreach (XmlNode m in ipaMatches)
                    {
                        // A little lenient, in that it allows for all or none of these attributes to exist
                        XmlNodeList transcriptionExMatches = m.SelectNodes(transcriptionExXPath);
                        string original = m.GetAttribute("Original");
                        string replacement = m.GetAttribute("Replacement");
                        string prefix = m.GetAttribute("Prefix");
                        string suffix = m.GetAttribute("Suffix");
                        Transcription t = new Transcription(original, replacement, prefix, suffix);

                        foreach (XmlNode n in transcriptionExMatches)
                        {
                            string exOriginal = n.GetAttribute("Original");
                            string exReplacement = n.GetAttribute("Replacement");
                            string exPrefix = n.GetAttribute("Prefix");
                            string exSuffix = n.GetAttribute("Suffix");
                            t.AddException(exOriginal, exReplacement, exPrefix, exSuffix);
                        }

                        transcriptions.Add(t);
                    }

                    foreach (XmlNode m in romanizationMatches)
                    {
                        XmlNodeList transliterationMatches = m.SelectNodes(transliterationXPath);
                        string romanizationName = m.GetAttribute("Name");
                        Romanization r = new Romanization(romanizationName);

                        foreach (XmlNode n in transliterationMatches)
                        {
                            XmlNodeList transliterationExMatches = n.SelectNodes(transliterationExXPath);
                            string original = n.GetAttribute("Original");
                            string replacement = n.GetAttribute("Replacement");
                            string prefix = n.GetAttribute("Prefix");
                            string suffix = n.GetAttribute("Suffix");
                            Transcription t= new Transcription(original, replacement,prefix,suffix);

                            foreach (XmlNode o in transliterationExMatches)
                            {
                                string exOriginal = o.GetAttribute("Original");
                                string exReplacement = o.GetAttribute("Replacement");
                                string exPrefix = o.GetAttribute("Prefix");
                                string exSuffix = o.GetAttribute("Suffix");
                                t.AddException(exOriginal, exReplacement, exPrefix, exSuffix);
                            }
                            r.Transliterations.Add(t);
                        }

                        romanizations.Add(r);
                    }

                    foreach (XmlNode m in decompositionMatches)
                    {
                        XmlNodeList prevFactorsMatches = m.SelectNodes(prevFactorsXPath);

                        int offset = int.Parse(m.GetAttribute("Offset"));
                        int modulus = int.Parse(m.GetAttribute("Modulus"));
                        int divisor = int.Parse(m.GetAttribute("Divisor"));
                        int intercept = int.Parse(m.GetAttribute("Intercept"));
                        int order = int.Parse(m.GetAttribute("Order"));
                        int rangeMin = int.Parse(m.GetAttribute("RangeMin"));
                        int rangeMax = int.Parse(m.GetAttribute("RangeMax"));

                        Decomposition d = new Decomposition(offset, modulus, divisor, intercept, order, rangeMin, rangeMax);

                        foreach (XmlNode n in prevFactorsMatches)
                        {
                            int index = int.Parse(n.GetAttribute("Index"));
                            int multiplyBy = int.Parse(n.GetAttribute("MultiplyBy"));

                            d.PrevFactors.Add(index, multiplyBy);
                        }

                        decompositions.Add(d);
                    }
                }
            }
Exemple #2
0
            /// <summary>
            /// Loads a language from the provided XML document reference.
            /// </summary>
            /// <param name="xml">A reference to the transliterations XML document.</param>
            public void Load(ref XmlDocument xml)
            {
                if (!loaded)
                {
                    XmlNode     languageNode         = xml.SelectSingleNode(string.Format(languageXPath, name));
                    XmlNodeList ipaMatches           = languageNode.SelectNodes(transcriptionXPath);
                    XmlNodeList romanizationMatches  = languageNode.SelectNodes(romanizationXPath);
                    XmlNodeList decompositionMatches = languageNode.SelectNodes(decompositionXPath);

                    foreach (XmlNode m in ipaMatches)
                    {
                        // A little lenient, in that it allows for all or none of these attributes to exist
                        XmlNodeList   transcriptionExMatches = m.SelectNodes(transcriptionExXPath);
                        string        original    = m.GetAttribute("Original");
                        string        replacement = m.GetAttribute("Replacement");
                        string        prefix      = m.GetAttribute("Prefix");
                        string        suffix      = m.GetAttribute("Suffix");
                        Transcription t           = new Transcription(original, replacement, prefix, suffix);

                        foreach (XmlNode n in transcriptionExMatches)
                        {
                            string exOriginal    = n.GetAttribute("Original");
                            string exReplacement = n.GetAttribute("Replacement");
                            string exPrefix      = n.GetAttribute("Prefix");
                            string exSuffix      = n.GetAttribute("Suffix");
                            t.AddException(exOriginal, exReplacement, exPrefix, exSuffix);
                        }

                        transcriptions.Add(t);
                    }

                    foreach (XmlNode m in romanizationMatches)
                    {
                        XmlNodeList  transliterationMatches = m.SelectNodes(transliterationXPath);
                        string       romanizationName       = m.GetAttribute("Name");
                        Romanization r = new Romanization(romanizationName);

                        foreach (XmlNode n in transliterationMatches)
                        {
                            XmlNodeList   transliterationExMatches = n.SelectNodes(transliterationExXPath);
                            string        original    = n.GetAttribute("Original");
                            string        replacement = n.GetAttribute("Replacement");
                            string        prefix      = n.GetAttribute("Prefix");
                            string        suffix      = n.GetAttribute("Suffix");
                            Transcription t           = new Transcription(original, replacement, prefix, suffix);

                            foreach (XmlNode o in transliterationExMatches)
                            {
                                string exOriginal    = o.GetAttribute("Original");
                                string exReplacement = o.GetAttribute("Replacement");
                                string exPrefix      = o.GetAttribute("Prefix");
                                string exSuffix      = o.GetAttribute("Suffix");
                                t.AddException(exOriginal, exReplacement, exPrefix, exSuffix);
                            }
                            r.Transliterations.Add(t);
                        }

                        romanizations.Add(r);
                    }

                    foreach (XmlNode m in decompositionMatches)
                    {
                        XmlNodeList prevFactorsMatches = m.SelectNodes(prevFactorsXPath);

                        int offset    = int.Parse(m.GetAttribute("Offset"));
                        int modulus   = int.Parse(m.GetAttribute("Modulus"));
                        int divisor   = int.Parse(m.GetAttribute("Divisor"));
                        int intercept = int.Parse(m.GetAttribute("Intercept"));
                        int order     = int.Parse(m.GetAttribute("Order"));
                        int rangeMin  = int.Parse(m.GetAttribute("RangeMin"));
                        int rangeMax  = int.Parse(m.GetAttribute("RangeMax"));

                        Decomposition d = new Decomposition(offset, modulus, divisor, intercept, order, rangeMin, rangeMax);

                        foreach (XmlNode n in prevFactorsMatches)
                        {
                            int index      = int.Parse(n.GetAttribute("Index"));
                            int multiplyBy = int.Parse(n.GetAttribute("MultiplyBy"));

                            d.PrevFactors.Add(index, multiplyBy);
                        }

                        decompositions.Add(d);
                    }
                }
            }