spell-exploder 0.1.0__py3-none-any.whl

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 (37) hide show
  1. spell_exploder/__init__.py +205 -0
  2. spell_exploder/_version.py +1 -0
  3. spell_exploder/analyzers/__init__.py +18 -0
  4. spell_exploder/analyzers/adaptive_evolution.py +453 -0
  5. spell_exploder/analyzers/complexity_index.py +224 -0
  6. spell_exploder/analyzers/keyword_erp.py +477 -0
  7. spell_exploder/analyzers/valence_model.py +523 -0
  8. spell_exploder/core/__init__.py +45 -0
  9. spell_exploder/core/compression.py +103 -0
  10. spell_exploder/core/entropy.py +203 -0
  11. spell_exploder/core/information.py +179 -0
  12. spell_exploder/core/nlp.py +107 -0
  13. spell_exploder/exceptions.py +25 -0
  14. spell_exploder/extractors/__init__.py +35 -0
  15. spell_exploder/extractors/action_frames.py +133 -0
  16. spell_exploder/extractors/noun_dependencies.py +96 -0
  17. spell_exploder/extractors/sentence_parser.py +168 -0
  18. spell_exploder/graphs/__init__.py +0 -0
  19. spell_exploder/io/__init__.py +14 -0
  20. spell_exploder/io/exporters.py +94 -0
  21. spell_exploder/io/readers.py +117 -0
  22. spell_exploder/results/__init__.py +44 -0
  23. spell_exploder/results/complexity.py +111 -0
  24. spell_exploder/results/evolution.py +136 -0
  25. spell_exploder/results/keyword.py +139 -0
  26. spell_exploder/results/valence.py +134 -0
  27. spell_exploder/utils/__init__.py +11 -0
  28. spell_exploder/utils/imports.py +48 -0
  29. spell_exploder/utils/smoothing.py +42 -0
  30. spell_exploder/utils/statistics.py +54 -0
  31. spell_exploder/visualization/__init__.py +27 -0
  32. spell_exploder/visualization/plots.py +562 -0
  33. spell_exploder-0.1.0.dist-info/METADATA +221 -0
  34. spell_exploder-0.1.0.dist-info/RECORD +37 -0
  35. spell_exploder-0.1.0.dist-info/WHEEL +5 -0
  36. spell_exploder-0.1.0.dist-info/licenses/LICENSE +21 -0
  37. spell_exploder-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,221 @@
1
+ Metadata-Version: 2.4
2
+ Name: spell-exploder
3
+ Version: 0.1.0
4
+ Summary: Analyze natural language through complex systems science, information theory, and evolutionary game theory.
5
+ Author: Spellcaster Contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/inc-research/spell-exploder
8
+ Project-URL: Documentation, https://github.com/inc-research/spell-exploder#readme
9
+ Project-URL: Repository, https://github.com/inc-research/spell-exploder
10
+ Keywords: nlp,information-theory,complex-systems,text-analysis,evolutionary-game-theory,linguistics
11
+ Classifier: Development Status :: 3 - Alpha
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.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
20
+ Classifier: Topic :: Text Processing :: Linguistic
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: numpy>=1.23
25
+ Requires-Dist: pandas>=1.5
26
+ Requires-Dist: spacy>=3.4
27
+ Requires-Dist: scipy>=1.9
28
+ Requires-Dist: python-Levenshtein>=0.20
29
+ Provides-Extra: viz
30
+ Requires-Dist: matplotlib>=3.5; extra == "viz"
31
+ Requires-Dist: seaborn>=0.12; extra == "viz"
32
+ Provides-Extra: graphs
33
+ Requires-Dist: networkx>=3.0; extra == "graphs"
34
+ Provides-Extra: ml
35
+ Requires-Dist: sentence-transformers>=2.0; extra == "ml"
36
+ Requires-Dist: scikit-learn>=1.0; extra == "ml"
37
+ Provides-Extra: all
38
+ Requires-Dist: spell-exploder[graphs,ml,viz]; extra == "all"
39
+ Provides-Extra: dev
40
+ Requires-Dist: pytest>=7.0; extra == "dev"
41
+ Requires-Dist: spell-exploder[all]; extra == "dev"
42
+ Dynamic: license-file
43
+
44
+ # Spell Exploder
45
+
46
+ Analyze natural language text through complex systems science, information theory, information-theoretic physics analogues, and evolutionary game theory.
47
+
48
+ Spell Exploder provides four complementary analyzers that reveal the hidden structural, informational, and evolutionary properties of text — from sentence-level compression dynamics to document-scale syntactic evolution.
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ pip install spell-exploder
54
+ ```
55
+
56
+ **Required dependencies** (installed automatically): `numpy`, `pandas`, `spacy`, `scipy`, `python-Levenshtein`
57
+
58
+ **Optional dependencies:**
59
+
60
+ ```bash
61
+ # Sentence embeddings for APE hybrid clustering
62
+ pip install spell-exploder[ml] # sentence-transformers, scikit-learn
63
+
64
+ # Visualization (convenience plotting)
65
+ pip install spell-exploder[viz] # matplotlib, seaborn
66
+
67
+ # Everything
68
+ pip install spell-exploder[all]
69
+ ```
70
+
71
+ **spaCy model** (required):
72
+
73
+ ```bash
74
+ python -m spacy download en_core_web_sm
75
+ ```
76
+
77
+ ## Quick Start
78
+
79
+ ### One-liner API
80
+
81
+ ```python
82
+ import spell_exploder
83
+
84
+ # Complexity flow analysis (LCX)
85
+ result = spell_exploder.analyze_complexity("essay_a.txt", "essay_b.txt")
86
+ df = result.to_dataframe()
87
+
88
+ # Valence model (LCVM) — entropy, MI, action frames, multiscale collapse
89
+ result = spell_exploder.analyze_valence("essay_a.txt", "essay_b.txt")
90
+ profile = spell_exploder.ValenceModelAnalyzer().build_complexity_profile(result)
91
+
92
+ # Adaptive evolution (APE) — syntactic species dynamics
93
+ result = spell_exploder.analyze_evolution("early_draft.txt", "final_draft.txt")
94
+ print(result.to_dataframe())
95
+
96
+ # Keyword structural coherence (KEPM)
97
+ result = spell_exploder.analyze_keywords(
98
+ "essay.txt",
99
+ keywords=["information", "network"],
100
+ )
101
+ ```
102
+
103
+ ### Full-control API
104
+
105
+ ```python
106
+ from spell_exploder.analyzers import TextComplexityAnalyzer
107
+
108
+ analyzer = TextComplexityAnalyzer()
109
+ result = analyzer.compare(
110
+ ["Human text here.", "AI text here."],
111
+ labels=["Human", "AI"],
112
+ from_files=False,
113
+ )
114
+ for flow in result.flows:
115
+ print(f"{flow.label}: {len(flow.sentences)} sentences")
116
+ print(f" Final k_hist: {flow.sentences[-1].k_hist}")
117
+ ```
118
+
119
+ ## Analyzers
120
+
121
+ ### TextComplexityAnalyzer (LCX)
122
+
123
+ Sentence-by-sentence complexity flow via compression (zlib), Levenshtein volatility, and synergy ratios.
124
+
125
+ ```python
126
+ from spell_exploder.analyzers import TextComplexityAnalyzer
127
+
128
+ lcx = TextComplexityAnalyzer()
129
+ result = lcx.compare(["file_a.txt", "file_b.txt"])
130
+ ```
131
+
132
+ **Key metrics:** cumulative compressed size (`k_hist`), edit distance (`volatility`), volatility/marginal-info ratio (`synergy`)
133
+
134
+ ### ValenceModelAnalyzer (LCVM)
135
+
136
+ The most comprehensive analyzer — ~30 metrics per document across five dimensions:
137
+
138
+ | Dimension | Metrics |
139
+ |-----------|---------|
140
+ | **Variation** | Shannon entropy of token distributions |
141
+ | **Redundancy** | Multiscale entropy-collapse curves |
142
+ | **Organisation** | MI(Verb; Subject), MI(Verb; Object), coupling strength |
143
+ | **Repertoire** | Action-frame density, verb diversity |
144
+ | **Semantic breadth** | Schema-keyword concentration, valence entropy |
145
+
146
+ ```python
147
+ from spell_exploder.analyzers import ValenceModelAnalyzer
148
+
149
+ vm = ValenceModelAnalyzer()
150
+ result = vm.analyze(["essay_a.txt", "essay_b.txt"])
151
+ profile = vm.build_complexity_profile(result)
152
+ print(vm.profile_for_print(profile))
153
+ ```
154
+
155
+ ### AdaptiveEvolutionAnalyzer (APE)
156
+
157
+ Treats syntactic structures as biological species competing for "cognitive market share" across document revisions.
158
+
159
+ ```python
160
+ from spell_exploder.analyzers import AdaptiveEvolutionAnalyzer
161
+
162
+ ape = AdaptiveEvolutionAnalyzer(use_embeddings=False) # NCD-only mode
163
+ result = ape.analyze(["draft_v1.txt", "draft_v2.txt"])
164
+
165
+ for species in result.species[:5]:
166
+ print(f" Group {species.cluster_id}: {species.status.value} "
167
+ f"(Δ={species.delta:+.3f})")
168
+ ```
169
+
170
+ ### KeywordERPAnalyzer (KEPM)
171
+
172
+ Analyses structural coherence of keyword usage through POS co-occurrence spectral entropy and NCD-based structural similarity.
173
+
174
+ ```python
175
+ from spell_exploder.analyzers import KeywordERPAnalyzer
176
+
177
+ kw = KeywordERPAnalyzer(keywords=["information", "network"])
178
+ result = kw.analyze(["essay.txt"])
179
+ df = result.to_dataframe()
180
+ ```
181
+
182
+ ## Export
183
+
184
+ All results can be exported to CSV or JSON:
185
+
186
+ ```python
187
+ from spell_exploder.io import export_csv, export_json
188
+
189
+ export_csv(result, "output.csv")
190
+ export_json(result, "output.json")
191
+ ```
192
+
193
+ ## Result Objects
194
+
195
+ Every analyzer returns a structured result with:
196
+
197
+ - **`.to_dataframe()`** — flat pandas DataFrame for analysis
198
+ - **Direct attribute access** — full nested data (e.g., `result.posts[0].schema_valence_entropy`)
199
+ - **NumPy array properties** — e.g., `flow.k_hist_array`, `flow.volatility_array`
200
+
201
+ ## Architecture
202
+
203
+ ```
204
+ spell_exploder/
205
+ ├── analyzers/ # 4 analyzer classes (LCX, LCVM, APE, KEPM)
206
+ ├── core/ # Shared math: entropy, compression, MI, JS divergence
207
+ ├── extractors/ # NLP extraction: action frames, noun deps, sentences
208
+ ├── results/ # Structured dataclass results with .to_dataframe()
209
+ ├── io/ # Text loading and result export (CSV, JSON)
210
+ ├── utils/ # Smoothing, statistics, lazy imports
211
+ └── visualization/ # Optional convenience plotting (requires matplotlib)
212
+ ```
213
+
214
+ ## Requirements
215
+
216
+ - Python ≥ 3.10
217
+ - spaCy with `en_core_web_sm` (or another English model)
218
+
219
+ ## License
220
+
221
+ MIT
@@ -0,0 +1,37 @@
1
+ spell_exploder/__init__.py,sha256=WOCQu_4AN8CX2iuaDR9FSZ1MbbxMnBBkWE8zeUMnO5o,5715
2
+ spell_exploder/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
3
+ spell_exploder/exceptions.py,sha256=KdnM8EGaCgYfyaadxypRgxHT1Lqa8BW8_vlFFFzbc1s,767
4
+ spell_exploder/analyzers/__init__.py,sha256=FfF84oUzvhQKbbBm5wMr_jR_ketWLAwoHRhqPIPH4VE,569
5
+ spell_exploder/analyzers/adaptive_evolution.py,sha256=XuDyioJTXkaXQsmtNNGG_XhzOsvi25e7sBbN2a1Rjzw,15575
6
+ spell_exploder/analyzers/complexity_index.py,sha256=nQhHxDh_hm7dRvCm0CD0-gFP7ozCZIsmH282B270plI,7286
7
+ spell_exploder/analyzers/keyword_erp.py,sha256=4br3nOCSX_m26-G0HsdMtbjegxJxq0Ih-6teJgEF6W8,16292
8
+ spell_exploder/analyzers/valence_model.py,sha256=VU51mbFp5WEmPYozD-gikdfVcEGxyLuJgJlgsyxucyA,19221
9
+ spell_exploder/core/__init__.py,sha256=Y62KSe91xleJuM3_KSjmy9qiYgyQ4cqYDPeWaw0JUHg,1097
10
+ spell_exploder/core/compression.py,sha256=40GLBreGzBmxe09Yt9Jep3ZjZsbHL_qewXWlX12dbeI,2670
11
+ spell_exploder/core/entropy.py,sha256=HjcaowHhBCqX5CgcZ5udDgsnmM0iNfmo-kq71kBzxMU,5726
12
+ spell_exploder/core/information.py,sha256=AWLb9crr7WqOxT99YSbr2kB-DqM3KsH9SmfvJUaqVYA,4734
13
+ spell_exploder/core/nlp.py,sha256=nFhUIAp0KQjtZdWy6BtSrZtxaKv_bd-c9rXdGCxoZ0U,3099
14
+ spell_exploder/extractors/__init__.py,sha256=xk8VAU0ZFaiJTJYYO8JfGHcmFP8ZRwpSPzy9L86Lfqc,895
15
+ spell_exploder/extractors/action_frames.py,sha256=hotGPsH8DkKKS8kbEhsYETXr0datCpbSBDPd6NBEjqg,3583
16
+ spell_exploder/extractors/noun_dependencies.py,sha256=zc4QxTTNYclb_YfmzMbAjWKn_XX55RzW5wVHk8MPR8w,3120
17
+ spell_exploder/extractors/sentence_parser.py,sha256=FJXy9Wnvx8bYYRbYAuJgThs2z4MEvU3j7wNDnXcpgAA,5146
18
+ spell_exploder/graphs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ spell_exploder/io/__init__.py,sha256=gTSxDn4x1Fv9n1bHl7dlJodTsyuIwW4Qrb_4NeUofpc,319
20
+ spell_exploder/io/exporters.py,sha256=aq8rFjLrRUOwRO2UwcJxm_J7epRPzkmjZtI2lwbo3qU,2242
21
+ spell_exploder/io/readers.py,sha256=Kf5wdRh1gceTr1MGNZUiMaimoV2ICRknsUKV60CLANU,3072
22
+ spell_exploder/results/__init__.py,sha256=wxbv6xyZnGG_nKWaBM9-BFuideGZpPIPuggM4e9pvX4,1031
23
+ spell_exploder/results/complexity.py,sha256=33-Sxd8XMQomSE7rpbMZCpUoWzkTvBoQbAS4jOrqHck,3344
24
+ spell_exploder/results/evolution.py,sha256=q5XU6mHZ7c85yjfIpwUMfoAy15Xpi4Q_zQkuMzceP2o,4312
25
+ spell_exploder/results/keyword.py,sha256=fBJGPzmT2UyolF42fiSzbLKh6crTLmdyArVHggxZLdo,4334
26
+ spell_exploder/results/valence.py,sha256=UOEzUH0IuqwlMLtvVJ25BbdWEXs1bgwiG0G27uC921Q,5382
27
+ spell_exploder/utils/__init__.py,sha256=BoR6-2S1Y149atqZLXkFr5vl1b93O-xPE14qTvxh_Lk,270
28
+ spell_exploder/utils/imports.py,sha256=3E0K1oHhuPeTVbidgCcMVLX_cFJVRZnTD50MfxYw7H8,1415
29
+ spell_exploder/utils/smoothing.py,sha256=oOvc_jmWNS8M40fiCxBDC8U3MGvBVOwk1VwecGC9QT4,1107
30
+ spell_exploder/utils/statistics.py,sha256=MRbPqmEr3q43B87x8B4fPJD2eoxvqFELd7-vP8YZppU,1574
31
+ spell_exploder/visualization/__init__.py,sha256=r2aZme8AHBzFj_kh6LZnumXCrYMo_ky-QhWZjy-xacU,655
32
+ spell_exploder/visualization/plots.py,sha256=Wprpy6gL0CdmKNGGnnoDvSwA3R3tr7UEnx89zJW9ZsQ,16535
33
+ spell_exploder-0.1.0.dist-info/licenses/LICENSE,sha256=Bl-aIarlo_QhU4Lc2j8uW9IJFI13--oTYdgIhXkTq44,1081
34
+ spell_exploder-0.1.0.dist-info/METADATA,sha256=V68GEZb6Z_SxjCXs07YCZzmDMbK3ThRT6K0eNzNwa-4,7156
35
+ spell_exploder-0.1.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
36
+ spell_exploder-0.1.0.dist-info/top_level.txt,sha256=f6X_qVJNZ98HxlVtdsxcWmS3xNkEoE9gZyTk0uXOZGk,15
37
+ spell_exploder-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Spellcaster Contributors
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 @@
1
+ spell_exploder