static DictItem encodeHtml(DictFoundRes root, XNode nd, Dictionary <string, short> tagStrToInt) { Func <short, string, DictItem> createRes = (tag, text) => { var res = root == null ? new DictItem() : new DictItemRoot { type = root.type }; //, soundFiles = new string[] { root.entry.soundMaster } }; res.tag = tag; res.text = text; return(res); }; if (nd.NodeType == System.Xml.XmlNodeType.Text) { return(createRes(0, ((XText)nd).Value)); } else { var el = nd as XElement; var res = createRes(tagStrToInt[tagToStr(el)], null); var nodes = el.Nodes(); var first = nodes.FirstOrDefault(); if (first != null && first.NodeType == System.Xml.XmlNodeType.Text) { nodes = nodes.Skip(1); res.text = ((XText)first).Value; } if (nodes.Count() > 0) { res.items = nodes.Select(n => encodeHtml(null, n, tagStrToInt)).ToArray(); } return(res); } }
public void dictForText(Dictionary <string, List <string> > wordForms, CourseMeta.CacheDict res) { var entries = new Dictionary <string, DictFoundRes>(); foreach (var wordForm in wordForms) //kv.key - hledane slovo, kv.Value - hledane slovo + lowercase hledane slovo + seznam zakladnich tvaru slova { DictEntryObj dictEntry = find(wordForm.Value); //vrat ze vsech kandidatu jedno nalezne entry (dle zvolene strategie) if (dictEntry == null) { res.notFound.Add(wordForm.Key); continue; } //nenalezeno => dej mezi nenalezene string key = DictFoundRes.getKey(dictEntry.type, dictEntry.entryId); //nalezeno - klic DictFoundRes entry; if (!entries.TryGetValue(key, out entry)) { entries.Add(key, entry = new DictFoundRes { entry = dictEntry }); // najdi dle klice lock (dictEntry) { var snd = dictEntry.entry.Descendants("sound").FirstOrDefault(); var sndVal = snd == null ? null : snd.Value; if (sndVal != null) { if (sndVal.StartsWith("@")) { snd.Remove(); } else { res.externals.Add(sndVal); } } } } entry.words.Add(wordForm.Key); //pridej ohyb tvar } res.dict = createDict(entries.Values); //k nalezenym heslum vytvori slovnik res.dict.crsLang = crsData.crsLang; res.dict.natLang = natLang; }
List <ILookup <string, DictEntryObj> > sourcesLower = new List <ILookup <string, DictEntryObj> >(); //tabulka case unsenzitive headword => hesla public XElement findEntry(string word, Action <XElement> modifySoundTag = null) { foreach (var w in crsData.getWordsForms(XExtension.Create(word))) { DictEntryObj dictEntry = find(w.Value); if (dictEntry == null) { continue; } string key = DictFoundRes.getKey(dictEntry.type, dictEntry.entryId); var snd = dictEntry.entry.Descendants("sound").FirstOrDefault(); if (modifySoundTag != null && snd != null) { modifySoundTag(snd); } else if (snd != null && snd.Value.StartsWith("@")) { snd.Remove(); } return(dictEntry.entry); } return(null); }