Beispiel #1
0
 public void AddSibling(HashTag hashTag)
 {
     if (!_siblings.Contains(hashTag))
     {
         _siblings.Add(hashTag);
         hashTag._siblings.Add(this);
     }
 }
Beispiel #2
0
        public Edge(HashTag left, HashTag right)
        {
            this._left = left;
            this._right = right;

            this._left.AddSibling(right);

            left.LastParentEdge = this;
            right.LastParentEdge = this;

            GenerateId();
        }
        public void OnEdgeConstruction_HashTagsShouldBeMadeSiblings()
        {
            HashTag h1 = new HashTag();
            HashTag h2 = new HashTag();

            Edge e = new Edge(h1, h2);

            int expectedSiblingsCount = 1;

            Assert.AreEqual<int>(expectedSiblingsCount, h1.Siblings.Length);
            Assert.AreEqual<int>(expectedSiblingsCount, h2.Siblings.Length);
            Assert.AreSame(h2, h1.Siblings[0]);
            Assert.AreSame(h1, h2.Siblings[0]);
        }
        public void AddSibling()
        {
            HashTag h1 = new HashTag()
            {
                Name = "h1"
            };

            HashTag h2 = new HashTag()
            {
                Name = "h2"
            };

            h1.AddSibling(h2);

            int expectedSiblingsCount = 1;

            Assert.AreEqual<int>(expectedSiblingsCount, h1.Siblings.Length);
        }
        public void RemoveSiblingFromOneHashTag_MustRemoveBothFromEachOthersSiblingsList()
        {
            HashTag h1 = new HashTag()
            {
                Name = "h1"
            };

            HashTag h2 = new HashTag()
            {
                Name = "h2"
            };

            h1.AddSibling(h2);
            h1.RemoveSibling(h2);

            int expectedSiblingsCount = 0;

            Assert.AreEqual<int>(expectedSiblingsCount, h2.Siblings.Length);
        }
        public void AddSiblingToOneHashTag_MustMakeBothEachOthersSiblings()
        {
            HashTag h1 = new HashTag()
            {
                Name = "h1"
            };

            HashTag h2 = new HashTag()
            {
                Name = "h2"
            };

            h1.AddSibling(h2);

            int expectedSiblingsCountDifference = 0;
            int actualSiblingsCountDifference = h1.Siblings.Length - h2.Siblings.Length;

            Assert.AreEqual<int>(expectedSiblingsCountDifference, actualSiblingsCountDifference);
            Assert.AreSame(h2, h1.Siblings[0]);
            Assert.AreSame(h1, h2.Siblings[0]);
        }
Beispiel #7
0
 public void RemoveSibling(HashTag hashTag)
 {
     _siblings.Remove(hashTag);
     hashTag._siblings.Remove(this);
 }
Beispiel #8
0
        /// <summary>
        /// Process hashtags and their relational graph in a tweet
        /// </summary>
        /// <param name="tweet">Tweet to be processed</param>
        /// <param name="tweetText">The cleaned-up ASCII string of the tweet.</param>
        private static void ProcessHashtagData(Tweet tweet, string tweetText)
        {
            //Extract hashtags from tweet text
            var hashtags = Regex.Matches(tweetText, @"(\b|\s)?#\w+");

            foreach (Match tag in hashtags)
            {
                HashTag hashTag = null;
                string strHashtagName = tag.Value.Trim().ToLower();

                if (!_dicHashtagNameMappings.TryGetValue(strHashtagName, out hashTag))
                {
                    hashTag = new HashTag()
                    {
                        Name = strHashtagName
                    };

                    _dicHashtagNameMappings.Add(strHashtagName, hashTag);
                }

                foreach (var t in tweet.HashTags)
                {
                    if (t != hashTag)
                    {
                        Edge newEdge = new Edge(t, hashTag);
                        tweet.AddEdge(newEdge);

                        Edge edExisting = null;

                        if (_dicEdgeIdMappings.TryGetValue(newEdge.Id, out edExisting))
                            _dicEdgeIdMappings[newEdge.Id] = newEdge;
                        else
                            _dicEdgeIdMappings.Add(newEdge.Id, newEdge);
                    }
                }

                tweet.HashTags.Add(hashTag);
            }
        }