private void AnalyseCommunity(Community community)
        {
            List<User> users = community.Users;
            foreach (var user in users)
            {
                double scorePos = 0;
                double scoreNeg = 0;
                int scoreCount = 0;
                if (System.String.CompareOrdinal(user.FullReview, "* *") == 0)
                {
                    List<string> friends = user.Friends;
                    foreach (var friendName in friends)
                    {
                        User friend = FindUser(community, friendName);
                        string review = friend.FullReview;
                        if (System.String.CompareOrdinal(review, "* *") == 0) // Ensure that the friend has written a review
                            continue;

                        double pos = _sentimentClassifier.ScoreLog(review, Label.Pos);
                        double neg = _sentimentClassifier.ScoreLog(review, Label.Neg);

                        if (double.IsInfinity(neg))
                            neg = 0;
                        if (double.IsInfinity(pos))
                            pos = 0;

                        if (friend.CommunityId != user.CommunityId || System.String.CompareOrdinal(friend.Name, "kyle") == 0)
                        {
                            pos *= 10;
                            neg *= 10;
                            scoreCount += 10;
                        }
                        else
                        {
                            scoreCount++;   
                        }
                        scorePos += pos;
                        scoreNeg += neg;
                    }
                    Label score = DetermineScore(scorePos/scoreCount, scoreNeg/scoreCount);
                    WriteDecision(user, score);
                }
                else
                {
                    scorePos = _sentimentClassifier.ScoreLog(user.FullReview, Label.Pos);
                    scoreNeg = _sentimentClassifier.ScoreLog(user.FullReview, Label.Neg);

                    if (double.IsInfinity(scoreNeg))
                        scoreNeg = 0;
                    if (double.IsInfinity(scorePos))
                        scorePos = 0;
                    Label score = DetermineScore(scorePos, scoreNeg);
                    WriteScore(user, score);
                }
            }
        }
Example #2
0
 static void PrintCommunity(Community community)
 {
     Console.WriteLine("Users:");
     foreach (var user in community.Users)
     {
         Console.WriteLine(user.ToString());
     }
     Matrix<double> matrix = community.AdjacencyMatrix;
     Console.WriteLine("\nAdjacency Matrix:");
     for (int i = 0; i < matrix.RowCount; i++)
     {
         string line = string.Join("\t", matrix.Row(i));
         Console.WriteLine(line);
     }
 }
 public FriendListParser(string filePath)
 {
     _filePath = filePath;
     _community = new Community();
 }
        private User FindUser(Community startCommunity, string name)
        {
            User user = startCommunity.GetUser(name);
            if (user == null)
            {
                foreach (var community in _communities)
                {
                    if (community.Id.Equals(startCommunity.Id))
                        continue;

                    user = community.GetUser(name);
                    if (user != null)
                        break;
                }
            }
            return user;
        }
        public List<Community> Identify(double lastDiff = double.MinValue)
        {
            List<Community> communities = new List<Community>();
            if (_rootCommunity.Users.Count < 2)
                return communities;

            Console.WriteLine("Root community size: {0}", _rootCommunity.Users.Count);

            _eigenvector = CalculateEigenvector();
            //Console.WriteLine("Eigenvector:\n\t" + string.Join("\n\t", _eigenvector));

            double largestDiff = lastDiff;
            int nodeIndexBeforeDiff = -1;
            for (int i = 1; i < _eigenvector.Count; i++)
            {
                double diff = Math.Abs(_eigenvector[i].Value - _eigenvector[i - 1].Value);
                if (diff > largestDiff)
                {
                    nodeIndexBeforeDiff = i;
                    largestDiff = diff;
                }
            }

            Console.WriteLine("Largest diff: " + largestDiff);

            if (nodeIndexBeforeDiff > -1) // We did discover subcommunities
            {
                Community community1 = new Community();
                for (int i = 0; i < nodeIndexBeforeDiff; i++)
                {
                    User user = _rootCommunity.Users[_eigenvector[i].Key];
                    community1.AddUser(user);
                }
                Community community2 = new Community();
                for (int i = nodeIndexBeforeDiff; i < _eigenvector.Count; i++)
                {
                    User user = _rootCommunity.Users[_eigenvector[i].Key];
                    community2.AddUser(user);
                }

                Console.WriteLine("Community1: " + community1.Size);
                Console.WriteLine("Community2: " + community2.Size);
                Console.WriteLine();

                if (community1.Size > 1 && community2.Size > 1)
                {
                    lastDiff = largestDiff*0.6;
                    CommunityIdentifier identifier1 = new CommunityIdentifier(community1);
                    List<Community> communities1 = identifier1.Identify(lastDiff);
                    if (communities1.Count > 0)
                        communities.AddRange(communities1);
                    else
                        communities.Add(community1);

                    CommunityIdentifier identifier2 = new CommunityIdentifier(community2);
                    List<Community> communities2 = identifier2.Identify(lastDiff);
                    if (communities2.Count > 0)
                        communities.AddRange(communities2);
                    else
                        communities.Add(community2);
                }
            }
            Console.WriteLine("Communities: {0}\n", communities.Count);
            return communities;
        }
 public CommunityIdentifier(Community community)
 {
     _rootCommunity = community;
 }
 public void Dispose()
 {
     _eigenvector = null;
     _rootCommunity = null;
 }