go-reloaded is a Go-based text processing tool that reads text files, applies a series of text transformations, and writes the processed output to a new file. It’s designed to be modular, so different text processing operations (capitalization, punctuation, quotes, number conversions, etc.) can be added or modified easily.
Capitalization Commands: Supports (cap), (low), (up) and multi-word commands (cap, n), (low, n).
Number Conversions: Converts (hex) and (bin) numbers to decimal automatically.
Indefinite Articles: Fixes a/an based on following words (handles vowel sounds and silent 'h').
Punctuation: Cleans up extra spaces before punctuation marks (.,:;!?) and preserves ellipsis ....
Quotes: Fixes spacing inside single quotes '...'.
Tokenization: Processes text word by word to apply transformations.
Installation
Clone the repository:
git clone https://learn.zone01kisumu.ke/git/danikeya/go-reloaded.git cd go-reloaded
Make sure Go is installed (tested with Go 1.20+).
Usage go run main.go <input_file> <output_file>
Example:
$ cat input.txt it (cap) was the best of times, it was the worst of times (up) , it was the age of wisdom, it was the age of foolishness (cap, 6) , IT WAS THE (low, 3) winter of despair.
$ go run main.go input.txt output.txt $ cat output.txt It was the best of times, it was the worst of TIMES, it was the age of wisdom, It Was The Age Of Foolishness, it was the winter of despair.
Directory Structure
.
├── command.txt # Example command input file
├── convert # Number and string conversion functions
│ ├── bintodec.go
│ ├── capitalize.go
│ ├── hextodec.go
│ ├── tolower.go
│ └── toupper.go
├── fileprocessor # Main file processing logic
│ └── fileprocessor.go
├── go.mod
├── input.txt # Example input file
├── main.go # Program entry point
├── output.txt # Example output file
├── README.md
├── testing # Unit tests for conversions
│ └── convertest.go
└── utils # Text processing utilities
├── applycommand.go
├── fixinfinitearticles.go
├── fixpunctuations.go
├── fixquotes.go
├── parsecommandwithpunc.go
├── processtext.go
└── tokenize.go
Modules Overview
utils/ – Core text processing functions
fixpunctuations.go – Fixes spacing around punctuation
fixquotes.go – Cleans spacing inside quotes
fixinfinitearticles.go – Fixes a/an based on next word
parsecommandwithpunc.go – Extracts commands like (cap, 6)
applycommand.go – Applies capitalization or case transformations
processtext.go – Applies all transformations to a line of text
tokenize.go – Splits text into words for processing
convert/ – Conversion utilities
bintodec.go – Converts binary numbers to decimal
hextodec.go – Converts hexadecimal numbers to decimal
capitalize.go – Capitalizes first letter of a word
tolower.go – Lowercases first letter
toupper.go – Uppercases first letter
fileprocessor/ – Reads input files, applies processing, writes output
testing/ – Contains unit tests for conversion functions
Contributing
Fork the repository
Add new text transformations or fix bugs
Test thoroughly using input.txt and check output.txt
Submit a pull request
License
MIT License
### Testing Examples
Here are some sample inputs and expected outputs to verify the program works correctly:
Example 1: Capitalization and Case Commands
Input (sample1.txt):
it (cap) was the best of times, it was the worst of times (up) , it was the age of wisdom, it was the age of foolishness (cap, 6) , IT WAS THE (low, 3) winter of despair.
Command Run:
go run main.go sample1.txt result1.txt
Expected Output (result1.txt):
It was the best of times, it was the worst of TIMES, it was the age of wisdom, It Was The Age Of Foolishness, it was the winter of despair.
Example 2: Hexadecimal and Binary Number Conversion
Input (sample2.txt):
Simply add 42 (hex) and 10 (bin) and you will see the result is 68.
Command Run:
```bash
go run main.go sample2.txt result2.txt
Expected Output (result2.txt):
Simply add 66 and 2 and you will see the result is 68.
Example 3: Indefinite Articles and Quotes
Input (sample3.txt):
the wizard said:' prepare yourselves ! ' , and a (an) hour later, the battle began.
Command Run:
```bash
go run main.go sample3.txt result3.txt
Expected Output (result3.txt):
The wizard said: 'Prepare yourselves!', and an hour later, the battle began.
Example 4: Punctuation Fixes
Input (sample4.txt):
punctuation tests are ... kinda boring ,what do you think ?
Command Run:
```bash
go run main.go sample4.txt result4.txt
Expected Output (result4.txt):
Punctuation tests are... kinda boring, what do you think?
Example 5: Mega Test Input
Input (mega_test_input.txt):
it (cap) was the dawn of a new era, where every hero faced challenges (up) , and every villain plotted in secret. the kingdom had 31 (hex) soldiers and 110 (bin) spies waiting. the wizard whispered: ' prepare yourselves ! ' , and a (an) hour later, the battle began. it was the age of courage, and the age of fear (cap, 7) , yet the light of hope shone through darkness (low, 5) .
simply multiply 12 (hex) by 5 (bin) and you will see the result is 60.
there is no greater agony than keeping a secret untold inside your heart.
punctuation practice is ... essential , do you agree ?
quotes can be tricky too: ' remember to check every word ! ' and ' never skip punctuation ? '
Command Run:
```bash
go run main.go mega_test_input.txt mega_test_output.txt
Expected Output (mega_test_output.txt):
It was the dawn of a new era, where every HERO faced challenges, and every villain plotted in secret. The kingdom had 49 soldiers and 6 spies waiting. The wizard whispered: 'Prepare yourselves!', and an hour later, the battle began. It Was The Age Of Courage, And The Age Of Fear, yet the light of hope shone through darkness.
Simply multiply 18 by 1 and you will see the result is 60.
There is no greater agony than keeping a secret untold inside your heart.
Punctuation practice is... essential, do you agree?
Quotes can be tricky too: 'Remember to check every word!' and 'Never skip punctuation?'