Table of Contents

👉 Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/text-generation/grammar-spell-correction/text_corrector

Folder Grammar Reviewer with Diff for C# .NET Applications


🎯 Purpose of the Demo

An interactive console app that takes editorial content (single lines, single files, or entire folders) and applies LM-Kit.NET's TextCorrection engine. It produces corrected copies, per-file diffs in fenced-diff Markdown, and a summary CSV ranking files by edit ratio so the worst-edited files get human review first.

All correction runs on-device. No cloud round-trip, no data leaving the host.


👥 Industry Target Audience

  • Editorial / docs teams maintaining a repository of release notes, blog drafts, runbooks.
  • Publishing running pre-print spell/grammar passes.
  • Education flagging student submissions for review.
  • L1/L2 ESL writing tools producing tracked-changes output.

🚀 Problem Solved

A black-box "fix it all" pass is the wrong product. Teams want a tracked-changes artefact set: corrected copies they can compare, a diff to verify what the model touched, and a ranking so the worst-edited files surface first. This demo produces exactly that, with the LM-Kit TextCorrection engine doing the actual correction and a small LCS-based diff turning the result into a reviewable report.


💻 Application Overview

Interactive menu — no command-line arguments — with four modes. Model load happens once at startup; every mode reuses the same in-memory model.

Mode What it does
Live Type or paste a single line, get the correction back inline.
Sample Run 5 built-in error-laden sentences end-to-end.
File Correct one .txt / .md file. Path-prompts for input and output. Optionally shows the diff inline (colour-coded).
Folder Walk a whole folder of .txt / .md files. Writes corrected copies preserving the relative path, plus per-file diffs and a summary report.
Quit Exit.

Folder mode produces this artefact set under the chosen output directory:

  • <rel-path> — corrected copy of each source file, same relative path.
  • diffs/<file>.diff.md — per-file diff in a fenced ```diff ``` block ( /+/- lines).
  • review_report.md — Markdown table of files sorted by edit ratio (worst first).
  • review_summary.csvfile, added, removed, edit_ratio, elapsed_seconds for downstream tooling.

✨ Key Features

  • TextCorrection.Correct: the entire correction is one API call per input. No prompt engineering visible to the developer.
  • Interactive, no flags: every input is a console prompt.
  • LCS line-level diff: produces a deterministic /+/- track-changes view per file.
  • Edit-ratio ranking: the heaviest-edited files float to the top so review time is spent where it matters.
  • Folder-shaped output: corrected copies preserve the original tree, ready to drop into source control.

🧠 Supported Models

The model picker offers:

  • Alibaba Qwen 3.5 9B (~7 GB VRAM) [Recommended]
  • Google Gemma 4 E4B (~6 GB VRAM)
  • Microsoft Phi-4 14.7B (~11 GB VRAM)
  • OpenAI GPT OSS 20B (~16 GB VRAM)
  • Z.ai GLM 4.7 Flash 30B (~18 GB VRAM)
  • Alibaba Qwen 3.6 27B (~18 GB VRAM)
  • Alibaba Qwen 3.6 35B-A3B (~22 GB VRAM)

Or any custom model URI.


🛠️ Getting Started

📋 Prerequisites

  • .NET 8.0 or later
  • Sufficient VRAM for the selected model (3–18 GB)

▶️ Running the Application

git clone https://github.com/LM-Kit/lm-kit-net-samples
cd lm-kit-net-samples/console_net/text-generation/grammar-spell-correction/text_corrector
dotnet run

Pick a model from the prompt, then a mode from the menu.

💡 Example session (folder mode)

╔══════════════════════════════════════════════════╗
║      Folder Grammar Reviewer with Diff           ║
╚══════════════════════════════════════════════════╝

  1 / live     Correct one line at a time
  2 / sample   Run 5 built-in sample sentences
  3 / file     Correct a single .txt / .md file with diff
  4 / folder   Review a folder, produce per-file diffs and a summary
  q / quit     Exit

> 4

Path to a folder containing .txt / .md files: docs/drafts
Output folder for corrected copies and diffs: docs/reviewed

Reviewing 8 file(s) ...

  [1/8] release-notes-v3.md
        +12 -10 ratio=22% 14.3s
  [2/8] onboarding.md
        +3 -3 ratio=8% 11.2s
  ...

Top-edited files (review these first):
  release-notes-v3.md            +12  -10 ratio= 22.0%
  ...

Markdown report : .../review_report.md
Summary CSV     : .../review_summary.csv
Diff folder     : .../diffs
Share