我正在尝试使用Angular,Node和Express构建一个Twitter情绪分析工具。现在我能够抓取用户推文,删除*一些特殊字符然后当我调用情绪函数时它返回input.lowercase不是一个函数。我尝试使用Sentimental包,它返回了一个非常类似的错误。
router.post("/postUsername", function(req, res){
console.log(req.body.userName);
var client = new Twitter({
consumer_key: ,
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});
client.get('statuses/user_timeline', {screen_name: req.body.userName, count:20}, function(error, tweets, response) {
if (!error) {
var concatenatedTweets = analyzeIt.analyzeIt(tweets);
console.log(concatenatedTweets);
var score = sentiment(concatenatedTweets);
console.log(score);
}
});
});
并且我的分析功能*功能不能像我想要删除的东西那样工作
function analyzeIt(data) {
return data.map(function(item){
var puncutaionLess = item.text.replace("/[.,#!$%^&*;:{}=-_`~()]/g@?" , '');
var finalString = puncutaionLess.replace(/\s{2,}/g," ");
return finalString.replace("#@" , "");
});
};
非常感谢任何帮助?
答案 0 :(得分:0)
你的常规快递很奇怪。
首先,javascript中没有关于正则表达式的引用。
此外,您还没有逃避特殊字符:
item.text.replace("/[.,#!$%^&*;:{}=-_`~()]/g@?" , '');
应该是:
item.text.replace(/[\.,#!$%^&*;:{}=\-_`~()]/g , '');
注意.
您可能还想在其中添加[]
:
例如:
text = "hello[!] there!";
text = text.replace(/[\.\[\],#!$%^&*;:{}=\-_`~()]/g , '');
console.log(text)