Rust_Grammar 2.2.0

A comprehensive, production-ready text analysis library and REST API server. Features 19+ professional writing analysis tools including grammar checking, readability metrics, passive voice detection, style scoring, and more. Provides both CLI and REST API interfaces with 6 specialized endpoints.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
# Rust_Grammar

## Complete Professional Text Analysis Library & API

[![Crates.io](https://img.shields.io/crates/v/Rust_Grammar.svg)](https://crates.io/crates/Rust_Grammar)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust](https://img.shields.io/badge/rust-1.75%2B-blue.svg)](https://www.rust-lang.org)

**Rust_Grammar** is a production-grade, comprehensive text analysis library written in Rust that provides detailed analysis of grammar, readability, style, and 19+ professional writing metrics. Built for maximum performance, reliability, and accuracy with zero-crash guarantees.

---

## Table of Contents

1. [Overview]#overview
2. [Features]#features
3. [Architecture]#architecture
4. [Installation]#installation
5. [Configuration]#configuration
6. [Usage]#usage
7. [REST API Reference]#rest-api-reference
8. [Code Examples]#code-examples
9. [Data Models]#data-models
10. [Error Handling]#error-handling
11. [Testing]#testing
12. [Deployment]#deployment
13. [Contributing]#contributing
14. [Changelog & Roadmap]#changelog--roadmap
15. [FAQ]#faq
16. [License & Credits]#license--credits

---

## Overview

### Project Description

Rust_Grammar is a comprehensive text analysis toolkit designed for writers, editors, developers, and content creators who need detailed insights into their writing. Whether you're analyzing academic papers, fiction manuscripts, business documents, or technical documentation, Rust_Grammar provides actionable feedback on grammar, style, readability, and writing quality.

### Key Value Propositions

| Value | Description |
|-------|-------------|
| **Performance** | Written in Rust for blazing-fast analysis (~500ms per 1000 words) |
| **Accuracy** | 95%+ sentence splitting, 85%+ passive voice detection, 90%+ syllable counting |
| **Reliability** | Zero crashes with comprehensive error handling using `Result<T, E>` |
| **Completeness** | 19+ professional analysis features in a single library |
| **Flexibility** | CLI, Library, and REST API interfaces |
| **Extensibility** | Modular architecture with configurable presets |

### Target Audience

- **Writers & Authors**: Improve prose quality and readability
- **Editors**: Automated first-pass analysis
- **Developers**: Integrate text analysis into applications
- **Educators**: Teaching writing improvement
- **Content Teams**: Maintain consistent writing standards

---

## Features

### Complete Feature List (19+ Professional Features)

<details open>
<summary><strong>📝 Grammar Analysis</strong></summary>

| Feature | Description |
|---------|-------------|
| Subject-Verb Agreement | Detects mismatched subjects and verbs (e.g., "He are going") |
| Double Negative Detection | Finds double negatives (e.g., "don't have nothing") |
| Run-on Sentence Detection | Identifies excessively long compound sentences |
| Comma Splice Detection | Finds improperly joined independent clauses |
| Missing Punctuation | Detects sentences lacking end punctuation |
| Severity Levels | Issues categorized as Low, Medium, or High severity |

</details>

<details open>
<summary><strong>✍️ Style Analysis</strong></summary>

| Feature | Description |
|---------|-------------|
| Passive Voice Detection | 85%+ accuracy with confidence scoring (0.0-1.0) |
| Adverb Counting | Counts `-ly` words throughout the text |
| Hidden Verbs | Finds nominalizations (e.g., "decision" → "decide") |
| Overall Style Score | 0-100% rating based on multiple factors |

</details>

<details open>
<summary><strong>📊 Readability Metrics</strong></summary>

| Metric | Description |
|--------|-------------|
| Flesch Reading Ease | 0-100 scale (higher = easier to read) |
| Flesch-Kincaid Grade Level | U.S. school grade level equivalent |
| SMOG Index | Readability formula for healthcare documents |
| Coleman-Liau Index | Character-based readability |
| Automated Readability Index | Character and word count based |
| Average Words per Sentence | Sentence complexity indicator |
| Average Syllables per Word | Vocabulary complexity indicator |

</details>

<details open>
<summary><strong>🔗 Sticky Sentences</strong></summary>

| Feature | Description |
|---------|-------------|
| Overall Glue Index | Percentage of "glue words" (the, a, is, etc.) |
| Sticky Sentence Detection | Sentences with >45% glue words |
| Semi-Sticky Detection | Sentences with 35-45% glue words |
| Position Tracking | Character-level positions for highlighting |

</details>

<details open>
<summary><strong>⚡ Pacing Analysis</strong></summary>

| Category | Description |
|----------|-------------|
| Fast-Paced | Sentences with <10 words |
| Medium-Paced | Sentences with 10-20 words |
| Slow-Paced | Sentences with >20 words |
| Distribution | Count and percentage per category |

</details>

<details open>
<summary><strong>📏 Sentence Structure</strong></summary>

| Feature | Description |
|---------|-------------|
| Average Length | Mean word count per sentence |
| Standard Deviation | Variation in sentence length |
| Variety Score | 0-10 scale measuring length diversity |
| Very Long Detection | Sentences >30 words flagged |
| Shortest/Longest | Extremes identified |

</details>

<details open>
<summary><strong>🔄 Transition Analysis</strong></summary>

| Feature | Description |
|---------|-------------|
| Transition Count | Sentences containing transitions |
| Transition Percentage | Ratio of sentences with transitions |
| Unique Transitions | Count of distinct transition words |
| Most Common | Ranked list with frequencies |
| Multi-word Support | Detects phrases like "on the other hand" |

</details>

<details open>
<summary><strong>🔁 Repetition Analysis</strong></summary>

| Feature | Description |
|---------|-------------|
| Overused Words | Words appearing >0.5% frequency |
| Repeated Phrases | 2-4 word phrase repetition |
| Echoes | Word repetition within 20 words |
| Position Tracking | Exact character positions |

</details>

<details open>
<summary><strong>👁️👂✋👃👅 Sensory Language</strong></summary>

| Sense | Example Words |
|-------|---------------|
| Sight | see, bright, vivid, sparkle, glowing |
| Sound | hear, loud, whisper, echo, buzz |
| Touch | feel, soft, rough, texture, smooth |
| Smell | scent, aroma, fragrant, stench |
| Taste | flavor, sweet, savory, bitter |

</details>

<details open>
<summary><strong>💭 Diction Analysis</strong></summary>

| Feature | Description |
|---------|-------------|
| Vague Words | thing, stuff, nice, very, really |
| Vague Phrases | "kind of", "sort of", "a bit" |
| Frequency Count | Per-word usage statistics |
| Position Tracking | Character-level locations |

</details>

<details open>
<summary><strong>🎭 Cliché Detection</strong></summary>

50+ common clichés tracked including:
- "avoid like the plague"
- "piece of cake"
- "think outside the box"
- "at the end of the day"
- "break the ice"

</details>

<details open>
<summary><strong>✅ Consistency Checking</strong></summary>

| Check Type | Examples |
|------------|----------|
| US vs UK Spelling | color/colour, analyze/analyse |
| Hyphenation | email/e-mail, online/on-line |
| Capitalization | Inconsistent title case |

</details>

<details open>
<summary><strong>🔤 Acronym Analysis</strong></summary>

| Feature | Description |
|---------|-------------|
| Total Count | All acronym occurrences |
| Unique Count | Distinct acronyms found |
| Frequency List | Ranked by usage |

</details>

<details open>
<summary><strong>💼 Business Jargon</strong></summary>

Single words and phrases detected:
- synergy, leverage, paradigm
- "circle back", "touch base"
- "low-hanging fruit", "move the needle"

</details>

<details open>
<summary><strong>🧩 Complex Paragraphs</strong></summary>

| Threshold | Description |
|-----------|-------------|
| Sentence Length | >20 words average |
| Syllables | >1.8 per word average |
| Position Tracking | Start/end character indices |

</details>

<details open>
<summary><strong>🔗 Conjunction Starts</strong></summary>

Tracks sentences beginning with:
- and, but, or, so, yet, for, nor

</details>

---

## Architecture

### System Design Overview

```
┌─────────────────────────────────────────────────────────────────────────────┐
│                           Rust_Grammar Architecture                          │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐    ┌─────────────┐  │
│  │   CLI App   │    │  REST API   │    │   Library   │    │ HTML Visual │  │
│  │  (main.rs)  │    │(api-server) │    │  (lib.rs)   │    │(visualizer) │  │
│  └──────┬──────┘    └──────┬──────┘    └──────┬──────┘    └──────┬──────┘  │
│         │                  │                  │                  │          │
│         └──────────────────┴────────┬─────────┴──────────────────┘          │
│                                     │                                        │
│                          ┌──────────▼──────────┐                            │
│                          │    TextAnalyzer     │                            │
│                          │   (Core Engine)     │                            │
│                          └──────────┬──────────┘                            │
│                                     │                                        │
│         ┌───────────────────────────┼───────────────────────────┐           │
│         │                           │                           │           │
│  ┌──────▼──────┐           ┌───────▼───────┐           ┌───────▼───────┐   │
│  │   Grammar   │           │Comprehensive  │           │ Configuration │   │
│  │   Module    │           │   Analysis    │           │    System     │   │
│  ├─────────────┤           ├───────────────┤           ├───────────────┤   │
│  │• Sentence   │           │• Sticky Sent. │           │• YAML/TOML    │   │
│  │  Splitter   │           │• Pacing       │           │• Presets      │   │
│  │• Passive    │           │• Transitions  │           │• Thresholds   │   │
│  │  Voice      │           │• Sensory      │           │• Feature      │   │
│  │• Grammar    │           │• Clichés      │           │  Toggles      │   │
│  │  Checker    │           │• Jargon       │           │               │   │
│  └──────┬──────┘           └───────┬───────┘           └───────────────┘   │
│         │                          │                                        │
│  ┌──────▼──────────────────────────▼──────┐                                │
│  │           Dictionaries Module           │                                │
│  ├─────────────────────────────────────────┤                                │
│  │  • 200+ Abbreviations                   │                                │
│  │  • 200+ Irregular Past Participles      │                                │
│  │  • 1000+ Syllable Counts                │                                │
│  │  • Glue Words, Transitions, Clichés     │                                │
│  └─────────────────────────────────────────┘                                │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────────────────┐│
│  │                         Error Handling Layer                            ││
│  │    Result<T, AnalysisError> throughout • Zero crashes guaranteed        ││
│  └─────────────────────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────────────────────┘
```

### Directory Structure

```
rust_grammar/
├── Cargo.toml                        # Project manifest and dependencies
├── README.md                         # This documentation
├── LICENSE                           # MIT License
├── config.example.yaml               # Example configuration file
├── sample.txt                        # Sample text for testing
│
├── src/
│   ├── main.rs                       # CLI entry point with clap
│   ├── lib.rs                        # Core library exports
│   ├── error.rs                      # Custom error types (thiserror)
│   ├── config.rs                     # Configuration system
│   ├── word_lists.rs                 # Static word dictionaries
│   ├── analysis_reports.rs           # Report data structures
│   ├── comprehensive_analysis.rs     # All 19 analysis features
│   ├── visualizer.rs                 # HTML report generator
│   │
│   ├── bin/
│   │   ├── api-server.rs             # Basic REST API server (1 endpoint)
│   │   └── api-server-enhanced.rs    # Enhanced API with 6 endpoints
│   │
│   ├── dictionaries/
│   │   ├── mod.rs                    # Module exports
│   │   ├── abbreviations.rs          # 200+ abbreviations
│   │   ├── irregular_verbs.rs        # Past participles dictionary
│   │   └── syllable_dict.rs          # 1000+ syllable counts
│   │
│   └── grammar/
│       ├── mod.rs                    # Module exports
│       ├── sentence_splitter.rs      # Advanced sentence boundary detection
│       ├── passive_voice.rs          # Confidence-scored detection
│       └── checker.rs                # Grammar rules engine
│
├── tests/
│   └── integration_tests.rs          # Comprehensive integration tests
│
├── benches/
│   └── performance.rs                # Criterion benchmarks
│
└── docs/
    ├── API_DOCUMENTATION.md          # REST API documentation
    ├── IMPLEMENTATION.md             # Technical details
    ├── QUICKSTART.md                 # Quick setup guide
    └── CHANGELOG.md                  # Version history
```

---

## Installation

### Prerequisites

| Requirement | Minimum Version | Notes |
|------------|-----------------|-------|
| Rust | 1.75+ | Install via [rustup]https://rustup.rs/ |
| Cargo | Latest | Included with Rust |
| Git | Any recent | For cloning repository |

### Method 1: Install from Crates.io

```bash
# Install as a library dependency
cargo add Rust_Grammar

# Or add to Cargo.toml manually
[dependencies]
Rust_Grammar = "2.1.1"
```

### Method 2: Install from Source

```bash
# Clone the repository
git clone https://github.com/Eeman1113/rust_grammar.git
cd rust_grammar

# Build release version (optimized)
cargo build --release

# Verify installation
cargo test

# Optional: Install binary globally
cargo install --path .
```

### Method 3: Build API Server

```bash
# Build enhanced API server (recommended)
cargo build --release --features server --bin api-server-enhanced

# Or build basic API server
cargo build --release --features server --bin api-server
```

### Feature Flags

| Feature | Description | Default |
|---------|-------------|---------|
| `cli` | Command-line interface | ✅ Yes |
| `server` | REST API server | ❌ No |
| `parallel` | Rayon parallel processing | ✅ Yes |
| `markdown` | Markdown preprocessing | ✅ Yes |
| `html` | HTML parsing support | ✅ Yes |
| `full` | All features enabled | ❌ No |

---

## Configuration

### Configuration File Format

The analyzer supports both YAML and TOML configuration formats.

#### YAML Configuration (`config.yaml`)

```yaml
# Text Analyzer Configuration

# Input validation settings
validation:
  max_file_size_mb: 10
  min_words: 10
  max_words: null
  timeout_seconds: 300

# Analysis behavior settings
analysis:
  parallel_processing: true
  cache_results: false
  document_type: general  # general|academic|fiction|business|technical

# Threshold settings
thresholds:
  sticky_sentence_threshold: 40.0
  overused_word_threshold: 0.5
  echo_distance: 20
  very_long_sentence: 30
  complex_paragraph_sentence_length: 20.0
  complex_paragraph_syllables: 1.8
  passive_voice_max: 10
  adverb_max: 20

# Feature toggles
features:
  grammar_check: true
  style_check: true
  readability_check: true
  consistency_check: true
  sensory_analysis: true
  cliche_detection: true
  jargon_detection: true
  echo_detection: true

# Output settings
output:
  format: text  # text|json|yaml|html
  verbosity: normal  # quiet|normal|verbose|debug
  color: true
  show_progress: true
```

### Document Type Presets

| Preset | Use Case | Key Modifications |
|--------|----------|-------------------|
| `general` | Default for most documents | Balanced settings |
| `academic` | Research papers, theses | Lenient on passive voice (max=20%) |
| `fiction` | Novels, short stories | Strict sticky sentences (35%) |
| `business` | Reports, proposals | Lenient glue words (45%) |
| `technical` | Documentation, manuals | Lenient complexity |

---

## Usage

### CLI Usage

```bash
# Basic analysis
./target/release/text-analyzer myfile.txt

# Comprehensive analysis (ALL 19 features)
./target/release/text-analyzer myfile.txt --all

# With document type preset
./target/release/text-analyzer paper.txt -a -t academic

# Save report to file
./target/release/text-analyzer myfile.txt -a -o report.txt

# JSON output
./target/release/text-analyzer myfile.txt -f json

# Visual HTML report
./target/release/text-analyzer myfile.txt -V

# Use custom configuration
./target/release/text-analyzer myfile.txt -c config.yaml
```

### Starting the API Server

```bash
# Start enhanced API server (recommended)
./target/release/api-server-enhanced

# Output:
# 🚀 Text Analyzer API running on http://0.0.0.0:2000
# 📝 POST to http://0.0.0.0:2000/analyze with JSON body: {"text": "your text"}
# 📊 POST to http://0.0.0.0:2000/score for scores only
# 📏 POST to http://0.0.0.0:2000/sentencelength for sentence length analysis
# 📖 POST to http://0.0.0.0:2000/readability for readability analysis
# 🎯 POST to http://0.0.0.0:2000/passivevoice for passive voice analysis
# 🔗 POST to http://0.0.0.0:2000/glueindex for glue index analysis
```

---

## REST API Reference

The API server runs on `http://0.0.0.0:2000` by default with CORS enabled.

### API Servers

| Server | Binary | Endpoints | Use Case |
|--------|--------|-----------|----------|
| Basic | `api-server` | 1 (`/analyze`) | Simple integration |
| Enhanced | `api-server-enhanced` | 6 | Full-featured applications |

---

### Endpoint Summary

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/analyze` | POST | Full analysis with all scores and issues |
| `/score` | POST | Scores only with ideal values and status |
| `/sentencelength` | POST | Detailed sentence length analysis |
| `/readability` | POST | Readability metrics and difficult paragraphs |
| `/passivevoice` | POST | Passive voice, adverbs, hidden verbs, and style |
| `/glueindex` | POST | Glue index and sticky sentences |

---

### 1. POST `/analyze`

**Full analysis with comprehensive scores and all detected issues.**

#### Request

```bash
curl -X POST http://localhost:2000/analyze \
  -H "Content-Type: application/json" \
  -d '{"text": "Your text to analyze here."}'
```

**Request Body:**
```json
{
  "text": "The report was written yesterday. This is very important."
}
```

#### Response

```json
{
  "scores": {
    "styleScore": {
      "score": 75,
      "percentage": 75.0,
      "message": "Good writing with minor improvements needed"
    },
    "styleGuideCompliance": {
      "score": 100,
      "percentage": 100.0,
      "message": "Create your own style guide"
    },
    "sentenceLength": {
      "score": 8,
      "percentage": 8.0,
      "message": "Use a few longer sentences to add more depth to your writing.",
      "numWords": 9,
      "numCharacters": 58,
      "avgSentenceLength": 4.5,
      "targetRange": "11 to 18",
      "sentenceVariety": 2.1,
      "varietyTarget": "over 3",
      "sentencesByWordCount": {
        "under10": 2,
        "range10to19": 0,
        "range20to29": 0,
        "range30to39": 0,
        "over40": 0
      },
      "individualSentenceLengths": [...]
    },
    "readabilityGrade": {
      "score": 5,
      "percentage": 31.25,
      "message": null
    },
    "sentenceVariety": {
      "score": 6,
      "percentage": 6.0,
      "message": null
    },
    "glueIndex": {
      "percentage": 33.3,
      "count": 0,
      "total": 2,
      "message": "Reduce the number of glue words to make your writing clearer.",
      "occurrences": []
    },
    "passiveVoice": {
      "count": 1,
      "percentage": 50.0,
      "message": null,
      "occurrences": [
        {
          "start": 11,
          "end": 22,
          "length": 11,
          "string": "was written",
          "paragraphKey": "0"
        }
      ]
    },
    "businessJargon": {
      "count": 0,
      "percentage": 0.0,
      "message": null,
      "occurrences": []
    },
    "complexParagraphs": {
      "percentage": 0.0,
      "count": 0,
      "total": 1,
      "message": null,
      "occurrences": []
    },
    "conjunctionStarts": {
      "percentage": 0.0,
      "count": 0,
      "total": 2,
      "message": null
    },
    "slowPacing": {
      "percentage": 0.0,
      "count": 0,
      "total": 2,
      "message": null
    },
    "veryLongSentences": {
      "percentage": 0.0,
      "count": 0,
      "total": 2,
      "message": null,
      "occurrences": []
    },
    "emotionTells": {
      "count": 0,
      "percentage": 0.0,
      "message": null
    },
    "ingStarts": {
      "percentage": 0.0,
      "count": 0,
      "total": 2,
      "message": "Rewrite some of your sentences that start with words ending in \"-ing.\"",
      "occurrences": []
    },
    "dialogueTags": {
      "percentage": 0.0,
      "count": 0,
      "total": 0,
      "message": "Remove some dialogue tags to help your writing flow better."
    },
    "unusualDialogueTags": {
      "percentage": 0.0,
      "count": 0,
      "total": 0,
      "message": null
    },
    "dialogueTagsWithAdverbs": {
      "percentage": 0.0,
      "count": 0,
      "total": 0,
      "message": "Remove adverbs from dialogue tags and \"show\" emotions more."
    },
    "weakAdverbs": {
      "count": 0,
      "percentage": 0.0,
      "message": "Replace some adverbs with stronger verbs to improve engagement.",
      "occurrences": []
    }
  },
  "issues": [
    {
      "Id": "auto_11_22_11_passive_was_written",
      "start": 11,
      "length": 11,
      "end": 22,
      "paragraphKey": "0",
      "string": "was written",
      "type": "PassiveVoice",
      "suggestions": {
        "recommendation": ["Consider using active voice for clarity"]
      }
    },
    {
      "Id": "auto_37_41_4_vague_very",
      "start": 37,
      "length": 4,
      "end": 41,
      "paragraphKey": "0",
      "string": "very",
      "type": "VagueWord",
      "suggestions": {
        "recommendation": ["Be more specific", "Use concrete language"]
      }
    }
  ],
  "summary": {
    "total_issues": 2,
    "word_count": 9,
    "sentence_count": 2,
    "paragraph_count": 1,
    "character_count": 58
  }
}
```

---

### 2. POST `/score`

**Returns only scoring metrics with ideal values, status, and helpful messages.**

#### Request

```bash
curl -X POST http://localhost:2000/score \
  -H "Content-Type: application/json" \
  -d '{"text": "Your text to analyze here."}'
```

**Request Body:**
```json
{
  "text": "The report was written yesterday. This is very important."
}
```

#### Response

```json
{
  "scores": {
    "styleScore": {
      "current": 75.0,
      "ideal": "80-100",
      "status": "fair",
      "message": "Good foundation. Focus on reducing passive voice and improving sentence variety."
    },
    "sentenceLength": {
      "current": 4.5,
      "ideal": "15-20 words",
      "status": "needs improvement",
      "message": "Your sentences average 4.5 words. Add longer sentences (15-20 words) to create more depth and flow in your writing."
    },
    "readability": {
      "current": 5.2,
      "ideal": "7-9 grade level",
      "status": "fair",
      "message": "Your writing is at grade level 5.2. Consider using more complex sentence structures and vocabulary to add sophistication."
    },
    "sentenceVariety": {
      "current": 2.1,
      "ideal": "5-10",
      "status": "needs improvement",
      "message": "Your sentences lack variety (σ=2.1). Combine short punchy sentences with longer, flowing ones to maintain reader interest."
    },
    "glueIndex": {
      "current": 33.3,
      "ideal": "< 40%",
      "status": "good",
      "message": "Great! Your glue word usage is within the ideal range, keeping your writing clear and direct."
    },
    "passiveVoice": {
      "current": 50.0,
      "ideal": "< 10%",
      "status": "needs improvement",
      "message": "High passive voice usage: 1 instances (50.0%). Rewrite in active voice to make your writing more dynamic and clear."
    },
    "businessJargon": {
      "current": 0.0,
      "ideal": "0 instances",
      "status": "good",
      "message": "Perfect! No business jargon detected. Your writing is clear and accessible."
    },
    "complexParagraphs": {
      "current": 0.0,
      "ideal": "0%",
      "status": "good",
      "message": "Great! All your paragraphs are easy to read with well-balanced sentence lengths."
    },
    "conjunctionStarts": {
      "current": 0.0,
      "ideal": "< 10%",
      "status": "good",
      "message": "Good! Your sentence variety creates natural flow without overusing conjunctions at the start."
    },
    "slowPacing": {
      "current": 0.0,
      "ideal": "< 30%",
      "status": "good",
      "message": "Excellent pacing! Your sentences maintain good rhythm and energy."
    },
    "veryLongSentences": {
      "current": 0.0,
      "ideal": "< 10%",
      "status": "good",
      "message": "Perfect! No overly long sentences. Your writing maintains good readability."
    },
    "emotionTells": {
      "current": 0.0,
      "ideal": "0 instances",
      "status": "good",
      "message": "Excellent! You're showing emotions through action and description rather than telling."
    },
    "ingStarts": {
      "current": 0.0,
      "ideal": "< 10%",
      "status": "good",
      "message": "Great! Your sentence variety keeps the writing fresh and engaging."
    },
    "weakAdverbs": {
      "current": 0.0,
      "ideal": "< 5%",
      "status": "good",
      "message": "Perfect! No weak adverbs detected. Your verbs are strong and precise."
    },
    "dialogueTags": {
      "current": 0.0,
      "ideal": "< 50%",
      "status": "good",
      "message": "No dialogue detected, or dialogue is well-balanced with minimal tags."
    }
  },
  "word_count": 9,
  "sentence_count": 2,
  "complex_words_count": 2
}
```

---

### 3. POST `/sentencelength`

**Detailed sentence length analysis with individual sentence positions.**

#### Request

```bash
curl -X POST http://localhost:2000/sentencelength \
  -H "Content-Type: application/json" \
  -d '{
    "data": [
      {"text": "The quick brown fox jumps over the lazy dog. This is a test.", "key": "para_0"},
      {"text": "Another paragraph with different content.", "key": "para_1"}
    ]
  }'
```

**Request Body:**
```json
{
  "data": [
    {
      "text": "Paragraph text here.",
      "key": "para_0"
    },
    {
      "text": "Another paragraph.",
      "key": "para_1"
    }
  ]
}
```

#### Response

```json
{
  "score": 70,
  "percentage": 70.0,
  "message": "Great! Your sentence length is in the ideal range.",
  "numWords": 15,
  "numCharacters": 75,
  "avgSentenceLength": 7.5,
  "longestSentenceLength": 9,
  "targetRange": "11 to 18",
  "sentenceVariety": 2.1,
  "varietyTarget": "over 3",
  "sentencesByWordCount": {
    "under10": 2,
    "range10to19": 0,
    "range20to29": 0,
    "range30to39": 0,
    "over40": 0
  },
  "individualSentenceLengths": [
    {
      "start": 0,
      "end": 44,
      "length": 44,
      "string": "The quick brown fox jumps over the lazy dog.",
      "wordCount": 9,
      "paragraphKey": "para_0",
      "kind": "under10"
    },
    {
      "start": 45,
      "end": 60,
      "length": 15,
      "string": "This is a test.",
      "wordCount": 4,
      "paragraphKey": "para_0",
      "kind": "under10"
    },
    {
      "start": 0,
      "end": 40,
      "length": 40,
      "string": "Another paragraph with different content.",
      "wordCount": 5,
      "paragraphKey": "para_1",
      "kind": "under10"
    }
  ]
}
```

---

### 4. POST `/readability`

**Readability metrics with difficult paragraph identification.**

#### Request

```bash
curl -X POST http://localhost:2000/readability \
  -H "Content-Type: application/json" \
  -d '{
    "data": [
      {"text": "Your paragraph text here.", "key": "para_0"}
    ]
  }'
```

**Request Body:**
```json
{
  "data": [
    {
      "text": "Paragraph text here.",
      "key": "para_0"
    }
  ]
}
```

#### Response

```json
{
  "estimatedReadingTime": "0 min, 15 sec",
  "message": "Excellent! Your document is very easy to read - perfect for a wide audience.",
  "fleschReadingEase": 92.5,
  "fleschKincaidGrade": 4.2,
  "colemanLiau": 6.1,
  "automatedReadabilityIndex": 5.3,
  "difficultParagraphs": [
    {
      "difficulty": "slightly difficult",
      "start": 0,
      "end": 250,
      "string": "Full paragraph text...",
      "excerpt": "First 50 characters of the paragraph...",
      "paragraphKey": "para_2"
    }
  ]
}
```

**Difficulty Levels:**
- `"very hard"` - Average word length >6.5 and sentence length >30
- `"hard"` - Average word length >5.5 and sentence length >25
- `"slightly difficult"` - Sentence length >20

---

### 5. POST `/passivevoice`

**Comprehensive style analysis including passive voice, adverbs, hidden verbs, and more.**

#### Request

```bash
curl -X POST http://localhost:2000/passivevoice \
  -H "Content-Type: application/json" \
  -d '{
    "data": [
      {"text": "The report was written by the team. It seemed very important.", "key": "para_0"}
    ]
  }'
```

**Request Body:**
```json
{
  "data": [
    {
      "text": "Paragraph text here.",
      "key": "para_0"
    }
  ]
}
```

#### Response

```json
{
  "passiveVerbsFound": 1,
  "passiveVerbsMessage": "1 passive verb found. Consider revising for stronger, more direct writing.",
  "passiveVerbs": [
    {
      "verb": "was written",
      "count": 1,
      "occurrences": [
        {
          "start": 11,
          "end": 22,
          "string": "was written",
          "paragraphKey": "para_0",
          "report": "passiveVerbs"
        }
      ]
    }
  ],
  "hiddenVerbsFound": 0,
  "hiddenVerbsMessage": "No hidden verbs found.",
  "hiddenVerbs": [],
  "adverbsInDialogue": 0,
  "adverbsOutsideDialogue": 1,
  "adverbsMessage": "1 adverb found outside dialogue. Use sparingly.",
  "adverbsList": [
    {
      "adverb": "very",
      "count": 1,
      "occurrences": [
        {
          "start": 47,
          "end": 51,
          "string": "very",
          "paragraphKey": "para_0",
          "report": "adverbs"
        }
      ]
    }
  ],
  "readabilityEnhancementsFound": 0,
  "readabilityEnhancementsMessage": "No weak constructions found.",
  "readabilityEnhancements": [],
  "inclusiveLanguageMessage": "No non-inclusive language detected.",
  "inclusiveLanguageImprovements": [],
  "emotionTellsMessage": "1 emotion tell found (e.g., 'felt', 'seemed'). Show, don't tell emotions.",
  "emotionTells": [
    {
      "phrase": "seemed",
      "count": 1,
      "occurrences": [...]
    }
  ],
  "styleImprovementsMessage": "1 filler word found (e.g., 'very', 'really'). Remove for stronger writing.",
  "styleImprovements": [...],
  "businessJargonMessage": "No business jargon found.",
  "businessJargon": [],
  "longSubordinateClausesMessage": "No overly complex sentences found.",
  "longSubordinateClauses": [],
  "passiveIndex": 50.0,
  "passiveIndexMessage": "Very high passive voice: 50.0% (target: up to 25%). Extensive revision needed - convert to active voice.",
  "passiveIndexTarget": "up to 25",
  "repeatedSentenceStartsMessage": "No repetitive sentence starts found.",
  "repeatedSentenceStarts": [],
  "styleGuideItemsMessage": "No style guide violations found.",
  "styleGuideItems": []
}
```

**Analysis Categories:**
| Category | Description |
|----------|-------------|
| `passiveVerbs` | Passive voice constructions |
| `hiddenVerbs` | Nominalizations (e.g., "make a decision" → "decide") |
| `adverbsList` | Words ending in -ly |
| `readabilityEnhancements` | Weak constructions ("there is", "it was") |
| `inclusiveLanguageImprovements` | Gendered/non-inclusive language |
| `emotionTells` | Words like "felt", "seemed", "appeared" |
| `styleImprovements` | Filler words ("very", "really", "just") |
| `businessJargon` | Corporate buzzwords |
| `longSubordinateClauses` | Sentences with 3+ commas |
| `repeatedSentenceStarts` | Words used 3+ times to start sentences |
| `styleGuideItems` | Common grammar mistakes ("alot", "could of") |

---

### 6. POST `/glueindex`

**Glue word analysis and sticky sentence detection.**

#### Request

```bash
curl -X POST http://localhost:2000/glueindex \
  -H "Content-Type: application/json" \
  -d '{
    "data": [
      {"text": "The fact that it is the case that the problem is in the system.", "key": "para_0"}
    ]
  }'
```

**Request Body:**
```json
{
  "data": [
    {
      "text": "Paragraph text here.",
      "key": "para_0"
    }
  ]
}
```

#### Response

```json
{
  "glueIndex": 45.2,
  "glueIndexTarget": "up to 40%",
  "sentences": [
    {
      "start": 0,
      "end": 63,
      "string": "The fact that it is the case that the problem is in the system.",
      "excerpt": "The fact that it is the case that the problem is in...",
      "gluePercentage": 61.5,
      "category": "sticky",
      "paragraphKey": "para_0"
    }
  ]
}
```

**Sentence Categories:**
| Category | Glue Percentage | Description |
|----------|-----------------|-------------|
| `sticky` | >45% | High glue word density, needs revision |
| `semi-sticky` | 35-45% | Moderate glue word density |

---

### Error Responses

All endpoints return consistent error responses:

```json
{
  "error": "Error message description"
}
```

| Status Code | Error | Description |
|-------------|-------|-------------|
| 400 | `Text cannot be empty` | Empty text provided |
| 500 | `Failed to analyze text: [details]` | Analysis processing error |

---

## Code Examples

### Example 1: Rust Library Usage

```rust
use Rust_Grammar::{TextAnalyzer, Config, FullAnalysisReport};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let text = std::fs::read_to_string("article.txt")?;
    let config = Config::default();
    let analyzer = TextAnalyzer::new(text, config)?;
    
    // Get basic statistics
    let stats = analyzer.statistics();
    println!("Words: {}", stats.word_count);
    
    // Get readability
    let readability = analyzer.readability_metrics()?;
    println!("Reading Ease: {:.1}", readability.flesch_reading_ease);
    
    // Check grammar
    let grammar = analyzer.check_grammar()?;
    println!("Grammar issues: {}", grammar.len());
    
    // Detect passive voice
    let passive = analyzer.detect_passive_voice()?;
    for pv in &passive {
        println!("Passive: '{}' (confidence: {:.0}%)", 
            pv.text, pv.confidence * 100.0);
    }
    
    // Full comprehensive report
    let report: FullAnalysisReport = analyzer.generate_full_report()?;
    println!("Style Score: {}%", report.style_score);
    
    Ok(())
}
```

### Example 2: Python API Client

```python
#!/usr/bin/env python3
import requests

API_BASE = "http://localhost:2000"

def analyze_text(text: str) -> dict:
    """Full analysis with scores and issues."""
    response = requests.post(
        f"{API_BASE}/analyze",
        json={"text": text}
    )
    return response.json()

def get_scores(text: str) -> dict:
    """Get scores only with ideal values."""
    response = requests.post(
        f"{API_BASE}/score",
        json={"text": text}
    )
    return response.json()

def get_sentence_length(paragraphs: list) -> dict:
    """Analyze sentence length by paragraph."""
    response = requests.post(
        f"{API_BASE}/sentencelength",
        json={"data": paragraphs}
    )
    return response.json()

def get_readability(paragraphs: list) -> dict:
    """Get readability metrics."""
    response = requests.post(
        f"{API_BASE}/readability",
        json={"data": paragraphs}
    )
    return response.json()

def get_passive_voice(paragraphs: list) -> dict:
    """Get passive voice and style analysis."""
    response = requests.post(
        f"{API_BASE}/passivevoice",
        json={"data": paragraphs}
    )
    return response.json()

def get_glue_index(paragraphs: list) -> dict:
    """Get glue index and sticky sentences."""
    response = requests.post(
        f"{API_BASE}/glueindex",
        json={"data": paragraphs}
    )
    return response.json()

# Example usage
if __name__ == "__main__":
    text = """
    The comprehensive report was written by the research team. 
    At the end of the day, we need to leverage our synergies.
    """
    
    # Full analysis
    result = analyze_text(text)
    print(f"Style Score: {result['scores']['styleScore']['score']}")
    print(f"Issues Found: {result['summary']['total_issues']}")
    
    # Scores only
    scores = get_scores(text)
    for metric, data in scores['scores'].items():
        print(f"{metric}: {data['current']} (ideal: {data['ideal']}) - {data['status']}")
    
    # Paragraph-based analysis
    paragraphs = [
        {"text": "First paragraph text.", "key": "para_0"},
        {"text": "Second paragraph text.", "key": "para_1"}
    ]
    
    readability = get_readability(paragraphs)
    print(f"Flesch Reading Ease: {readability['fleschReadingEase']}")
    
    passive = get_passive_voice(paragraphs)
    print(f"Passive Voice Found: {passive['passiveVerbsFound']}")
    
    glue = get_glue_index(paragraphs)
    print(f"Glue Index: {glue['glueIndex']}%")
```

### Example 3: JavaScript/Node.js Client

```javascript
const API_BASE = 'http://localhost:2000';

async function analyzeText(text) {
  const response = await fetch(`${API_BASE}/analyze`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ text })
  });
  return response.json();
}

async function getScores(text) {
  const response = await fetch(`${API_BASE}/score`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ text })
  });
  return response.json();
}

async function getSentenceLength(paragraphs) {
  const response = await fetch(`${API_BASE}/sentencelength`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ data: paragraphs })
  });
  return response.json();
}

async function getReadability(paragraphs) {
  const response = await fetch(`${API_BASE}/readability`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ data: paragraphs })
  });
  return response.json();
}

async function getPassiveVoice(paragraphs) {
  const response = await fetch(`${API_BASE}/passivevoice`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ data: paragraphs })
  });
  return response.json();
}

async function getGlueIndex(paragraphs) {
  const response = await fetch(`${API_BASE}/glueindex`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ data: paragraphs })
  });
  return response.json();
}

// Example usage
async function main() {
  const text = `
    The comprehensive report was written by the research team.
    At the end of the day, we need to leverage our synergies.
  `;
  
  // Full analysis
  const result = await analyzeText(text);
  console.log(`Style Score: ${result.scores.styleScore.score}`);
  console.log(`Issues: ${result.summary.total_issues}`);
  
  // Scores with guidance
  const scores = await getScores(text);
  Object.entries(scores.scores).forEach(([metric, data]) => {
    console.log(`${metric}: ${data.current} (${data.status})`);
    console.log(`  → ${data.message}`);
  });
  
  // Paragraph-based analysis
  const paragraphs = [
    { text: 'First paragraph.', key: 'para_0' },
    { text: 'Second paragraph.', key: 'para_1' }
  ];
  
  const passive = await getPassiveVoice(paragraphs);
  console.log(`Passive Index: ${passive.passiveIndex}%`);
  console.log(passive.passiveIndexMessage);
}

main().catch(console.error);
```

### Example 4: cURL Test Script

```bash
#!/bin/bash
# test-api.sh - Test all API endpoints

API_URL="http://localhost:2000"
TEXT='{"text": "The report was written yesterday. This is very important."}'
PARA='{"data": [{"text": "The report was written yesterday. This is very important.", "key": "para_0"}]}'

echo "=== Testing /analyze ==="
curl -s -X POST "$API_URL/analyze" \
  -H "Content-Type: application/json" \
  -d "$TEXT" | jq '.summary'

echo -e "\n=== Testing /score ==="
curl -s -X POST "$API_URL/score" \
  -H "Content-Type: application/json" \
  -d "$TEXT" | jq '.scores.styleScore'

echo -e "\n=== Testing /sentencelength ==="
curl -s -X POST "$API_URL/sentencelength" \
  -H "Content-Type: application/json" \
  -d "$PARA" | jq '{score, avgSentenceLength, message}'

echo -e "\n=== Testing /readability ==="
curl -s -X POST "$API_URL/readability" \
  -H "Content-Type: application/json" \
  -d "$PARA" | jq '{fleschReadingEase, fleschKincaidGrade, message}'

echo -e "\n=== Testing /passivevoice ==="
curl -s -X POST "$API_URL/passivevoice" \
  -H "Content-Type: application/json" \
  -d "$PARA" | jq '{passiveVerbsFound, passiveIndex, passiveIndexMessage}'

echo -e "\n=== Testing /glueindex ==="
curl -s -X POST "$API_URL/glueindex" \
  -H "Content-Type: application/json" \
  -d "$PARA" | jq '{glueIndex, glueIndexTarget}'

echo -e "\n✅ All tests complete!"
```

---

## Data Models

### Request Models

#### Simple Text Request (for `/analyze`, `/score`)

```typescript
interface AnalyzeRequest {
  text: string;
}
```

#### Paragraph Data Request (for `/sentencelength`, `/readability`, `/passivevoice`, `/glueindex`)

```typescript
interface ParagraphRequest {
  data: ParagraphData[];
}

interface ParagraphData {
  text: string;
  key: string;  // Unique identifier for the paragraph
}
```

### Response Models

<details>
<summary><strong>Occurrence Model (used across all endpoints)</strong></summary>

```typescript
interface Occurrence {
  start: number;       // Character position (start)
  end: number;         // Character position (end)
  length: number;      // Character length
  string: string;      // Matched text
  paragraphKey: string; // Reference to source paragraph
}
```

</details>

<details>
<summary><strong>Score Models</strong></summary>

```typescript
interface SimpleScore {
  current: number;    // Current value
  ideal: string;      // Target range (e.g., "< 10%")
  status: string;     // "good" | "fair" | "needs improvement"
  message: string;    // Actionable guidance
}

interface ScoreDetail {
  score: number;
  percentage: number;
  message?: string;
}

interface PercentageScore {
  percentage: number;
  count: number;
  total: number;
  message?: string;
  occurrences?: Occurrence[];
}

interface CountScore {
  count: number;
  percentage?: number;
  message?: string;
  occurrences?: Occurrence[];
}
```

</details>

<details>
<summary><strong>Issue Model</strong></summary>

```typescript
interface AnalysisIssue {
  Id: string;           // Unique identifier
  start: number;        // Character position (start)
  end: number;          // Character position (end)
  length: number;       // Character length
  paragraphKey: string; // Source paragraph
  string: string;       // Matched text
  type: string;         // Issue category
  suggestions: {
    recommendation: string[];
  };
}
```

**Issue Types:**
- `PassiveVoice`
- `Grammar_SubjectVerbAgreement`
- `Grammar_DoubleNegative`
- `Grammar_RunOnSentence`
- `StickySentence`
- `OverusedWord`
- `Repetition`
- `Cliche`
- `VagueWord`
- `BusinessJargon`

</details>

---

## Error Handling

### Error Types

```rust
pub enum AnalysisError {
    IoError(std::io::Error),
    ValidationError(String),
    EncodingError(std::string::FromUtf8Error),
    JsonError(serde_json::Error),
    YamlError(serde_yaml::Error),
    ConfigError(String),
    TimeoutError(u64),
    RegexError(regex::Error),
    FileTooLarge { size: u64, max: u64 },
    DocumentTooShort { words: usize, min: usize },
    EmptyInput,
    InvalidPath(PathBuf),
    ProcessingError(String),
}
```

### API Error Handling

```rust
enum ApiError {
    EmptyText,
    AnalysisError(String),
}

// Returns:
// 400 Bad Request - for empty text
// 500 Internal Server Error - for analysis failures
```

---

## Testing

### Running Tests

```bash
# Run all tests
cargo test

# Run with output
cargo test -- --nocapture

# Run specific tests
cargo test grammar
cargo test integration
```

### API Testing

```bash
# Start the server
./target/release/api-server-enhanced &

# Run test script
./test-api.sh

# Or test individual endpoints
curl -X POST http://localhost:2000/analyze \
  -H "Content-Type: application/json" \
  -d '{"text": "Test sentence."}' | jq '.'
```

---

## Deployment

### Running the API Server

```bash
# Build
cargo build --release --features server --bin api-server-enhanced

# Run directly
./target/release/api-server-enhanced
# Server starts on http://0.0.0.0:2000

# Run with PM2 (production)
pm2 start ./target/release/api-server-enhanced --name text-analyzer-api
pm2 save
```

### Docker Deployment

```dockerfile
FROM rust:1.75 as builder
WORKDIR /app
COPY . .
RUN cargo build --release --features server --bin api-server-enhanced

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/api-server-enhanced /usr/local/bin/
EXPOSE 2000
CMD ["api-server-enhanced"]
```

```bash
docker build -t rust-grammar-api .
docker run -p 2000:2000 rust-grammar-api
```

### PM2 Configuration

```javascript
// ecosystem.config.js
module.exports = {
  apps: [{
    name: 'text-analyzer-api',
    script: './target/release/api-server-enhanced',
    instances: 1,
    autorestart: true,
    max_memory_restart: '1G',
    env: {
      RUST_LOG: 'info'
    }
  }]
};
```

---

## Contributing

1. Fork the repository
2. Create a feature branch: `git checkout -b feature/new-feature`
3. Make your changes
4. Run tests: `cargo test`
5. Format code: `cargo fmt`
6. Create pull request

---

## Changelog & Roadmap

### v2.1.1 (Current)
- ✅ Enhanced API with 6 endpoints
- ✅ Paragraph-relative position tracking
- ✅ Unicode-safe character indexing
- ✅ Comprehensive style analysis
- ✅ Intelligent messaging system

### Roadmap
- [ ] WebSocket real-time analysis
- [ ] Multi-language support
- [ ] VS Code extension
- [ ] WebAssembly build

---

## FAQ

**Q: What port does the API run on?**
A: `0.0.0.0:2000` by default.

**Q: Is CORS enabled?**
A: Yes, permissive CORS is enabled for all endpoints.

**Q: What's the difference between the two API servers?**
A: `api-server` has 1 endpoint (`/analyze`), while `api-server-enhanced` has 6 specialized endpoints.

**Q: How are positions calculated?**
A: All positions are character-based (not byte-based) for proper Unicode support.

---

## License & Credits

**MIT License** - Copyright (c) 2025 Eeman Majumder

**Built with:**
- [Rust]https://www.rust-lang.org/
- [Axum]https://github.com/tokio-rs/axum - Web framework
- [Tokio]https://tokio.rs/ - Async runtime
- [Serde]https://serde.rs/ - Serialization
- [Tower-HTTP]https://github.com/tower-rs/tower-http - HTTP middleware

---

<div align="center">

**Built with ❤️ using Rust 🦀**

[GitHub](https://github.com/Eeman1113/rust_grammar) · [Crates.io](https://crates.io/crates/Rust_Grammar)

</div>