Пример #1
0
        private void button2_Click(object sender, EventArgs e) //получить список комментариев выбранной группы
        {
            List <string> commentsList = new List <string>();
            string        s            = dataGridViewGroups.Rows[dataGridViewGroupsSelectedRowIndex].Cells[0].Value.ToString();
            long          groupId      = Convert.ToInt64(dataGridViewGroups.Rows[dataGridViewGroupsSelectedRowIndex].Cells[0].Value);
            var           posts        = vk.getGroupPosts(groupId, countPosts);

            foreach (var post in posts)
            {
                System.Data.DataTable comments = vk.getGroupComents(groupId, (long)post.Id);
                foreach (DataRow row in comments.Rows)
                {
                    commentsList.Add(row.ItemArray[0].ToString());
                    //dataGridViewComments.Rows.Add(row.ItemArray);
                }
            }
            dataGridViewComments.Rows.Clear();
            dataGridViewComments.Columns.Clear();
            dataGridViewComments.Columns.Add(new DataGridViewTextBoxColumn());
            dataGridViewComments.Columns.Add(new DataGridViewTextBoxColumn());
            foreach (string comment in commentsList)
            {
                SentimentAnalysis sentimentAnalysis = new SentimentAnalysis();
                dataGridViewComments.Rows.Add(comment, sentimentAnalysis.getEmotion(comment));
            }
        }
Пример #2
0
 public Form1()
 {
     InitializeComponent();
     //string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
     //MessageBox.Show(path);//
     Import();
     SentimentAnalysis.setVocabulary(columnNames, valueArray);
 }
Пример #3
0
        static void Main(string[] args)
        {
            var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
            var pathFiles  = Directory.EnumerateFiles(projectDir + @"\Samples").ToList();

            SentimentAnalysis.SentimentAnalysis sentimenAnalysis = new SentimentAnalysis.SentimentAnalysis();
            sentimenAnalysis.Load(File.ReadAllLines("AFINN-emoticon-8.txt"));
            sentimenAnalysis.Load(File.ReadAllLines("AFINN-en-165.txt"));
            sentimenAnalysis.Load(File.ReadAllLines("AFINN-fr-165.txt"));

            Dictionary <string, List <double> > scorePerCategory = new Dictionary <string, List <double> >();

            foreach (var path in pathFiles)
            {
                var fileName = Path.GetFileNameWithoutExtension(path);
                var category = fileName.Split('-')[0].Trim();

                var content = File.ReadAllText(path);
                SentimentAnalysis.SentimentAnalysis.Score score = sentimenAnalysis.GetScore(content);

                var averageSentiment = score.AverageSentimentWords;

                if (!scorePerCategory.ContainsKey(category))
                {
                    scorePerCategory.Add(category, new List <double>());
                }
                scorePerCategory[category].Add(averageSentiment);
            }

            var scores = scorePerCategory
                         .Select(m => new KeyValuePair <string, double>(m.Key, m.Value.Average()))
                         .OrderBy(m => m.Value);

            foreach (var category in scores)
            {
                Console.WriteLine(category.Key + ": " + category.Value);
            }
            Console.ReadLine();

            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
        }