Public
Authored by Mohd Firdaus Poat Kamal

Mongo FastData

Edited
1.45 KB
  • Top Emotion Aggregation

    db.getCollection('tweet_1mdb').aggregate(

    {$match: { AnalysisEmotion: { $exists: true } } },
    {$project : {AnalysisEmotion:'$AnalysisEmotion.document.AnalysisEmotion',_id:0}},
    {$group: {_id: null, 
        anger: { $avg: "$AnalysisEmotion.anger" },
        disgust: { $avg: "$AnalysisEmotion.disgust" },
        fear: { $avg: "$AnalysisEmotion.fear" },
        joy: { $avg: "$AnalysisEmotion.joy" },
        sadness: { $avg: "$AnalysisEmotion.sadness" },
    }}

    )

    //refactor

    db.getCollection('tweet_1mdb').aggregate( {$match: { AnalysisEmotion: { $exists: true } } }, {$project : {AnalysisEmotion:'$AnalysisEmotion.document.AnalysisEmotion',_id:0}}, {$group: {_id: null, anger: { $avg: "$AnalysisEmotion.anger" },disgust: { $avg: "$AnalysisEmotion.disgust" },fear: { $avg: "$AnalysisEmotion.fear" },joy: { $avg: "$AnalysisEmotion.joy" },sadness: { $avg: "$AnalysisEmotion.sadness" },}} )

  • Top Emotion

    db.getCollection('tweet_1mdb').aggregate( {$match: { AnalysisSentiment: { $exists: true } } }, {$project: { score:'$AnalysisSentiment.document.score', sentiment:{ $switch: { branches: [ { case: { $gt : [ "$AnalysisSentiment.document.score" , 0 ] }, then: "Positive" }, { case: { $lt : [ "$AnalysisSentiment.document.score" , 0 ] }, then: "Negative" } ], default: "Neutral" } } } }, {$group : {'_id': {'sentiment': '$sentiment',},count:{$sum:1}}}, {$project: {sentiment: '$_id.sentiment',count:1 }} )

    db.getCollection('tweet_1mdb').aggregate( {$match: { AnalysisSentiment: { $exists: true } } }, {$project:{score:'$AnalysisSentiment.document.score',sentiment:{$switch:{branches: [{case: { $gt : [ "$AnalysisSentiment.document.score" , 0 ] },then: "Positive"},{case: { $lt : [ "$AnalysisSentiment.document.score", 0 ] },then: "Negative"}],default: "Neutral"}}}}, {$group : {'_id': {'sentiment': '$sentiment',},count:{$sum:1}}}, {$project: {sentiment: '$_id.sentiment',count:1 }} )

    Edited by Al khan Abdul Gani
  • Hashtag Aggregation

    db.getCollection('tweet_1mdb').aggregate( { $match: { aylienHashtags: { $exists: true } } }, { $project : { hashtags:'$aylienHashtags.hashtags.hashtags',_id:0}}, { $unwind : '$hashtags' }, { $group: { _id: { 'text':'$hashtags'}, count:{$sum:1} }}, { $project : { text:'$_id.text',count:1, _id:0}}, { $sort: {count:-1}}, { $limit:50} )

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment