Пример #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);
                }
            }
Пример #2
0
        public static void Initialize()
        {
            var dataProvider     = new SQLiteDataProvider();
            var entryProvider    = new EntryProvider(dataProvider);
            var settingsProvider = new SettingsProvider(dataProvider);

            ProC.Register <IEntryProvider>(entryProvider);
            ProC.Register <ISettingsProvider>(settingsProvider);
        }
        private async void UpdateEntries()
        {
            Entries entries = await EntryProvider.Read(Whooing.Instance.DefaultSectionID);

            Entries = new List <string>();
            foreach (var entry in entries.EntryList)
            {
                Entries.Add($"{entry.Item} / {entry.Money} / {entry.LeftAccount} - {entry.RightAccount}");
            }
            OnPropertyChanged("Entries");
        }
Пример #4
0
        public IEnumerable <Models.Sitemap> GenerateSitemaps(SitemapParams param)
        {
            if (string.IsNullOrWhiteSpace(param.BaseUrl))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BaseUrl)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }
            if (param.Culture == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.Culture)), nameof(param));
            }

            var iterationIndex = 1;
            var offset         = 0;

            do
            {
                var entries = EntryProvider.GetEntriesAsync(
                    param,
                    culture: param.Culture,
                    offset: offset,
                    count: NumberOfEntriesPerSitemap
                    ).Result;

                var isEntriesNotEnough = entries.Count() < NumberOfEntriesPerSitemap;

                if (entries.Any())
                {
                    yield return(new Models.Sitemap
                    {
                        Name = isEntriesNotEnough && iterationIndex == 1 ? GetSitemapName(param.Culture) : GetSitemapName(param.Culture, iterationIndex),
                        Entries = entries.ToArray(),
                    });

                    offset         += NumberOfEntriesPerSitemap;
                    iterationIndex += 1;

                    if (isEntriesNotEnough)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }while (true);
        }
Пример #5
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);
                }
            }
        public IEnumerable <Models.Sitemap> GenerateSitemaps(SitemapParams sitemapParams)
        {
            Guard.NotNullOrWhiteSpace(sitemapParams.BaseUrl, nameof(sitemapParams.BaseUrl));
            Guard.NotNullOrWhiteSpace(sitemapParams.Scope, nameof(sitemapParams.Scope));
            Guard.NotNull(sitemapParams.Culture, nameof(sitemapParams.Culture));

            var iterationIndex = 1;
            var offset         = 0;

            do
            {
                var entries = EntryProvider.GetEntriesAsync(
                    sitemapParams,
                    culture: sitemapParams.Culture,
                    offset: offset,
                    count: NumberOfEntriesPerSitemap
                    ).Result;

                var isEntriesNotEnough = entries.Count() < NumberOfEntriesPerSitemap;

                if (entries.Any())
                {
                    yield return(new Models.Sitemap
                    {
                        Name = isEntriesNotEnough && iterationIndex == 1 ? GetSitemapName(sitemapParams.Culture) : GetSitemapName(sitemapParams.Culture, iterationIndex),
                        Entries = entries.ToArray(),
                    });

                    offset         += NumberOfEntriesPerSitemap;
                    iterationIndex += 1;

                    if (isEntriesNotEnough)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }while (true);
        }
Пример #7
0
            public CedictLookupResult Lookup(string query)
            {
                // Prepare
                EntryProvider           ep   = new EntryProvider();
                List <CedictResult>     res  = new List <CedictResult>();
                List <CedictAnnotation> anns = new List <CedictAnnotation>();
                SearchLang sl = SearchLang.Chinese;

                if (hasHanzi(query))
                {
                    lookupHanzi(query, ep, res, anns);
                }
                else
                {
                    lookupPinyin(query, ep, res);
                }

                // Done
                return(new CedictLookupResult(ep, query, res, anns, sl));
            }
Пример #8
0
        /// <summary>
        /// Find entries that match the search expression.
        /// </summary>
        /// <param name="query">The query string, as entered by the user.</param>
        /// <param name="script">For hanzi lookup: simplified, traditional or both.</param>
        /// <param name="lang">Chinese or target language (English).</param>
        /// <returns>The lookup result.</returns>
        public CedictLookupResult Lookup(string query, SearchScript script, SearchLang lang)
        {
            List<CedictResult> res = new List<CedictResult>();
            // BinReader: I own it until I successfully return results to caller.
            BinReader br = new BinReader(dictFileName);
            EntryProvider ep = new EntryProvider(br);

            try
            {
                // Try first in language requested by user
                // If no results that way, try in opposite language
                // Override if lookup in opposite language is successful
                if (lang == SearchLang.Chinese)
                {
                    res = doChineseLookup(br, query, script);
                    // We got fish
                    if (res.Count > 0)
                        return new CedictLookupResult(ep, new ReadOnlyCollection<CedictResult>(res), lang);
                    // OK, try opposite (target)
                    res = doTargetLookup(br, query);
                    // We got fish: override
                    if (res.Count > 0)
                        return new CedictLookupResult(ep, new ReadOnlyCollection<CedictResult>(res), SearchLang.Target);
                }
                else
                {
                    res = doTargetLookup(br, query);
                    // We got fish
                    if (res.Count > 0)
                        return new CedictLookupResult(ep, new ReadOnlyCollection<CedictResult>(res), lang);
                    // OK, try opposite (target)
                    res = doChineseLookup(br, query, script);
                    // We got fish: override
                    if (res.Count > 0)
                        return new CedictLookupResult(ep, new ReadOnlyCollection<CedictResult>(res), SearchLang.Chinese);
                }
                // Sorry, no results, no override
                return new CedictLookupResult(ep, new ReadOnlyCollection<CedictResult>(res), lang);
            }
            catch
            {
                br.Dispose();
                throw;
            }
        }
Пример #9
0
        /// <summary>
        /// Find entries that match the search expression.
        /// </summary>
        /// <param name="query">The query string, as entered by the user.</param>
        /// <param name="script">For hanzi lookup: simplified, traditional or both.</param>
        /// <param name="lang">Chinese or target language (English).</param>
        /// <returns>The lookup result.</returns>
        public CedictLookupResult Lookup(string query, SearchScript script, SearchLang lang)
        {
            List <CedictResult>     res  = new List <CedictResult>();
            List <CedictAnnotation> anns = new List <CedictAnnotation>();
            // BinReader: I own it until I successfully return results to caller.
            BinReader     br = new BinReader(dictFileName);
            EntryProvider ep = new EntryProvider(br);

            try
            {
                // Try first in language requested by user
                // If no results that way, try in opposite language
                // Override if lookup in opposite language is successful
                if (lang == SearchLang.Chinese)
                {
                    res = doChineseLookup(br, query, script);
                    // We got fish
                    if (res.Count > 0)
                    {
                        return(new CedictLookupResult(ep, query, res, anns, lang));
                    }
                    // Try to annotate
                    anns = doAnnotate(br, query);
                    if (anns.Count > 0)
                    {
                        return(new CedictLookupResult(ep, query, res, anns, lang));
                    }
                    // OK, try opposite (target)
                    res = doTargetLookup(br, query);
                    // We got fish: override
                    if (res.Count > 0)
                    {
                        return(new CedictLookupResult(ep, query, res, anns, SearchLang.Target));
                    }
                }
                else
                {
                    res = doTargetLookup(br, query);
                    // We got fish
                    if (res.Count > 0)
                    {
                        return(new CedictLookupResult(ep, query, res, anns, lang));
                    }
                    // OK, try opposite (target)
                    res = doChineseLookup(br, query, script);
                    // We got fish: override
                    if (res.Count > 0)
                    {
                        return(new CedictLookupResult(ep, query, res, anns, SearchLang.Chinese));
                    }
                    // Try to annotate
                    anns = doAnnotate(br, query);
                    if (anns.Count > 0)
                    {
                        return(new CedictLookupResult(ep, query, res, anns, SearchLang.Chinese));
                    }
                }
                // Sorry, no results, no override
                return(new CedictLookupResult(ep, query, res, anns, lang));
            }
            catch
            {
                br.Dispose();
                throw;
            }
        }