This Go project reads a .txt file and analyzes the word frequency within it. It displays the total number of words and the top 5 most frequently used words in the file.
- Reads text files line by line
- Cleans and normalizes words (e.g., removes punctuation, lowercases)
- Calculates word frequency using a
map[string]int - Displays:
- Total number of words
- Top 5 most frequent words with their counts
- Go 1.20 or later
projectGolang/
├── main.go
├── file.txt
├── go.mod
├── README.md
├── file/
│ └── reader.go
├── counter/
│ └── counter.go
-
Clone the repository (or place your
.gofiles as shown above).git clone https://github.com/Olzzhass/projectGo.git
-
Initialize Go module (if not already):
go mod init projectGolang
-
Run the program
go run main.go <path-to-your-text-file>
-
Example Output
Total words in file: 372
Top 5 most frequent words:
1. the (28 occurrences)
2. and (17 occurrences)
3. of (15 occurrences)
4. to (14 occurrences)
5. a (13 occurrences)