Esempio n. 1
0
        private async Task <IDictionary <string, IList <string> > > ExtractTagsAsync(string html)
        {
            var tags = new Dictionary <string, IList <string> >();

            foreach (Match match in TagRowRegex.Matches(html))
            {
                var name = match.Groups["name"].Value;
                var tag  = (await Task.WhenAll(TagRegex.Matches(match.Groups["content"].Value)
                                               .Select(async t => await _tagTranslationInfo.GetTranslationAsync(name, t.Groups["tag"].Value))))
                           .Select(t => t.Item2).ToList();
                tags.Add((await _tagTranslationInfo.GetTranslationAsync(name)).Item2, tag);
            }

            return(tags);
        }
Esempio n. 2
0
        private async Task <string> GetTranslationAsync(string row, string tag = null)
        {
            if (tag == null)
            {
                switch (row)
                {
                case "Tags":
                    return("标签");

                case "Artists":
                    return("艺术家");

                case "Parodies":
                    return("原作");

                case "Characters":
                    return("角色");

                case "Groups":
                    return("团队");

                case "Languages":
                    return("语言");

                case "Categories":
                    return("分类");
                }
            }
            else
            {
                switch (row)
                {
                case "Tags":
                    var(success, translatedTag) = await _tagTranslationInfo.GetTranslationAsync("female", tag);

                    if (success)
                    {
                        return(translatedTag);
                    }
                    else
                    {
                        (success, translatedTag) = await _tagTranslationInfo.GetTranslationAsync("male", tag);
                    }
                    if (success)
                    {
                        return(translatedTag);
                    }
                    else
                    {
                        (_, translatedTag) = await _tagTranslationInfo.GetTranslationAsync("misc", tag);
                    }
                    return(translatedTag);

                case "Artists":
                    return((await _tagTranslationInfo.GetTranslationAsync("artist", tag)).Item2);

                case "Parodies":
                    return((await _tagTranslationInfo.GetTranslationAsync("parody", tag)).Item2);

                case "Characters":
                    return((await _tagTranslationInfo.GetTranslationAsync("character", tag)).Item2);

                case "Groups":
                    return((await _tagTranslationInfo.GetTranslationAsync("group", tag)).Item2);

                case "Languages":
                    return((await _tagTranslationInfo.GetTranslationAsync("language", tag)).Item2);
                }
            }

            return(tag ?? row);
        }