/// <summary> /// エンティティのコレクションに文字列と絵文字を追加する /// </summary> /// <param name="entities"></param> /// <param name="text"></param> /// <param name="emojis"></param> private static void AddText(TextEntityCollection entities, string text, SocialApis.Mastodon.Emoji[] emojis) { if (emojis?.Length == 0) { entities.AddText(text); return; } var matches = EmojiRegex.Matches(text); if (matches.Count == 0) { entities.AddText(text); return; } if (matches[0].Index != 0) { var firstText = text.Substring(0, matches[0].Index); entities.AddText(firstText); } for (int i = 0; i < matches.Count; ++i) { var m = matches[i]; var shortCode = m.Groups["code"].Value; SocialApis.Mastodon.Emoji emoji = default; foreach (var e in emojis) { if (e.ShortCode == shortCode) { emoji = e; break; } } if (emoji == default) { entities.AddText(m.Value); } else { entities.Add(new EmojiEntity(emoji)); } if (i < matches.Count - 1) { var nextMatch = matches[i + 1]; var content = text.Substring(m.Index + m.Value.Length, nextMatch.Index - m.Index - m.Value.Length); entities.AddText(content); } else if (m.Index + m.Value.Length != text.Length) { int offset = m.Index + m.Value.Length; var content = text[offset..];
/// <summary> /// The maximum length of the text phrase is 1024 characters. /// You can submit up to 30 text phrases in a request. /// </summary> /// <param name="classifier_id"></param> /// <param name="textList"></param> /// <returns></returns> public virtual ClassifyCollectionResponse Classify(string classifier_id, List <string> textList) { TextEntityCollection collection = new TextEntityCollection { collection = textList.Select(t => new TextEntity { text = t }).ToList() }; var response = RepositoryClient .WithAuthentication(ApiKeys.NaturalLanguageClassifierUsername, ApiKeys.NaturalLanguageClassifierPassword) .PostAsync($"{ApiKeys.NaturalLanguageClassifierEndpoint}{classifier_id}{classifyCollectionUrl}") .WithBody(collection) .As <ClassifyCollectionResponse>() .Result; return(response); }