ExtractMentionEntities() 공개 정적인 메소드

テキストからメンションを抽出してエンティティとして返します
public static ExtractMentionEntities ( string text ) : IEnumerable
text string
리턴 IEnumerable
예제 #1
0
        private async Task SetDescriptionAsync(string descriptionText, TwitterEntities entities, CancellationToken cancellationToken)
        {
            if (descriptionText != null)
            {
                foreach (var entity in entities.Urls)
                {
                    entity.ExpandedUrl = await ShortUrl.Instance.ExpandUrlAsync(entity.ExpandedUrl);
                }

                // user.entities には urls 以外のエンティティが含まれていないため、テキストをもとに生成する
                entities.Hashtags     = TweetExtractor.ExtractHashtagEntities(descriptionText).ToArray();
                entities.UserMentions = TweetExtractor.ExtractMentionEntities(descriptionText).ToArray();

                var html = TweetFormatter.AutoLinkHtml(descriptionText, entities);
                html = this.mainForm.createDetailHtml(html);

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                this.DescriptionBrowser.DocumentText = html;
            }
            else
            {
                this.DescriptionBrowser.DocumentText = "";
            }
        }
예제 #2
0
        public void ExtractMentionEntities_SurrogatePairTest()
        {
            var entity = TweetExtractor.ExtractMentionEntities("🍣 @twitterapi").Single();

            Assert.Equal(new[] { 2, 13 }, entity.Indices);
            Assert.Equal("twitterapi", entity.ScreenName);
        }
예제 #3
0
        private async Task SetDescriptionAsync(string?descriptionText, TwitterEntities?entities, CancellationToken cancellationToken)
        {
            if (descriptionText != null)
            {
                var urlEntities = entities?.Urls ?? Array.Empty <TwitterEntityUrl>();

                foreach (var entity in urlEntities)
                {
                    entity.ExpandedUrl = await ShortUrl.Instance.ExpandUrlAsync(entity.ExpandedUrl);
                }

                // user.entities には urls 以外のエンティティが含まれていないため、テキストをもとに生成する
                var mergedEntities = urlEntities.AsEnumerable <TwitterEntity>()
                                     .Concat(TweetExtractor.ExtractHashtagEntities(descriptionText))
                                     .Concat(TweetExtractor.ExtractMentionEntities(descriptionText))
                                     .Concat(TweetExtractor.ExtractEmojiEntities(descriptionText));

                var html = TweetFormatter.AutoLinkHtml(descriptionText, mergedEntities);
                html = this.mainForm.createDetailHtml(html);

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                this.DescriptionBrowser.DocumentText = html;
            }
            else
            {
                this.DescriptionBrowser.DocumentText = "";
            }
        }
예제 #4
0
        public void ExtractMentionEntities_ListTest()
        {
            var entity = TweetExtractor.ExtractMentionEntities("hogehoge @twitter/developers").Single();

            // Indices は「@twitter/developers」の範囲を指すが、ScreenName には「@」を含めない
            Assert.Equal(new[] { 9, 28 }, entity.Indices);
            Assert.Equal("twitter/developers", entity.ScreenName);
        }
예제 #5
0
        public void ExtractMentionEntities_MultipleTest()
        {
            var entities = TweetExtractor.ExtractMentionEntities("hogehoge @twitterapi @opentween").ToArray();

            Assert.Equal(2, entities.Length);
            Assert.Equal(new[] { 9, 20 }, entities[0].Indices);
            Assert.Equal("twitterapi", entities[0].ScreenName);
            Assert.Equal(new[] { 21, 31 }, entities[1].Indices);
            Assert.Equal("opentween", entities[1].ScreenName);
        }