Esempio n. 1
0
        public TagCloudNode GetCommentTreeString(children children)
        {
            Dictionary <string, int> topNWordsRoot = children.GetTopNWordsDictionary(10);
            TagCloudNode             tgnRoot       = new TagCloudNode();

            tgnRoot.id   = children.id;
            tgnRoot.key  = children.key;
            tgnRoot.text = children.text;
            bool   isOP     = author == children.author;
            string citePre  = isOP ? "<cite class='op'>" : "<cite>";
            string citePost = ":</cite>";

            tgnRoot.title = citePre + children.author + citePost + children.text;
            GetTagCloudFromDictionary(topNWordsRoot);
            tgnRoot.children  = new List <TagCloudNode>();
            children.Children = children.Children.OrderByDescending(x => x.created_at).ToList();
            foreach (children child in children.Children)
            {
                if (!string.IsNullOrWhiteSpace(child.SubtreeText))
                {
                    TagCloudNode tgnChild = GetCommentTreeString(child);
                    tgnRoot.children.Add(tgnChild);
                }
            }
            return(tgnRoot);
        }
Esempio n. 2
0
 void GetCommentDictionary(children childlist, ref Dictionary <int, string> dict)
 {
     foreach (children child in childlist.Children)
     {
         dict[child.id] = child.text;
         GetCommentDictionary(child, ref dict);
     }
 }
Esempio n. 3
0
 private void GetChildIDHashSetList(children node)
 {
     node.ChildIDList = GetChildIDList(node);
     foreach (children child in node.Children)
     {
         GetChildIDHashSetList(child);
     }
 }
Esempio n. 4
0
 private void PopulateNodeList(children child)
 {
     NodeList.Add(child);
     foreach (children childnode in child.Children)
     {
         PopulateNodeList(childnode);
     }
 }
Esempio n. 5
0
        private string GetSubtree(children node)
        {
            string subtreeText = WebUtility.HtmlDecode(node.text);

            foreach (children child in node.Children)
            {
                subtreeText += " " + WebUtility.HtmlDecode(GetSubtree(child));
            }
            return(subtreeText);
        }
Esempio n. 6
0
        public int GetChildCount(children childrenlist)
        {
            int counter = string.IsNullOrWhiteSpace(childrenlist.text)?0:1;

            foreach (children child in childrenlist.Children)
            {
                counter += GetChildCount(child);
            }
            return(counter);
        }
Esempio n. 7
0
        public List <string> GetAnchorWords(children root, int N)
        {
            List <string> anchorWords = new List <string>();

            string[] allWords = GetAllWords(root.SubtreeText);
            Dictionary <string, string> stemParentDictionary = GetStemParentDictionary(allWords);
            children rootNode = new children();
            List <HashSet <int> > rootChildIDs = new List <HashSet <int> >();

            foreach (children child in root.Children)
            {
                GetChildIDHashSetList(child);
                HashSet <int> currChildIDs = new HashSet <int>();
                currChildIDs.Add(child.id);
                foreach (var item in child.ChildIDList)
                {
                    currChildIDs.UnionWith(item);
                }
                rootChildIDs.Add(currChildIDs);
            }
            rootNode.ChildIDList = rootChildIDs;
            NodeList             = new List <children>();
            NodeList.Add(rootNode);
            foreach (children child in root.Children)
            {
                PopulateNodeList(child);
            }
            Dictionary <string, HashSet <int> > wordIDMapping = GetWordIDMapping();
            //Dictionary<string, double> WordTreeScore = new Dictionary<string, double>();
            Dictionary <string, List <children> > WordLCAList = new Dictionary <string, List <children> >();

            foreach (var kvp in wordIDMapping)
            {
                List <children> currLCAList = new List <children>();
                int             numLCAs     = 0;
                foreach (children node in NodeList)
                {
                    int numBranchesWithWord = 0;
                    foreach (var childIDBranch in node.ChildIDList)
                    {
                        if (childIDBranch.Intersect(kvp.Value).Count() > 0)
                        {
                            numBranchesWithWord += 1;
                        }
                    }
                    if ((numBranchesWithWord == 1 && node.ChildIDList.Count == 1) || numBranchesWithWord > 1)
                    {
                        currLCAList.Add(node);
                    }
                }
                WordLCAList[stemParentDictionary.ContainsKey(kvp.Key) ? stemParentDictionary[kvp.Key] : kvp.Key] = currLCAList;
            }
            anchorWords = WordLCAList.OrderByDescending(x => x.Value.Count).Select(x => x.Key).Where(y => CommonWords.GetFrequency(y) < 20).Take(N).ToList();
            return(anchorWords);
        }
Esempio n. 8
0
        private List <HashSet <int> > GetChildIDList(children node)
        {
            List <HashSet <int> > myChildren = new List <HashSet <int> >();

            foreach (children child in node.Children)
            {
                HashSet <int> idList = GetChildIDs(child);
                myChildren.Add(idList);
            }
            return(myChildren);
        }
Esempio n. 9
0
        public async Task <object> GetCommentTreeForId(string idTuple)
        {
            string       sStoryId = idTuple.Split(':')[1];
            string       sNodeId  = idTuple.Split(':')[0];
            int          storyid  = Convert.ToInt32(sStoryId);
            int          nodeid   = Convert.ToInt32(sNodeId);
            FullStory    fs       = FullStoryFactory.GetFullStory(storyid);
            children     child    = fs.GetNodeById(nodeid);
            TagCloudNode tgn      = fs.GetCommentTreeString(child);

            return(JsonConvert.SerializeObject(tgn));
        }
Esempio n. 10
0
        private HashSet <int> GetChildIDs(children childnode)
        {
            HashSet <int> childIDs = new HashSet <int>();

            childIDs.Add(childnode.id);
            foreach (children child in childnode.Children)
            {
                childIDs.Add(child.id);
                childIDs.UnionWith(GetChildIDs(child));
            }
            return(childIDs);
        }
Esempio n. 11
0
 void LoadUserComments(children child)
 {
     if (!string.IsNullOrWhiteSpace(child.author))
     {
         if (!UserComments.ContainsKey(child.author))
         {
             UserComments[child.author] = new List <CommentObj>();
         }
         UserComments[child.author].Add(new CommentObj()
         {
             Id = child.id, Text = child.text
         });
     }
     foreach (children childNode in child.Children)
     {
         LoadUserComments(childNode);
     }
 }
Esempio n. 12
0
        Dictionary <string, HashSet <int> > GetWordIDMapping(children child)
        {
            Dictionary <string, HashSet <int> > wordIDMapping = new Dictionary <string, HashSet <int> >();

            string[] allWords = GetAllWords(child.text);

            foreach (string word in allWords)
            {
                if (stopWords.Contains(word.ToLower()))
                {
                    continue;
                }
                if (word.Length < 3 && word.Any(c => char.IsLower(c)))
                {
                    continue;
                }
                string stem = Stemmer.GetStem(word);
                if (!wordIDMapping.ContainsKey(stem))
                {
                    wordIDMapping[stem] = new HashSet <int>();
                }
                wordIDMapping[stem].Add(child.id);
            }
            foreach (children childitem in child.Children)
            {
                Dictionary <string, HashSet <int> > mapping = GetWordIDMapping(childitem);
                foreach (var kvp in mapping)
                {
                    if (wordIDMapping.ContainsKey(kvp.Key))
                    {
                        wordIDMapping[kvp.Key].UnionWith(kvp.Value);
                    }
                    else
                    {
                        wordIDMapping[kvp.Key] = kvp.Value;
                    }
                }
            }
            return(wordIDMapping);
        }
Esempio n. 13
0
        public TagCloudNode GetTagCloudTreeString(children children)
        {
            Dictionary <string, int> topNWordsRoot = children.GetTopNWordsDictionary(10);
            string       topNWords = GetTagCloudFromDictionary(topNWordsRoot);
            TagCloudNode tgnRoot   = new TagCloudNode();

            tgnRoot.id    = children.id;
            tgnRoot.key   = children.key;
            tgnRoot.text  = topNWords;
            tgnRoot.title = topNWords;

            tgnRoot.children  = new List <TagCloudNode>();
            children.Children = children.Children.OrderByDescending(x => x.created_at).ToList();
            foreach (children child in children.Children)
            {
                if (!string.IsNullOrWhiteSpace(child.SubtreeText))
                {
                    TagCloudNode tgnChild = GetTagCloudTreeString(child);
                    tgnRoot.children.Add(tgnChild);
                }
            }
            return(tgnRoot);
        }
Esempio n. 14
0
        public Dictionary <string, List <CommentObj> > GetNamedObjects(int N)
        {
            StringBuilder sbAllWords = new StringBuilder();

            foreach (children child in children)
            {
                sbAllWords.Append(child.SubtreeText);
                sbAllWords.Append(" ");
            }
            string[] allWords = GetAllWords(sbAllWords.ToString());
            Dictionary <string, string> stemParentDictionary = GetStemParentDictionary(allWords);
            List <string>         namedObjects = new List <string>();
            children              rootNode     = new children();
            List <HashSet <int> > rootChildIDs = new List <HashSet <int> >();

            foreach (children child in children)
            {
                GetChildIDHashSetList(child);
                HashSet <int> currChildIDs = new HashSet <int>();
                currChildIDs.Add(child.id);
                foreach (var item in child.ChildIDList)
                {
                    currChildIDs.UnionWith(item);
                }
                rootChildIDs.Add(currChildIDs);
            }
            rootNode.ChildIDList = rootChildIDs;
            NodeList             = new List <children>();
            NodeList.Add(rootNode);
            foreach (children child in children)
            {
                PopulateNodeList(child);
            }
            Dictionary <string, HashSet <int> > wordIDMapping = GetWordIDMapping();
            //Dictionary<string, double> WordTreeScore = new Dictionary<string, double>();
            Dictionary <string, List <children> > WordLCAList = new Dictionary <string, List <children> >();

            foreach (var kvp in wordIDMapping)
            {
                List <children> currLCAList = new List <children>();
                int             numLCAs     = 0;
                foreach (children node in NodeList)
                {
                    int numBranchesWithWord = 0;
                    foreach (var childIDBranch in node.ChildIDList)
                    {
                        if (childIDBranch.Intersect(kvp.Value).Count() > 0)
                        {
                            numBranchesWithWord += 1;
                        }
                    }
                    if ((numBranchesWithWord == 1 && node.ChildIDList.Count == 1) || numBranchesWithWord > 1)
                    {
                        currLCAList.Add(node);
                    }
                }
                WordLCAList[stemParentDictionary.ContainsKey(kvp.Key) ? stemParentDictionary[kvp.Key] : kvp.Key] = currLCAList;
            }
            namedObjects = WordLCAList
                           .OrderByDescending(x => x.Value.Count)
                           .Select(x => x.Key)
                           .Where(y => CommonWords.GetFrequency(y) < 1)
                           .Where(a => char.IsUpper(a[0]))
                           .Where(b => b.Length > 1)
                           .Where(z => !(z.EndsWith("n't") || z.EndsWith("'m") || (z.EndsWith("'ll")) || (z.EndsWith("'d")) || z.EndsWith("'ve") || z.EndsWith("'re") || z.EndsWith("'s")))
                           .Take(N)
                           .ToList();
            //namedObjects.Sort();
            Dictionary <string, List <CommentObj> > namedObjectDictionary = new Dictionary <string, List <CommentObj> >();

            foreach (string namedObject in namedObjects)
            {
                List <CommentObj> commentObjsForWord = new List <CommentObj>();
                string            stem        = Stemmer.GetStem(namedObject);
                HashSet <int>     idsWithWord = wordIDMapping[stem];
                foreach (int id in idsWithWord)
                {
                    children   child      = GetNodeById(id);
                    CommentObj commentObj = new CommentObj()
                    {
                        Id = id, Text = child.text
                    };
                    commentObjsForWord.Add(commentObj);
                }
                namedObjectDictionary[namedObject] = commentObjsForWord;
            }
            var ordered = namedObjectDictionary.Keys.OrderByDescending(x => namedObjectDictionary[x].Count).ToList().ToDictionary(x => x, x => namedObjectDictionary[x]);

            return(ordered);
        }