コード例 #1
0
        public bool TryGetChar(string input, out char recognizedCharacter)
        {
            recognizedCharacter = '\0';
            var isKnownChar = false;

            foreach (var vector in _inputVectorsWithNames)
            {
                if (string.IsNullOrEmpty(vector.Key) || vector.Key.Length > 1)
                {
                    throw new ArgumentException("Cannot associate output with letter. Check file names.");
                }

                if (!string.Equals(input, vector.Value))
                {
                    if (!FuzzyStringComparer.Equals(input, vector.Value))
                    {
                        continue;
                    }
                }
                isKnownChar         = true;
                recognizedCharacter = char.Parse(vector.Key);
                break;
            }

            return(isKnownChar);
        }
コード例 #2
0
        //execute scraper search using specified param's, return results
        List <ScraperResult> getMatches(ScraperSearchParams searchParams)
        {
            Dictionary <string, string> paramList = new Dictionary <string, string>();

            if (searchParams.Term != null)
            {
                paramList["search.title"] = searchParams.Term;
            }
            if (searchParams.Platform != null)
            {
                paramList["search.platform"] = searchParams.Platform;
            }
            if (searchParams.PlatformId != null)
            {
                paramList["search.platformid"] = searchParams.PlatformId;
            }

            List <ScraperResult>        results        = new List <ScraperResult>();
            Dictionary <string, string> scraperResults = scraper.Execute("search", paramList);

            if (scraperResults == null)
            {
                return(results);
            }

            int count = 0;

            //loop and build results
            while (scraperResults.ContainsKey("game[" + count + "].site_id"))
            {
                string siteId, title, yearmade, system, prefix = "game[" + count + "].";
                if (!scraperResults.TryGetValue(prefix + "site_id", out siteId))
                {
                    continue;
                }
                if (scraperResults.TryGetValue(prefix + "system", out system))
                {
                    system = system.Trim();
                }
                scraperResults.TryGetValue(prefix + "title", out title);
                scraperResults.TryGetValue(prefix + "yearmade", out yearmade);
                results.Add(new ScraperResult(siteId, title, system, yearmade, this)
                {
                    SearchParams   = searchParams,
                    SearchDistance = FuzzyStringComparer.Score(searchParams.Term, ScraperProvider.RemoveSpecialChars(title))
                });
                count++;
            }

            return(results);
        }
コード例 #3
0
        public ScraperResult GetResult(Scraper scraper)
        {
            ScraperResult result;

            if (!cachedResults.TryGetValue(scraper, out result))
            {
                result = scraper.GetFirstMatch(searchParams);
                if (result != null && FuzzyStringComparer.Score(searchTerm, ScraperProvider.RemoveSpecialChars(result.Title)) > 2)
                {
                    result = null;
                }
                cachedResults[scraper] = result;
            }
            return(result);
        }