This is a small application to count the frequency of words appearing.
It will:
- Show the occurence of a specified word.
- Show the frequency of the word that occured the most
- Show a list of words based on N value given.
- The words will appear in alphabetical order based on highest to lowest frequency
There are several components to this project
- WordCount Console
- WordCount Library
- WordCount Tests
The console app uses the WordCount.Library
to evaluate the above mentioned frequency of word(s).
To run the console app you need to provide it the following arguments:
-t
or--text
| string: The text that need to be analysed for word frequency. This is meant for a small evaluation set-w
or--word
| string: The specified word the frequency should be calculated for-n
or--nth
| int: The most frequent 'n' words in the text-p
or--path
| string: Path to file with text to be analysed. For large body of text
Note if you provide both t
and p
, the application will concat them and evaluate it in it's entirety.
Running the app can happen in two ways:
-
When you have it open in visual studio,
- right click on the app
WordCount
: - Make it the startup project
- Go to properties > debug
- In the
Command Line Arguments
set the following
-w <word to evaluate> -t <text to evaluate> -n <n> -p <path to text file>
- Press F5
- right click on the app
-
When running from a
command line prompt
- Navigate to where
WordCount.exe
lives (after release build) - Run
WordCount.exe -w <word to evaluate> -t <text to evaluate> -n <n> -p <path to text file>
- Navigate to where
-
If no
commandline arguments
are given, the app will default back to basic readline commands for manual input, with instructions for optimal running. In this mode the following will display:Please provide the text you want analysed:
=> provide your text you want analysedPlease enter the word you want the frequency of:
=> enter what word you want the frequency forPlease enter the 'n' number:
=> enter anint
value forn
. if you provide anything else, it will first try to parse the value and if fail default to zero. Nothing will then be displayed.Please enter path to text file (if any exist):
=> if you have a large text file, enter the path of file e.g.C:\FileName.txt
Note in this project a large txt file is included named IpsumLargeString.txt
.
The output should look something like this:
A library used by Console app and tests, holding the implementation of:
- CalculateFrequencyForWord
- CalculateHighestFrequency
- CalculateMostFrequentNWords
To use this library in another project, you can build the .dll via release build and implement in another project. Can use the Console app as a guide.
The WordCount.Tests
is a small application that tests the implementation of the WordCount.Library
. It uses XUnit
as a testing framework.
It tests the following:
- Most_Frequent_N_Returns_List_Of_N_Words_With_Frequency
- Highest_Frequency_Of_Word_Return_Count_Of_Highest_Occurence_Of_Word
- Frequency_Of_Word_Return_Occurence_Of_Specified_Word
- CalculateMostFrequentNWords_Text_Empty_Throws_ArgumentException
- CalculateMostFrequentNWords_Text_Null_Throws_ArgumentNullException
- CalculateHighestFrequency_Text_Empty_Throws_ArgumentException
- CalculateHighestFrequency_Text_Null_Throws_ArgumentNullException
- CalculateFrequencyForWord_Word_Empty_Throws_ArgumentException
- CalculateFrequencyForWord_Word_Null_Throws_ArgumentNullException
- CalculateFrequencyForWord_Text_Empty_Throws_ArgumentException
- CalculateFrequencyForWord_Text_Null_Throws_ArgumentNullException
- Most_Frequent_N_Returns_List_Of_N_Words_Numeric_Values_Excluded
- Most_Frequent_N_Returns_List_Of_N_Words_Guid_Values_Excluded
- Most_Frequent_N_Returns_List_Of_N_Words_NumerWords_Values_Excluded
- Most_Frequent_N_Returns_List_Of_N_Words_SpecialChar_Values_Excluded
- Frequency_Of_Word_Word_Has_Leading_Trailing_Whitespace_Return_Occurence_Of_Specified_Word
XUnit
v2.4.1 => Unit testing frameworkxunit.runner.visualstudio
v2.4.2 => To run and discover unit testsCommandLineParser
v2.8.0 => to pass command line options easily