For this Project 1 Index milestone, your project must be able to calculate and store the word counts of a single file or a directory of text files, as well as output those counts to a JSON file.
TABLE OF CONTENTS
You must complete the following assignments before beginning to work on this one:
You are encouraged to copy/paste homework classes into your project to modify and use when appropriate.
Your main
method must be placed in a class named Driver
and must process the following additional command-line arguments:
-text [path]
where the flag -text
indicates the next argument [path]
is a path to either a single file or a directory.
If the value is a single file (regardless of its extension), open and process that file. If the value is a directory, find and add all of the text files with .txt
and .text
extensions (case-insensitive) in that directory and its subdirectories and process those files.
See the “Text Processing” section below for details on how to process the files and store the calculated word counts.
-counts [path]
where the flag -counts
indicates the next argument [path]
is the path to use to output all of the processed locations and their word counts in a “pretty JSON” format.
If the [path]
argument is not provided, use counts.json
as the default output filename. If the -counts
flag is not provided, your code should still calculate the word counts but should not produce an output file of those counts.
See the “Output Format” section below for details on the “pretty JSON” output format.
The command-line flag/value pairs may be provided in any order or not at all. Do not convert paths to absolute form when processing command-line input!
Output user-friendly error messages in the case of exceptions or invalid input. Under no circumstance should your main()
method output a stack trace to the user!
<aside> <img src="/icons/info-alternate_gray.svg" alt="/icons/info-alternate_gray.svg" width="40px" /> The ArgumentParser homework assignment may be adapted and used to handle command-line input for the project.
</aside>
If the appropriate command-line arguments are provided, process the provided input path as follows:
.text
or .txt
extension (case-insensitive) should be considered a text file.