pystylometry 1.3.0__tar.gz → 1.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. pystylometry-1.3.5/LICENSE +21 -0
  2. pystylometry-1.3.5/PKG-INFO +78 -0
  3. pystylometry-1.3.5/README.md +51 -0
  4. {pystylometry-1.3.0 → pystylometry-1.3.5}/pyproject.toml +6 -4
  5. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/__init__.py +42 -3
  6. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/_types.py +205 -3
  7. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/cli.py +321 -0
  8. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/lexical/__init__.py +5 -1
  9. pystylometry-1.3.5/pystylometry/lexical/repetition.py +506 -0
  10. pystylometry-1.3.5/pystylometry/lexical/ttr.py +340 -0
  11. pystylometry-1.3.0/PKG-INFO +0 -136
  12. pystylometry-1.3.0/README.md +0 -106
  13. pystylometry-1.3.0/pystylometry/lexical/ttr.py +0 -149
  14. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/README.md +0 -0
  15. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/_normalize.py +0 -0
  16. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/_utils.py +0 -0
  17. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/authorship/README.md +0 -0
  18. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/authorship/__init__.py +0 -0
  19. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/authorship/additional_methods.py +0 -0
  20. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/authorship/burrows_delta.py +0 -0
  21. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/authorship/compression.py +0 -0
  22. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/authorship/kilgarriff.py +0 -0
  23. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/authorship/zeta.py +0 -0
  24. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/character/README.md +0 -0
  25. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/character/__init__.py +0 -0
  26. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/character/character_metrics.py +0 -0
  27. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/consistency/README.md +0 -0
  28. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/consistency/__init__.py +0 -0
  29. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/consistency/_thresholds.py +0 -0
  30. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/consistency/drift.py +0 -0
  31. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/dialect/README.md +0 -0
  32. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/dialect/__init__.py +0 -0
  33. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/dialect/_data/dialect_markers.json +0 -0
  34. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/dialect/_loader.py +0 -0
  35. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/dialect/detector.py +0 -0
  36. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/lexical/README.md +0 -0
  37. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/lexical/advanced_diversity.py +0 -0
  38. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/lexical/function_words.py +0 -0
  39. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/lexical/hapax.py +0 -0
  40. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/lexical/mtld.py +0 -0
  41. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/lexical/word_frequency_sophistication.py +0 -0
  42. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/lexical/yule.py +0 -0
  43. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/ngrams/README.md +0 -0
  44. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/ngrams/__init__.py +0 -0
  45. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/ngrams/entropy.py +0 -0
  46. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/ngrams/extended_ngrams.py +0 -0
  47. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/prosody/README.md +0 -0
  48. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/prosody/__init__.py +0 -0
  49. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/prosody/rhythm_prosody.py +0 -0
  50. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/readability/README.md +0 -0
  51. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/readability/__init__.py +0 -0
  52. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/readability/additional_formulas.py +0 -0
  53. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/readability/ari.py +0 -0
  54. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/readability/coleman_liau.py +0 -0
  55. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/readability/complex_words.py +0 -0
  56. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/readability/flesch.py +0 -0
  57. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/readability/gunning_fog.py +0 -0
  58. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/readability/smog.py +0 -0
  59. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/readability/syllables.py +0 -0
  60. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/stylistic/README.md +0 -0
  61. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/stylistic/__init__.py +0 -0
  62. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/stylistic/cohesion_coherence.py +0 -0
  63. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/stylistic/genre_register.py +0 -0
  64. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/stylistic/markers.py +0 -0
  65. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/stylistic/vocabulary_overlap.py +0 -0
  66. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/syntactic/README.md +0 -0
  67. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/syntactic/__init__.py +0 -0
  68. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/syntactic/advanced_syntactic.py +0 -0
  69. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/syntactic/pos_ratios.py +0 -0
  70. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/syntactic/sentence_stats.py +0 -0
  71. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/syntactic/sentence_types.py +0 -0
  72. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/tokenizer.py +0 -0
  73. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/viz/README.md +0 -0
  74. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/viz/__init__.py +0 -0
  75. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/viz/drift.py +0 -0
  76. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/viz/jsx/__init__.py +0 -0
  77. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/viz/jsx/_base.py +0 -0
  78. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/viz/jsx/report.py +0 -0
  79. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/viz/jsx/timeline.py +0 -0
  80. {pystylometry-1.3.0 → pystylometry-1.3.5}/pystylometry/viz/jsx/viewer.py +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Craig Trim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.1
2
+ Name: pystylometry
3
+ Version: 1.3.5
4
+ Summary: Comprehensive Python package for stylometric analysis
5
+ License: MIT
6
+ Keywords: stylometry,nlp,text-analysis,authorship,readability,lexical-diversity,readability-metrics
7
+ Author: Craig Trim
8
+ Author-email: craigtrim@gmail.com
9
+ Requires-Python: >=3.9,<4.0
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
20
+ Classifier: Topic :: Text Processing :: Linguistic
21
+ Classifier: Typing :: Typed
22
+ Project-URL: Homepage, https://github.com/craigtrim/pystylometry
23
+ Project-URL: Issues, https://github.com/craigtrim/pystylometry/issues
24
+ Project-URL: Repository, https://github.com/craigtrim/pystylometry
25
+ Description-Content-Type: text/markdown
26
+
27
+ # pystylometry
28
+
29
+ [![PyPI version](https://badge.fury.io/py/pystylometry.svg)](https://badge.fury.io/py/pystylometry)
30
+ [![Downloads](https://static.pepy.tech/badge/pystylometry)](https://pepy.tech/project/pystylometry)
31
+ [![Downloads/Month](https://static.pepy.tech/badge/pystylometry/month)](https://pepy.tech/project/pystylometry)
32
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/downloads/)
33
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
34
+ [![Tests](https://img.shields.io/badge/tests-1022%20passed-brightgreen)]()
35
+
36
+ Stylometric analysis and authorship attribution for Python. 50+ metrics across 11 modules, from vocabulary diversity to AI-generation detection.
37
+
38
+ ## Install
39
+
40
+ ```bash
41
+ pip install pystylometry # Core (lexical metrics)
42
+ pip install pystylometry[all] # Everything
43
+ ```
44
+
45
+ ## Modules
46
+
47
+ | Module | Metrics | Description |
48
+ |--------|---------|-------------|
49
+ | [**lexical**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/lexical) | TTR, MTLD, Yule's K/I, Hapax, MATTR, VocD-D, HD-D, MSTTR, function words, word frequency | Vocabulary diversity and richness |
50
+ | [**readability**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/readability) | Flesch, Flesch-Kincaid, SMOG, Gunning Fog, Coleman-Liau, ARI, Dale-Chall, Fry, FORCAST, Linsear Write, Powers-Sumner-Kearl | Grade-level and difficulty scoring |
51
+ | [**syntactic**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/syntactic) | POS ratios, sentence types, parse tree depth, clausal density, passive voice, T-units, dependency distance | Sentence and parse structure (requires spaCy) |
52
+ | [**authorship**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/authorship) | Burrows' Delta, Cosine Delta, Zeta, Kilgarriff chi-squared, MinMax, John's Delta, NCD | Author attribution and text comparison |
53
+ | [**stylistic**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/stylistic) | Contractions, hedges, intensifiers, modals, punctuation, vocabulary overlap (Jaccard/Dice/Cosine/KL), cohesion, genre/register | Style markers and text similarity |
54
+ | [**character**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/character) | Letter frequencies, digit/uppercase ratios, special characters, whitespace | Character-level fingerprinting |
55
+ | [**ngrams**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/ngrams) | Word/character/POS n-grams, Shannon entropy, skipgrams | N-gram profiles and entropy |
56
+ | [**dialect**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/dialect) | British/American classification, spelling/grammar/vocabulary markers, markedness | Regional dialect detection |
57
+ | [**consistency**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/consistency) | Sliding-window chi-squared drift, pattern classification | Intra-document style analysis |
58
+ | [**prosody**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/prosody) | Syllable stress, rhythm regularity | Prose rhythm (requires spaCy) |
59
+ | [**viz**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/viz) | Timeline, scatter, report (PNG + interactive HTML) | Drift detection visualization |
60
+
61
+ ## Development
62
+
63
+ ```bash
64
+ git clone https://github.com/craigtrim/pystylometry && cd pystylometry
65
+ pip install -e ".[dev,all]"
66
+ make test # 1022 tests
67
+ make lint # ruff + mypy
68
+ make all # lint + test + build
69
+ ```
70
+
71
+ ## License
72
+
73
+ MIT
74
+
75
+ ## Author
76
+
77
+ Craig Trim -- craigtrim@gmail.com
78
+
@@ -0,0 +1,51 @@
1
+ # pystylometry
2
+
3
+ [![PyPI version](https://badge.fury.io/py/pystylometry.svg)](https://badge.fury.io/py/pystylometry)
4
+ [![Downloads](https://static.pepy.tech/badge/pystylometry)](https://pepy.tech/project/pystylometry)
5
+ [![Downloads/Month](https://static.pepy.tech/badge/pystylometry/month)](https://pepy.tech/project/pystylometry)
6
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/downloads/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
8
+ [![Tests](https://img.shields.io/badge/tests-1022%20passed-brightgreen)]()
9
+
10
+ Stylometric analysis and authorship attribution for Python. 50+ metrics across 11 modules, from vocabulary diversity to AI-generation detection.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pip install pystylometry # Core (lexical metrics)
16
+ pip install pystylometry[all] # Everything
17
+ ```
18
+
19
+ ## Modules
20
+
21
+ | Module | Metrics | Description |
22
+ |--------|---------|-------------|
23
+ | [**lexical**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/lexical) | TTR, MTLD, Yule's K/I, Hapax, MATTR, VocD-D, HD-D, MSTTR, function words, word frequency | Vocabulary diversity and richness |
24
+ | [**readability**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/readability) | Flesch, Flesch-Kincaid, SMOG, Gunning Fog, Coleman-Liau, ARI, Dale-Chall, Fry, FORCAST, Linsear Write, Powers-Sumner-Kearl | Grade-level and difficulty scoring |
25
+ | [**syntactic**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/syntactic) | POS ratios, sentence types, parse tree depth, clausal density, passive voice, T-units, dependency distance | Sentence and parse structure (requires spaCy) |
26
+ | [**authorship**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/authorship) | Burrows' Delta, Cosine Delta, Zeta, Kilgarriff chi-squared, MinMax, John's Delta, NCD | Author attribution and text comparison |
27
+ | [**stylistic**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/stylistic) | Contractions, hedges, intensifiers, modals, punctuation, vocabulary overlap (Jaccard/Dice/Cosine/KL), cohesion, genre/register | Style markers and text similarity |
28
+ | [**character**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/character) | Letter frequencies, digit/uppercase ratios, special characters, whitespace | Character-level fingerprinting |
29
+ | [**ngrams**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/ngrams) | Word/character/POS n-grams, Shannon entropy, skipgrams | N-gram profiles and entropy |
30
+ | [**dialect**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/dialect) | British/American classification, spelling/grammar/vocabulary markers, markedness | Regional dialect detection |
31
+ | [**consistency**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/consistency) | Sliding-window chi-squared drift, pattern classification | Intra-document style analysis |
32
+ | [**prosody**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/prosody) | Syllable stress, rhythm regularity | Prose rhythm (requires spaCy) |
33
+ | [**viz**](https://github.com/craigtrim/pystylometry/tree/master/pystylometry/viz) | Timeline, scatter, report (PNG + interactive HTML) | Drift detection visualization |
34
+
35
+ ## Development
36
+
37
+ ```bash
38
+ git clone https://github.com/craigtrim/pystylometry && cd pystylometry
39
+ pip install -e ".[dev,all]"
40
+ make test # 1022 tests
41
+ make lint # ruff + mypy
42
+ make all # lint + test + build
43
+ ```
44
+
45
+ ## License
46
+
47
+ MIT
48
+
49
+ ## Author
50
+
51
+ Craig Trim -- craigtrim@gmail.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pystylometry"
3
- version = "1.3.0"
3
+ version = "1.3.5"
4
4
  description = "Comprehensive Python package for stylometric analysis"
5
5
  authors = ["Craig Trim <craigtrim@gmail.com>"]
6
6
  readme = "README.md"
@@ -16,7 +16,7 @@ keywords = [
16
16
  "readability-metrics",
17
17
  ]
18
18
  classifiers = [
19
- "Development Status :: 4 - Beta",
19
+ "Development Status :: 5 - Production/Stable",
20
20
  "Intended Audience :: Science/Research",
21
21
  "Intended Audience :: Developers",
22
22
  "License :: OSI Approved :: MIT License",
@@ -35,6 +35,8 @@ classifiers = [
35
35
  pystylometry-drift = "pystylometry.cli:drift_cli"
36
36
  # pystylometry-viewer drift_analyzer.html
37
37
  pystylometry-viewer = "pystylometry.cli:viewer_cli"
38
+ # pystylometry-tokenize manuscript.txt --json --metadata
39
+ pystylometry-tokenize = "pystylometry.cli:tokenize_cli"
38
40
 
39
41
  [tool.poetry.urls]
40
42
  Homepage = "https://github.com/craigtrim/pystylometry"
@@ -43,7 +45,6 @@ Issues = "https://github.com/craigtrim/pystylometry/issues"
43
45
 
44
46
  [tool.poetry.dependencies]
45
47
  python = "^3.9"
46
- stylometry-ttr = "^1.0.3"
47
48
 
48
49
  [tool.poetry.group.readability.dependencies]
49
50
  pronouncing = "^0.2.0"
@@ -61,7 +62,7 @@ spacy = "^3.8.0"
61
62
  # - True neologisms (not in WordNet, not in BNC)
62
63
  # - Rare words (in BNC but not WordNet, or vice versa)
63
64
  # - Common words (in both lexicons)
64
- bnc-lookup = "*"
65
+ bnc-lookup = ">=1.3.0"
65
66
  wordnet-lookup = "*"
66
67
 
67
68
  [tool.poetry.group.viz.dependencies]
@@ -98,6 +99,7 @@ ignore = []
98
99
  "pystylometry/viz/jsx/*.py" = ["E501"]
99
100
  # Test files may have long assertions and test data
100
101
  "tests/*.py" = ["E501"]
102
+ "tests/**/*.py" = ["E501", "E402"]
101
103
 
102
104
  [tool.mypy]
103
105
  python_version = "3.9"
@@ -40,14 +40,13 @@ Usage:
40
40
  print(result.pattern_confidence)
41
41
  """
42
42
 
43
+ from . import lexical # noqa: E402
43
44
  from ._types import AnalysisResult
45
+ from .tokenizer import TokenizationStats, Tokenizer, TokenMetadata
44
46
 
45
47
  # Version
46
48
  __version__ = "0.1.0"
47
49
 
48
- # Core exports - always available
49
- from . import lexical
50
-
51
50
  # Optional exports - may raise ImportError if dependencies not installed
52
51
  try:
53
52
  from . import readability # noqa: F401
@@ -87,6 +86,41 @@ _CONSISTENCY_AVAILABLE = True
87
86
  _STYLISTIC_AVAILABLE = True
88
87
 
89
88
 
89
+ def tokenize(text: str, **kwargs: object) -> list[str]:
90
+ """Tokenize text using the stylometric tokenizer.
91
+
92
+ Convenience wrapper around Tokenizer.tokenize(). All keyword arguments
93
+ are forwarded to the Tokenizer constructor.
94
+
95
+ Args:
96
+ text: Input text to tokenize.
97
+ **kwargs: Options forwarded to Tokenizer (lowercase, strip_numbers,
98
+ expand_contractions, etc.).
99
+
100
+ Returns:
101
+ List of token strings.
102
+
103
+ Example:
104
+ >>> from pystylometry import tokenize
105
+ >>> tokenize("Hello, world! It's a test.")
106
+ ['hello', 'world', "it's", 'a', 'test']
107
+ """
108
+ return Tokenizer(**kwargs).tokenize(text) # type: ignore[arg-type]
109
+
110
+
111
+ def tokenize_with_metadata(text: str, **kwargs: object) -> list[TokenMetadata]:
112
+ """Tokenize text and return tokens with positional and type metadata.
113
+
114
+ Args:
115
+ text: Input text to tokenize.
116
+ **kwargs: Options forwarded to Tokenizer.
117
+
118
+ Returns:
119
+ List of TokenMetadata objects.
120
+ """
121
+ return Tokenizer(**kwargs).tokenize_with_metadata(text) # type: ignore[arg-type]
122
+
123
+
90
124
  def analyze(
91
125
  text: str,
92
126
  lexical_metrics: bool = True,
@@ -225,6 +259,11 @@ __all__ = [
225
259
  "__version__",
226
260
  "analyze",
227
261
  "get_available_modules",
262
+ "tokenize",
263
+ "tokenize_with_metadata",
264
+ "Tokenizer",
265
+ "TokenMetadata",
266
+ "TokenizationStats",
228
267
  "lexical",
229
268
  ]
230
269
 
@@ -23,7 +23,7 @@ from __future__ import annotations
23
23
 
24
24
  import statistics
25
25
  from dataclasses import dataclass
26
- from typing import Any
26
+ from typing import Any, Optional
27
27
 
28
28
  # ===== Distribution and Chunking =====
29
29
  # Related to GitHub Issue #27: Native chunked analysis with Distribution dataclass
@@ -316,8 +316,8 @@ class HapaxLexiconResult:
316
316
  class TTRResult:
317
317
  """Result from Type-Token Ratio (TTR) analysis.
318
318
 
319
- Wraps stylometry-ttr package functionality to measure vocabulary richness
320
- through the ratio of unique words (types) to total words (tokens).
319
+ Measures vocabulary richness through the ratio of unique words (types)
320
+ to total words (tokens).
321
321
 
322
322
  All numeric metrics include both a mean value (convenient access) and
323
323
  a full distribution with per-chunk values and statistics.
@@ -370,6 +370,208 @@ class TTRResult:
370
370
  metadata: dict[str, Any]
371
371
 
372
372
 
373
+ @dataclass
374
+ class TTRAggregateResult:
375
+ """Aggregated TTR statistics for a collection of texts.
376
+
377
+ Computes group-level summary statistics (mean, std, min, max, median)
378
+ across multiple ``TTRResult`` objects. Useful for comparative analysis
379
+ across authors, genres, or time periods.
380
+
381
+ Related GitHub Issue:
382
+ #43 - Inline stylometry-ttr into pystylometry (remove external dependency)
383
+ https://github.com/craigtrim/pystylometry/issues/43
384
+
385
+ Example:
386
+ >>> from pystylometry.lexical import compute_ttr, TTRAggregator
387
+ >>> results = [compute_ttr(t) for t in texts]
388
+ >>> agg = TTRAggregator()
389
+ >>> stats = agg.aggregate(results, group_id="Austen")
390
+ >>> stats.ttr_mean
391
+ 0.412
392
+ """
393
+
394
+ group_id: str
395
+ text_count: int
396
+ total_words: int
397
+
398
+ # Raw TTR statistics
399
+ ttr_mean: float
400
+ ttr_std: float
401
+ ttr_min: float
402
+ ttr_max: float
403
+ ttr_median: float
404
+
405
+ # Root TTR (Guiraud's index) statistics
406
+ root_ttr_mean: float
407
+ root_ttr_std: float
408
+
409
+ # Log TTR (Herdan's C) statistics
410
+ log_ttr_mean: float
411
+ log_ttr_std: float
412
+
413
+ # STTR statistics (None if no texts had enough words for STTR)
414
+ sttr_mean: Optional[float]
415
+ sttr_std: Optional[float]
416
+
417
+ # Delta std mean (None if no texts had delta metrics)
418
+ delta_std_mean: Optional[float]
419
+
420
+ metadata: dict[str, Any]
421
+
422
+
423
+ # ===== Repetition Detection Results =====
424
+ # Related to GitHub Issue #28: Verbal tics detection for slop analysis
425
+ # https://github.com/craigtrim/pystylometry/issues/28
426
+
427
+
428
+ @dataclass
429
+ class RepetitiveWord:
430
+ """A single word flagged as abnormally repetitive.
431
+
432
+ The repetition_score is the ratio of observed count to expected count
433
+ based on the word's frequency in the British National Corpus (BNC).
434
+ Higher scores indicate stronger overrepresentation.
435
+
436
+ Related GitHub Issue:
437
+ #28 - Verbal tics detection for slop analysis
438
+ https://github.com/craigtrim/pystylometry/issues/28
439
+
440
+ Attributes:
441
+ word: The flagged word (lowercased).
442
+ count: Observed count in the text.
443
+ expected_count: Expected count based on BNC relative frequency × text length.
444
+ 0.0 if word not found in BNC.
445
+ repetition_score: count / expected_count. float('inf') if expected_count is 0.
446
+ bnc_bucket: BNC frequency bucket (1-100, 1=most frequent). None if not in BNC.
447
+ chunk_counts: Per-chunk occurrence counts (for distribution analysis).
448
+ distribution_entropy: Shannon entropy of the word's chunk distribution.
449
+ Low entropy = suspiciously even spread (model tic).
450
+ High entropy = clustered usage (human writing about a specific scene).
451
+ distribution_variance: Variance of per-chunk counts.
452
+ """
453
+
454
+ word: str
455
+ count: int
456
+ expected_count: float
457
+ repetition_score: float
458
+ bnc_bucket: int | None
459
+ chunk_counts: list[int]
460
+ distribution_entropy: float
461
+ distribution_variance: float
462
+
463
+
464
+ @dataclass
465
+ class RepetitiveUnigramsResult:
466
+ """Result from repetitive unigram detection.
467
+
468
+ Identifies content words that appear far more frequently than expected
469
+ based on their frequency in the British National Corpus (BNC, ~100M tokens).
470
+ This is a key indicator of AI-generated "slop" where models exhibit verbal
471
+ tics — repeating certain words with suspicious regularity.
472
+
473
+ Related GitHub Issue:
474
+ #28 - Verbal tics detection for slop analysis
475
+ https://github.com/craigtrim/pystylometry/issues/28
476
+
477
+ The slop_score provides a single aggregate metric:
478
+ slop_score = flagged_words_per_10k × mean_repetition_score
479
+
480
+ Where:
481
+ - flagged_words_per_10k = count of flagged words / (total content words / 10000)
482
+ - mean_repetition_score = mean repetition_score across all flagged words
483
+
484
+ Higher slop_score = more likely AI-generated verbal tics.
485
+
486
+ References:
487
+ British National Corpus Consortium. (2007). The British National Corpus,
488
+ version 3 (BNC XML Edition). http://www.natcorp.ox.ac.uk/
489
+
490
+ Example:
491
+ >>> result = compute_repetitive_unigrams(text)
492
+ >>> for w in result.repetitive_words[:5]:
493
+ ... print(f"{w.word}: {w.count}x (expected {w.expected_count:.1f}, "
494
+ ... f"score {w.repetition_score:.1f})")
495
+ shimmered: 23x (expected 0.1, score 266.2)
496
+ >>> result.slop_score
497
+ 42.7
498
+ """
499
+
500
+ repetitive_words: list[RepetitiveWord] # Sorted by repetition_score descending
501
+ total_content_words: int
502
+ flagged_count: int # Number of words exceeding threshold
503
+ flagged_words_per_10k: float # flagged_count / (total_content_words / 10000)
504
+ mean_repetition_score: float # Mean score across flagged words
505
+ slop_score: float # Aggregate: flagged_words_per_10k × mean_repetition_score
506
+ total_content_words_dist: Distribution
507
+ chunk_size: int
508
+ chunk_count: int
509
+ metadata: dict[str, Any]
510
+
511
+
512
+ @dataclass
513
+ class RepetitiveNgram:
514
+ """A single n-gram flagged as abnormally repetitive.
515
+
516
+ Content n-grams (bigrams, trigrams, etc.) should rarely repeat verbatim
517
+ in natural writing. N-grams that repeat beyond a length-scaled threshold
518
+ are flagged.
519
+
520
+ Related GitHub Issue:
521
+ #28 - Verbal tics detection for slop analysis
522
+ https://github.com/craigtrim/pystylometry/issues/28
523
+
524
+ Attributes:
525
+ ngram: The flagged n-gram as a tuple of words.
526
+ count: Observed count in the text.
527
+ frequency_per_10k: Occurrences per 10,000 n-grams.
528
+ chunk_counts: Per-chunk occurrence counts.
529
+ distribution_entropy: Shannon entropy of the n-gram's chunk distribution.
530
+ distribution_variance: Variance of per-chunk counts.
531
+ """
532
+
533
+ ngram: tuple[str, ...]
534
+ count: int
535
+ frequency_per_10k: float
536
+ chunk_counts: list[int]
537
+ distribution_entropy: float
538
+ distribution_variance: float
539
+
540
+
541
+ @dataclass
542
+ class RepetitiveNgramsResult:
543
+ """Result from repetitive n-gram detection.
544
+
545
+ Detects bigrams, trigrams, or higher-order n-grams that repeat more than
546
+ expected within the text. No external corpus is required — content n-grams
547
+ should not repeat verbatim often in natural writing.
548
+
549
+ N-grams composed entirely of function words (e.g., "of the", "in a") are
550
+ excluded since their repetition is expected.
551
+
552
+ Related GitHub Issue:
553
+ #28 - Verbal tics detection for slop analysis
554
+ https://github.com/craigtrim/pystylometry/issues/28
555
+
556
+ Example:
557
+ >>> result = compute_repetitive_ngrams(text, n=2)
558
+ >>> for ng in result.repetitive_ngrams[:5]:
559
+ ... print(f"{' '.join(ng.ngram)}: {ng.count}x "
560
+ ... f"({ng.frequency_per_10k:.1f} per 10k)")
561
+ uncomfortable truth: 8x (1.6 per 10k)
562
+ """
563
+
564
+ repetitive_ngrams: list[RepetitiveNgram] # Sorted by count descending
565
+ n: int | tuple[int, ...] # N-gram order(s) analyzed
566
+ total_ngrams: int
567
+ flagged_count: int
568
+ flagged_per_10k: float # flagged_count / (total_ngrams / 10000)
569
+ total_ngrams_dist: Distribution
570
+ chunk_size: int
571
+ chunk_count: int
572
+ metadata: dict[str, Any]
573
+
574
+
373
575
  # ===== Readability Results =====
374
576
 
375
577