private static void AddDataStructureWordsToNode(ref KnowledgeGraph graph, WordCountByNodeIndex wordsToAddToNode, Dictionary <string, KnowledgeGraphNode> dataStructureNodes)
        {
            List <string> words         = GetWords(wordsToAddToNode);
            List <string> filteredWords = GetFilteredWords(words, DataStructureWordsToIgnore);

            foreach (var word in filteredWords)
            {
                AddEdgeToKnowledgeGraph(graph: ref graph, nodeIndex: wordsToAddToNode.Index, nodeToAdd: dataStructureNodes[word]);
            }
        }
        public static List <WordCountByNodeIndex> GetDataStructureWordCountsFromGraph(KnowledgeGraph knowledgeGraph)
        {
            // compute the list of DS words
            List <string> dataStructureWords   = Utilities.GetDataStructureWordsFromGraph(knowledgeGraph);
            List <WordCountByNodeIndex> result = new List <WordCountByNodeIndex>();

            // foreach node in the graph which has a link to page and downloaded file for that link, get the ds word count
            knowledgeGraph.KnGraph
            .Where(node => node.OriginalGraphType == OriginalGraphType.AlgorithmsKnGraph && node.LinkToPage != null && File.Exists(Utilities.GetFilePathFromNodeLinkTopage(node.LinkToPage))).ToList()
            .ForEach(node =>
            {
                // make empty ds words dictionary for this node
                Dictionary <string, int> dsWordsCountDictForOneNode = new Dictionary <string, int>();
                dataStructureWords.ForEach(dsWord =>
                {
                    dsWordsCountDictForOneNode.Add(dsWord, 0);
                });

                // get file content and count the ds words in it
                string fileContent        = File.ReadAllText(Utilities.GetFilePathFromNodeLinkTopage(node.LinkToPage));
                string[] fileContentWords = fileContent.Split(' ');
                foreach (string word in fileContentWords)
                {
                    if (dsWordsCountDictForOneNode.ContainsKey(word))
                    {
                        dsWordsCountDictForOneNode[word]++;
                    }
                }

                // remove words with 0 count from words count dictionary
                dsWordsCountDictForOneNode = dsWordsCountDictForOneNode.Where(x => x.Value > 0).ToDictionary(y => y.Key, y => y.Value);

                // only add it to the list if there is at least one ds word
                if (dsWordsCountDictForOneNode.Any())
                {
                    WordCountByNodeIndex wordCountForNode = new WordCountByNodeIndex()
                    {
                        Index      = node.Index,
                        WordsCount = new Dictionary <string, int>(dsWordsCountDictForOneNode)
                    };

                    result.Add(wordCountForNode);
                }
            });

            return(result);
        }
 private static List <string> GetWords(WordCountByNodeIndex wordCount)
 {
     return(wordCount.WordsCount.Keys.Select(word => word.ToLowerInvariant()).ToList());
 }