示例#1
0
 public void Setup()
 {
     _dictionary = new Jmdictionary();
     _dictionary.Append("a", "1");
     _dictionary.Append("b", "2");
     _dictionary.Append("b", "3");
 }
示例#2
0
 void CreateDictionary()
 {
     using (var nodes = _document.SelectNodes($"/JMdict/entry/k_ele/keb[text()]"))
     {
         foreach (XmlElement n in nodes)
         {
             var gloss = n.ParentNode.ParentNode.SelectSingleNode("sense/gloss");
             if (gloss != null)
             {
                 _dictionary.Append(n.InnerXml, gloss.InnerXml);
             }
         }
     }
 }
示例#3
0
        void ReadDictionary()
        {
            using (var stream = new StreamReader(_path))
                using (var reader = new XmlTextReader(stream)
                {
                    WhitespaceHandling = WhitespaceHandling.None,
                    Namespaces = false
                })
                {
                    string result = null;
                    if (reader.ReadToDescendant("entry"))
                    {
                        while (result == null && reader.ReadToNextSibling("entry"))
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                string word = null;

                                using (var subr = reader.ReadSubtree())
                                {
                                    while (subr.Read())
                                    {
                                        if (subr.Name == "keb" && subr.NodeType == XmlNodeType.Element)
                                        {
                                            word = subr.ReadElementContentAsString();
                                        }
                                        else if (word != null && subr.Name == "gloss" && subr.NodeType == XmlNodeType.Element)
                                        {
                                            _dictionary.Append(word, subr.ReadElementContentAsString());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
        }