【问题标题】:How to remove hashtag, user mentions & URLs from tweet. Twitter4j library(sentiment analysis) does not work properly with these noise words如何从推文中删除主题标签、用户提及和 URL。 Twitter4j 库(情感分析)无法正常处理这些干扰词
【发布时间】:2017-09-10 07:55:17
【问题描述】:

如何从推文中删除主题标签、用户提及和 URL。 Twitter4j 库(情感分析)无法正常处理这些干扰词

示例: 推文:今天早上好#summermorning @evilpriest @holysinner https://goo.le/asxmo/dataload.......

应该看起来像 - 你好今天夏天早上好

twitter4J 本身是否有任何可用的方法或实用程序,或者我们需要自己编写?请指导。

【问题讨论】:

  • 你需要自己写方法

标签: url twitter4j sentiment-analysis hashtag tweets


【解决方案1】:

在通过情感分析管道解析句子之前使用正则表达式过滤掉#es! 使用这个:

String withoutHashTweet = originalTweet.replaceAll("[#]", "");

所以“你好今天早上好#summermorning @evilpriest @holysinner”应该返回:“你好今天早上好summermorning @evilpriest @holysinner”

类似地用@替换代码中的hash来去掉各自的符号

【讨论】:

    【解决方案2】:

    类似的东西:

    let tweet = "@arthurlacoste check this link : http://lit.ly/hugeLink ! so #nsfw";
    
    tweet = tweet.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '') // remove links
            //.replace(/\#\w\w+\s?/g, '') remove hashtags words
            .replace('#', '') // remove hashtags only
            .replace(/\@\w\w+\s?/g, '');  // remove mentions
    
    console.log(tweet);
    
    // output : "check this link :  ! so nsfw" 
    

    【讨论】:

      猜你喜欢
      • 2014-12-14
      • 2017-04-12
      • 2014-02-07
      • 2014-06-14
      • 2014-06-26
      • 2014-05-13
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多