Beispiel #1
0
            private void lookupPinyin(string query,
                                      EntryProvider ep, List <CedictResult> res)
            {
                // Interpret query string
                List <PinyinSyllable> qsylls, qnorm;

                interpretPinyin(query, out qsylls, out qnorm);
                // Get instance vectors
                Dictionary <string, HashSet <int> > candsBySyll = getPinyinCandidates(qnorm);
                // Intersect candidates
                List <int> cands = intersectCandidates(candsBySyll);
                // Retrieve all candidates; verify on the fly
                List <ResWithEntry> rl = retrieveVerifyPinyin(cands, qsylls);

                // Sort pinyin results
                rl.Sort((a, b) => pyComp(a, b));
                // Done.
                res.Capacity = rl.Count;
                for (int i = 0; i != rl.Count; ++i)
                {
                    ResWithEntry rwe = rl[i];
                    res.Add(rwe.Res);
                    ep.AddEntry(rwe.Res.EntryId, rwe.Entry);
                }
            }
Beispiel #2
0
            private void lookupHanzi(string query, EntryProvider ep,
                                     List <CedictResult> res, List <CedictAnnotation> anns)
            {
                // Distinct Hanzi
                query = query.ToUpperInvariant();
                query = query.Trim();
                query = query.Replace(" ", "");
                HashSet <char> qhanzi = new HashSet <char>();

                foreach (char c in query)
                {
                    qhanzi.Add(c);
                }
                // Get instance vectors
                Dictionary <char, HashSet <int> > candsBySimp = new Dictionary <char, HashSet <int> >();
                Dictionary <char, HashSet <int> > candsByTrad = new Dictionary <char, HashSet <int> >();

                if (!getHanziCandidates(qhanzi, candsBySimp, candsByTrad))
                {
                    // If at least one Hanzi doesn't occur in any HW: we're done.
                    return;
                }
                // Intersect candidates
                HashSet <int> candsSimp = intersectCandidates(candsBySimp);
                HashSet <int> candsTrad = intersectCandidates(candsByTrad);
                // Take union
                HashSet <int> cands = new HashSet <int>();

                foreach (int i in candsSimp)
                {
                    cands.Add(i);
                }
                foreach (int i in candsTrad)
                {
                    cands.Add(i);
                }
                // Retrieve all candidates; verify on the fly
                List <ResWithEntry> rl = retrieveVerifyHanzi(cands, query);

                // Sort Hanzi results
                rl.Sort((a, b) => hrComp(a, b));
                // Done.
                res.Capacity = rl.Count;
                for (int i = 0; i != rl.Count; ++i)
                {
                    ResWithEntry rwe = rl[i];
                    res.Add(rwe.Res);
                    ep.AddEntry(rwe.Res.EntryId, rwe.Entry);
                }
            }