A text analyzer
The problem
Build a program that reads a text from the input and reports statistics: the number of lines, words and characters, the most common words, the longest word and how often each letter appears.
Requirements
- Read all lines with bufio.Scanner and split them into words
- Count words and letters with maps and print them in a fixed order
- Handle upper and lower case and punctuation
- Use runes so that accented letters count as one character
Technologies
- Go
- Maps
- Strings and runes
- Sorting
- bufio
Step by step
- Read the lines and count lines, words and characters.
- Clean each word: lower case and no punctuation at the ends.
- Count the words and letters with maps.
- Sort the results by count and then by name, and print the report.
Expected result
A report that is the same on every run and correct for texts with punctuation and accents.
How it is evaluated
- Counts match a hand count on a small text
- Ties are broken in a fixed, documented way
- Accented letters are counted as single characters
- The code is split into small functions
Ways to improve it
- Add a command to ignore common words such as the and a
- Print a simple bar of stars for each of the top words
- Count sentences and the average word length