示例#1
0
 //Creates an analysis state. A FileHandler method is used to read the analysis lines.
 public AnalysisState(string filePathResults)
 {
     string[] results = File.ReadAllLines(filePathResults);
     nodes = new List <LetterNode>();
     //Reads the header lines.
     uploadedFileName = results[0];
     includeStopwords = bool.Parse(results[1]);
     for (int i = 2; i < results.Length; i++)
     {
         LetterNode node = FileHandler.ReadPostProcessLine(results[i]);
         nodes.Add(node);
     }
 }
示例#2
0
        //This constructor reads a designated source file and constructs a node graph from it.
        public WordFile(string filepath, string stopwordDir, bool includeStopwords)
        {
            stemToPostfixes = GenerateStemToPostfixes();
            string fileText = File.ReadAllText(filepath);

            fileText = SanitizeText(fileText);
            string[] words = fileText.Split(' ');
            for (int i = 0; i < words.Length; i++)
            {
                words[i] = SanitizeWord(words[i], stopwordDir, includeStopwords);
            }
            nodeGraph = new LetterNode();
            foreach (string word in words)
            {
                if (word != "")
                {
                    nodeGraph.AddWord("", word);
                }
            }
        }
示例#3
0
        //A phase of adding a new word. This method is called once per char to make each node or reuse a node where applicable.
        public void AddWord(string writtenWord, string wordRemaining)
        {
            nodeWord = writtenWord;
            //If at the end, the traversal is done.
            if (wordRemaining.Length == 0)
            {
                count++;
                return;
            }
            //Grab the next letter from remaining for node logic.
            char nextLetter = wordRemaining.First();
            //Grab the applicable child. If not found, build the node. In either case, add the word, advanced one letter, through the child.
            LetterNode child = childLetters.FirstOrDefault(i => i.letter == nextLetter);

            if (child == null)
            {
                child = new LetterNode(nextLetter);
                childLetters.Add(child);
            }
            child.AddWord(writtenWord + nextLetter, wordRemaining.Substring(1));
        }
示例#4
0
 //Function for writing the results analysis.
 public void WritePostProcessLine(StreamWriter writer, LetterNode node)
 {
     writer.WriteLine(node.GetNodeWord() + ',' + node.GetCount());
 }