Project briefing illustration for text analysis: a flat tactical intelligence sheet in the style of Star Fox Assault.
ACADEMIC PROJECT / CSCI 1152 - Computer Science Course

Java Word Counter and Phrase Search

I revisited my text-analysis project around its preserved 114-word, 105-unique-word sample, then clarified punctuation, stable sorting, overlapping search markers, and empty-input behavior.

JavaText processingInsertion sortTestingArchive restoration
TRY THE IDEA

Interactive demonstration

A new browser adaptation made in October 2026 using sample data. It illustrates the concepts; it is not the original submitted program.

16 whitespace-separated words · 3 case-insensitive, non-overlapping matches

Build a small system. Test the system with sample data. Document what the system actually does.

This browser example uses a simple token rule. It does not reproduce the original Java project's exact tokenization or sorting implementation.

Why I began with the preserved sample

When I returned to my Java text tool, submitted on July 27, 2023, I wanted its rules to agree with the existing example. I had to make several decisions visible: whether punctuation belongs to a word, whether A and a are distinct, and whether phrase matches can overlap. The project combines those questions with file loading, a hand-written sort, and repeated console searches.

I used the CSCI 1152 semester-project prompt and its sample counts of 114 total words and 105 unique words as a concrete starting point. In October 2026, I reproduced both counts with the assignment’s ArrayList-based approach, treated the sample as a regression fixture, and added checks for punctuation, phrase matching, and empty input.

How I separated source text from counted words

PROJECT STEPS

How I keep counting separate from searching

Project briefing illustration for text analysis: a flat tactical intelligence sheet in the style of Star Fox Assault.
STEP 01 OF 04
Read UTF-8 lines

In my restoration, I read an ordinary UTF-8 text file once, keeping its original lines for phrase searches and building counted words separately. This prevents cleanup for counting from moving the search positions I display. I hold the whole file in memory, and Java’s character positions may not line up visually with tabs or some characters shown by the terminal.

Select a step to follow the project.
Read all step descriptions
  1. Read UTF-8 lines

    In my restoration, I read an ordinary UTF-8 text file once, keeping its original lines for phrase searches and building counted words separately. This prevents cleanup for counting from moving the search positions I display. I hold the whole file in memory, and Java’s character positions may not line up visually with tabs or some characters shown by the terminal.

  2. Build counted words

    For the word statistics, I split text wherever whitespace separates it, remove punctuation, and discard any fragment left empty. This makes blank lines and punctuation-only fragments contribute no words, matching the preserved sample’s counting rule. I treat this as the project’s definition of a word rather than a language-processing method intended for every language.

  3. Apply word-list rules

    I keep differently capitalized words as distinct entries in the ArrayList, Java’s expandable list, while sorting with comparisons that ignore capitalization. I use a stable sort, meaning entries that compare equally keep their original order. I retain the restored insertion sort, which reorders that same list one entry at a time, as part of the exercise; the recorded checks do not establish a performance improvement.

  4. Search original lines

    I search the original lines for exact phrases with matching capitalization, advancing one position after each match so overlapping matches remain visible. I show all starting positions in one marker row without repeating the source line, making the results easier to inspect. I separately reject an empty phrase to prevent a stalled search loop, while preserving repeated searches and the defined ways to leave the console.

Restored text flow: word normalization and literal phrase search follow separate rules.

I accept one path to a regular file and read its UTF-8 lines once. I keep the original lines for literal phrase searches and build a separate word list for statistics. That separation prevents my counting normalization from silently rewriting the text whose search positions I display.

For counting, I split on whitespace, remove punctuation, and discard fragments that become empty. Blank lines and punctuation-only fragments therefore contribute no words. I follow the preserved sample and older recovered work here; this is a project-specific definition of a word. A language-processing library could make different choices about contractions, hyphens, scripts, or sentence boundaries.

I use A a A! as a small explanatory example. After removing punctuation, I get three words but two case-sensitive unique entries. I keep that teaching example separate from the preserved 114/105 fixture.

How I preserved two comparison rules

I preserve two different comparison rules: the unique-word list uses ArrayList's contains behavior, so capitalization matters, while sorting compares case-insensitively. That means two distinct entries can have equal sort keys without contradicting the contract.

I use stable insertion sort in the restoration. For each key, I shift preceding entries only while their case-insensitive comparison is greater than zero, then place the key in the gap. Equal keys stay in encounter order. I modify and return the same list to match the recovered contract.

I kept those structures so the original exercise stays legible, and I state their cost plainly. Repeated linear membership checks can make uniqueness quadratic, and insertion sort has quadratic worst-case work. I recorded no benchmark and make no speed claim. Choosing production-oriented data structures would be a separate redesign.

THE CHALLENGE

The challenge: showing every overlap without stalling

The search challenge was to preserve every literal, case-sensitive match without printing a source line repeatedly. I give each line one marker row with a caret at every matching start, and advance the next search to the previous start plus one rather than skipping the whole phrase.

I use banana with the phrase ana to make the overlap visible: the starts are at indices 1 and 3.

Illustrative text example
banana
 ^ ^

I retain both matches because their overlap is valid. One marker row lets me display the source line once while identifying every occurrence; an absent phrase leaves no marked position.

I also reject an empty phrase before calling substring search. Empty strings can repeatedly match at a line's end and stall a naive loop, so they need their own rule. I let the interactive loop accept repeated searches and end on EINPUT or end-of-file, giving both redirected input and an interactive console a defined exit.

How I checked the behavior in layers

My restoration record reports six unit checks covering uniqueness, sorting, overlapping matches, multiple matches, empty searches, and absent searches. I also used integration checks for blank lines, missing files, repeated searching, and end-of-file. The preserved sample again produces exactly 114 total words and 105 unique words.

I reproduce the checks from small deterministic cases to the command-line interface and then the preserved sample totals. If a count changes, I inspect normalization before changing the expectation. If a marker moves, I inspect the original line and its indices rather than counting normalized tokens.

What I changed and learned

In October, I restored sample-grounded punctuation handling, corrected blank-line counts, made sorting work in place, restored an output heading, combined match markers, and added empty-search and EOF handling. I also replaced fragile recovery around the earlier reader with controlled file reading.

I learned to give each text operation its own clear contract instead of assuming one normalization policy fits everything. The limits remain visible: I hold the entire file in memory, and carets follow Java string positions, which may not align with terminal displays of tabs or some Unicode characters. The result is a verified small text-analysis exercise, not a general-purpose linguistic tokenizer.

PROJECT WALKTHROUGH

I reproduced the 114-word and 105-unique-word sample and checked punctuation, sorting, phrase matches, and empty input. Language-aware tokenization and performance remain outside the verification scope.

Validation & limitations

  • I reproduced the 114-word and 105-unique-word sample and checked punctuation, sorting, phrase matches, and empty input. Language-aware tokenization and performance remain outside the verification scope.

Project records

  • Project artifacts and historical records, July 27, 2023 submission
  • Restoration and public documentation, October 1, 2026
Course descriptions and assignment context
END OF PROJECT FILE RETURN TO ARCHIVE