torsh-text 0.1.2

Natural language processing utilities for ToRSh deep learning framework
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
//! Result structures and data types for discourse coherence analysis
//!
//! This module contains all result structures, metrics, and supporting data types
//! used in discourse coherence analysis, providing comprehensive serialization
//! support and detailed analysis results.

use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};

use super::config::{
    CohesiveDeviceType, DiscourseMarkerType, RhetoricalRelationType, TransitionQuality,
};

/// Comprehensive result of discourse coherence analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiscourseCoherenceResult {
    /// Overall discourse coherence score (0.0 to 1.0)
    pub overall_coherence_score: f64,
    /// Discourse marker coherence contribution
    pub marker_coherence_score: f64,
    /// Rhetorical structure coherence contribution
    pub rhetorical_structure_score: f64,
    /// Cohesion quality score
    pub cohesion_score: f64,
    /// Average transition quality scores
    pub transition_scores: Vec<f64>,
    /// Identified discourse markers
    pub discourse_markers: Vec<DiscourseMarker>,
    /// Identified rhetorical relations
    pub rhetorical_relations: HashMap<String, usize>,
    /// Detailed metrics (optional for comprehensive analysis)
    pub detailed_metrics: Option<DetailedDiscourseMetrics>,
}

/// Detailed metrics for comprehensive discourse analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DetailedDiscourseMetrics {
    /// Discourse marker analysis details
    pub marker_analysis: Option<DiscourseMarkerAnalysis>,
    /// Rhetorical structure analysis details
    pub rhetorical_analysis: Option<RhetoricalStructureAnalysis>,
    /// Cohesion analysis details
    pub cohesion_analysis: Option<CohesionAnalysis>,
    /// Transition analysis details
    pub transition_analysis: Option<TransitionAnalysis>,
    /// Information structure analysis
    pub information_structure: Option<InformationStructureMetrics>,
    /// Advanced analysis results
    pub advanced_analysis: Option<AdvancedDiscourseAnalysis>,
}

/// Individual discourse marker with context and analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiscourseMarker {
    /// Type of discourse marker
    pub marker_type: DiscourseMarkerType,
    /// Text content of the marker
    pub text: String,
    /// Position in original text
    pub position: (usize, usize),
    /// Sentence index
    pub sentence_index: usize,
    /// Word index within sentence
    pub word_index: usize,
    /// Context analysis
    pub context: ContextAnalysis,
    /// Marker confidence score
    pub confidence: f64,
    /// Rhetorical strength
    pub rhetorical_strength: f64,
    /// Scope of influence (number of sentences affected)
    pub scope: usize,
    /// Syntactic position information
    pub syntactic_position: SyntacticPosition,
}

/// Context analysis for discourse markers
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextAnalysis {
    /// Preceding context words
    pub preceding_context: Vec<String>,
    /// Following context words
    pub following_context: Vec<String>,
    /// Semantic coherence with preceding context
    pub semantic_coherence_preceding: f64,
    /// Semantic coherence with following context
    pub semantic_coherence_following: f64,
    /// Pragmatic appropriateness score
    pub pragmatic_appropriateness: f64,
}

/// Syntactic position information for markers
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SyntacticPosition {
    /// Position within sentence (beginning, middle, end)
    pub sentence_position: String,
    /// Clause boundary information
    pub clause_boundary: bool,
    /// Part of speech tag
    pub pos_tag: String,
    /// Dependency relation
    pub dependency_relation: String,
}

/// Detailed discourse marker analysis results
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiscourseMarkerAnalysis {
    /// Total marker count
    pub total_markers: usize,
    /// Marker density per 100 words
    pub marker_density: f64,
    /// Distribution by marker type
    pub type_distribution: HashMap<DiscourseMarkerType, usize>,
    /// Average confidence score
    pub average_confidence: f64,
    /// Marker effectiveness score
    pub effectiveness_score: f64,
    /// Context integration score
    pub context_integration: f64,
    /// Multiword marker statistics
    pub multiword_statistics: MultiwordMarkerStats,
}

/// Statistics for multiword discourse markers
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MultiwordMarkerStats {
    /// Count of multiword markers
    pub multiword_count: usize,
    /// Average length of multiword markers
    pub average_length: f64,
    /// Most common multiword patterns
    pub common_patterns: Vec<(String, usize)>,
}

/// Rhetorical structure analysis results
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RhetoricalStructureAnalysis {
    /// Identified rhetorical relations
    pub relations: HashMap<RhetoricalRelationType, usize>,
    /// Relation distribution score
    pub relation_distribution_score: f64,
    /// Structural complexity measure
    pub structural_complexity: f64,
    /// Discourse tree (if built)
    pub discourse_tree: Option<DiscourseTree>,
    /// Nucleus-satellite analysis
    pub nucleus_satellite_analysis: Option<NucleusSatelliteAnalysis>,
    /// Relation confidence scores
    pub relation_confidences: HashMap<RhetoricalRelationType, f64>,
}

/// Discourse tree representation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiscourseTree {
    /// Root node of the tree
    pub root: DiscourseNode,
    /// Tree depth
    pub depth: usize,
    /// Node count
    pub node_count: usize,
    /// Balance score
    pub balance_score: f64,
    /// Tree complexity measure
    pub complexity_score: f64,
}

/// Individual discourse tree node
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiscourseNode {
    /// Node identifier
    pub node_id: usize,
    /// Rhetorical relation type
    pub relation_type: RhetoricalRelationType,
    /// Nucleus or satellite designation
    pub nuclearity: String,
    /// Text span covered by this node
    pub text_span: (usize, usize),
    /// Child nodes
    pub children: Vec<DiscourseNode>,
    /// Confidence score for this relation
    pub confidence: f64,
    /// Salience score
    pub salience: f64,
}

/// Analysis of nucleus-satellite structures
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NucleusSatelliteAnalysis {
    /// Nucleus identification accuracy
    pub nucleus_accuracy: f64,
    /// Satellite attachment patterns
    pub satellite_patterns: HashMap<String, usize>,
    /// Nuclear chain analysis
    pub nuclear_chains: Vec<NuclearChain>,
    /// Embedding depth statistics
    pub embedding_statistics: EmbeddingStats,
}

/// Representation of a nuclear chain in discourse
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NuclearChain {
    /// Chain identifier
    pub chain_id: usize,
    /// Nuclear elements in order
    pub nuclear_elements: Vec<usize>,
    /// Attached satellites
    pub satellites: Vec<usize>,
    /// Chain coherence score
    pub coherence_score: f64,
}

/// Statistics about discourse structure embedding
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmbeddingStats {
    /// Maximum embedding depth
    pub max_depth: usize,
    /// Average embedding depth
    pub average_depth: f64,
    /// Depth distribution
    pub depth_distribution: HashMap<usize, usize>,
}

/// Cohesion analysis results
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CohesionAnalysis {
    /// Overall cohesion score
    pub overall_cohesion_score: f64,
    /// Identified cohesive devices
    pub cohesive_devices: Vec<CohesiveDevice>,
    /// Reference cohesion metrics
    pub reference_cohesion: ReferenceCohesionMetrics,
    /// Lexical cohesion metrics
    pub lexical_cohesion: LexicalCohesionMetrics,
    /// Conjunctive cohesion metrics
    pub conjunctive_cohesion: ConjunctiveCohesionMetrics,
    /// Temporal coherence metrics
    pub temporal_coherence: TemporalCoherenceMetrics,
}

/// Individual cohesive device analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CohesiveDevice {
    /// Type of cohesive device
    pub device_type: CohesiveDeviceType,
    /// Text elements involved in cohesion
    pub elements: Vec<String>,
    /// Positions of elements in text
    pub positions: Vec<(usize, usize)>,
    /// Cohesive strength score
    pub strength: f64,
    /// Local coherence contribution
    pub local_contribution: f64,
    /// Global coherence contribution
    pub global_contribution: f64,
    /// Resolution confidence
    pub resolution_confidence: f64,
    /// Distance between cohesive elements
    pub distance: usize,
}

/// Reference cohesion analysis metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReferenceCohesionMetrics {
    /// Total reference links
    pub total_references: usize,
    /// Reference density per sentence
    pub reference_density: f64,
    /// Successful reference resolution rate
    pub resolution_success_rate: f64,
    /// Average reference distance
    pub average_reference_distance: f64,
    /// Ambiguous references count
    pub ambiguous_references: usize,
    /// Reference complexity score
    pub complexity_score: f64,
    /// Chain analysis
    pub reference_chains: Vec<ReferenceChain>,
}

/// Analysis of reference chains in text
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReferenceChain {
    /// Chain identifier
    pub chain_id: usize,
    /// Referenced entity or concept
    pub entity: String,
    /// Referring expressions in order
    pub referring_expressions: Vec<String>,
    /// Positions of expressions
    pub positions: Vec<(usize, usize)>,
    /// Chain coherence score
    pub coherence_score: f64,
    /// Chain completeness score
    pub completeness_score: f64,
}

/// Lexical cohesion analysis metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LexicalCohesionMetrics {
    /// Lexical tie count
    pub lexical_ties: usize,
    /// Lexical density score
    pub lexical_density: f64,
    /// Repetition analysis
    pub repetition_analysis: RepetitionAnalysis,
    /// Synonym network metrics
    pub synonym_networks: SynonymNetworkMetrics,
    /// Semantic field coherence
    pub semantic_field_coherence: f64,
    /// Lexical sophistication score
    pub sophistication_score: f64,
}

/// Analysis of lexical repetition patterns
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RepetitionAnalysis {
    /// Exact repetitions count
    pub exact_repetitions: usize,
    /// Morphological variations count
    pub morphological_variations: usize,
    /// Most repeated terms
    pub frequent_terms: Vec<(String, usize)>,
    /// Repetition distribution score
    pub distribution_score: f64,
}

/// Metrics for synonym networks in text
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SynonymNetworkMetrics {
    /// Number of synonym clusters
    pub cluster_count: usize,
    /// Average cluster size
    pub average_cluster_size: f64,
    /// Network connectivity score
    pub connectivity_score: f64,
    /// Largest clusters
    pub major_clusters: Vec<SynonymCluster>,
}

/// Individual synonym cluster
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SynonymCluster {
    /// Cluster identifier
    pub cluster_id: usize,
    /// Words in the cluster
    pub words: Vec<String>,
    /// Cluster coherence score
    pub coherence_score: f64,
    /// Semantic similarity threshold
    pub similarity_threshold: f64,
}

/// Conjunctive cohesion analysis metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConjunctiveCohesionMetrics {
    /// Conjunction count by type
    pub conjunction_counts: HashMap<String, usize>,
    /// Conjunctive density
    pub conjunctive_density: f64,
    /// Logical flow score
    pub logical_flow_score: f64,
    /// Conjunction effectiveness
    pub conjunction_effectiveness: f64,
    /// Complex conjunction analysis
    pub complex_conjunctions: Vec<ComplexConjunction>,
}

/// Analysis of complex conjunctive structures
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComplexConjunction {
    /// Conjunction text
    pub text: String,
    /// Logical relation expressed
    pub logical_relation: String,
    /// Position in text
    pub position: (usize, usize),
    /// Effectiveness score
    pub effectiveness: f64,
    /// Scope of conjunction
    pub scope: usize,
}

/// Temporal coherence analysis metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TemporalCoherenceMetrics {
    /// Temporal marker frequency
    pub temporal_marker_frequency: f64,
    /// Temporal sequence coherence
    pub sequence_coherence: f64,
    /// Temporal anchoring score
    pub anchoring_score: f64,
    /// Timeline consistency
    pub timeline_consistency: f64,
    /// Temporal disruptions count
    pub temporal_disruptions: usize,
    /// Temporal reference chains
    pub temporal_chains: Vec<TemporalChain>,
}

/// Analysis of temporal reference chains
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TemporalChain {
    /// Chain identifier
    pub chain_id: usize,
    /// Temporal expressions
    pub expressions: Vec<String>,
    /// Temporal ordering
    pub ordering: Vec<usize>,
    /// Consistency score
    pub consistency_score: f64,
}

/// Transition analysis results
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransitionAnalysis {
    /// Individual transition quality scores
    pub transition_quality_scores: Vec<TransitionQualityScore>,
    /// Overall transition quality
    pub overall_transition_quality: f64,
    /// Lexical overlap statistics
    pub lexical_overlap_stats: LexicalOverlapStats,
    /// Semantic continuity metrics
    pub semantic_continuity: SemanticContinuityMetrics,
    /// Structural continuity analysis
    pub structural_continuity: StructuralContinuityMetrics,
}

/// Quality score for individual transitions
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransitionQualityScore {
    /// Transition position (between sentences i and i+1)
    pub position: (usize, usize),
    /// Quality classification
    pub quality: TransitionQuality,
    /// Numerical quality score
    pub score: f64,
    /// Contributing factors
    pub factors: TransitionFactors,
}

/// Factors contributing to transition quality
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransitionFactors {
    /// Lexical overlap contribution
    pub lexical_overlap: f64,
    /// Semantic continuity contribution
    pub semantic_continuity: f64,
    /// Structural continuity contribution
    pub structural_continuity: f64,
    /// Transition marker presence
    pub marker_presence: f64,
}

/// Statistics for lexical overlap between sentences
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LexicalOverlapStats {
    /// Average lexical overlap score
    pub average_overlap: f64,
    /// Distribution of overlap scores
    pub overlap_distribution: HashMap<String, usize>,
    /// Content word vs function word overlap
    pub content_vs_function: ContentFunctionOverlap,
}

/// Comparison of content vs function word overlap
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContentFunctionOverlap {
    /// Content word overlap average
    pub content_word_overlap: f64,
    /// Function word overlap average
    pub function_word_overlap: f64,
    /// Ratio of content to function overlap
    pub content_function_ratio: f64,
}

/// Semantic continuity analysis metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SemanticContinuityMetrics {
    /// Average semantic similarity scores
    pub average_semantic_similarity: f64,
    /// Semantic coherence distribution
    pub coherence_distribution: Vec<f64>,
    /// Topic continuity analysis
    pub topic_continuity: TopicContinuityMetrics,
    /// Conceptual overlap metrics
    pub conceptual_overlap: ConceptualOverlapMetrics,
}

/// Analysis of topic continuity across sentences
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TopicContinuityMetrics {
    /// Topic shift frequency
    pub topic_shift_frequency: f64,
    /// Average topic coherence
    pub average_topic_coherence: f64,
    /// Major topic transitions
    pub major_transitions: Vec<TopicTransition>,
}

/// Individual topic transition analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TopicTransition {
    /// Position of transition
    pub position: usize,
    /// Source topic indicators
    pub source_topic: Vec<String>,
    /// Target topic indicators
    pub target_topic: Vec<String>,
    /// Transition smoothness score
    pub smoothness: f64,
}

/// Analysis of conceptual overlap between sentences
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConceptualOverlapMetrics {
    /// Concept extraction statistics
    pub concept_stats: ConceptStats,
    /// Conceptual similarity network
    pub similarity_network: ConceptualSimilarityNetwork,
    /// Abstract concept tracking
    pub abstract_concepts: Vec<AbstractConcept>,
}

/// Statistics about concept extraction
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConceptStats {
    /// Total concepts identified
    pub total_concepts: usize,
    /// Average concepts per sentence
    pub concepts_per_sentence: f64,
    /// Concept diversity score
    pub diversity_score: f64,
}

/// Network of conceptual similarities
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConceptualSimilarityNetwork {
    /// Network nodes (concepts)
    pub nodes: Vec<String>,
    /// Network edges (similarities)
    pub edges: Vec<(usize, usize, f64)>,
    /// Network density
    pub density: f64,
    /// Clustering coefficient
    pub clustering_coefficient: f64,
}

/// Abstract concept tracking across discourse
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AbstractConcept {
    /// Concept identifier
    pub concept_id: String,
    /// Manifestations in text
    pub manifestations: Vec<String>,
    /// Positions of manifestations
    pub positions: Vec<usize>,
    /// Conceptual stability score
    pub stability_score: f64,
}

/// Structural continuity analysis metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StructuralContinuityMetrics {
    /// Syntactic pattern continuity
    pub syntactic_continuity: f64,
    /// Sentence length variation
    pub length_variation: SentenceLengthVariation,
    /// Structural parallelism
    pub parallelism_analysis: ParallelismAnalysis,
}

/// Analysis of sentence length variation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SentenceLengthVariation {
    /// Average sentence length
    pub average_length: f64,
    /// Length standard deviation
    pub length_std_dev: f64,
    /// Length variation score
    pub variation_score: f64,
    /// Length distribution
    pub length_distribution: HashMap<String, usize>,
}

/// Analysis of structural parallelism
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParallelismAnalysis {
    /// Parallel structure count
    pub parallel_structures: usize,
    /// Parallelism strength score
    pub parallelism_strength: f64,
    /// Identified parallel patterns
    pub parallel_patterns: Vec<ParallelPattern>,
}

/// Individual parallel structure pattern
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParallelPattern {
    /// Pattern identifier
    pub pattern_id: usize,
    /// Parallel elements
    pub elements: Vec<String>,
    /// Element positions
    pub positions: Vec<usize>,
    /// Pattern strength
    pub strength: f64,
}

/// Information structure analysis metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InformationStructureMetrics {
    /// Given-new information balance
    pub given_new_balance: f64,
    /// Topic-focus articulation score
    pub topic_focus_articulation: f64,
    /// Information packaging score
    pub information_packaging: f64,
    /// Thematic progression pattern
    pub thematic_progression: String,
    /// Information density metrics
    pub information_density: f64,
    /// Theme analysis
    pub theme_analysis: ThemeAnalysis,
    /// Focus tracking
    pub focus_tracking: FocusTracking,
}

/// Analysis of thematic elements
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThemeAnalysis {
    /// Identified themes
    pub themes: Vec<Theme>,
    /// Theme continuity score
    pub continuity_score: f64,
    /// Theme development patterns
    pub development_patterns: Vec<String>,
}

/// Individual theme in discourse
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Theme {
    /// Theme identifier
    pub theme_id: String,
    /// Theme manifestations
    pub manifestations: Vec<String>,
    /// Positions in text
    pub positions: Vec<usize>,
    /// Theme prominence score
    pub prominence: f64,
}

/// Focus tracking across discourse
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FocusTracking {
    /// Focus shifts count
    pub focus_shifts: usize,
    /// Focus continuity score
    pub continuity_score: f64,
    /// Major focus elements
    pub major_foci: Vec<FocusElement>,
}

/// Individual focus element
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FocusElement {
    /// Focus content
    pub content: String,
    /// Position in text
    pub position: usize,
    /// Focus strength
    pub strength: f64,
}

/// Advanced discourse analysis results
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AdvancedDiscourseAnalysis {
    /// Discourse tree structure (if built)
    pub discourse_tree: Option<DiscourseTree>,
    /// Coherence relation network
    pub coherence_network: CoherenceNetwork,
    /// Information-theoretic measures
    pub information_measures: DiscourseInformationMeasures,
    /// Cognitive processing measures
    pub cognitive_measures: CognitiveMeasures,
    /// Discourse genre analysis
    pub genre_analysis: GenreAnalysis,
}

/// Network representation of coherence relations
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CoherenceNetwork {
    /// Network nodes (discourse units)
    pub nodes: Vec<CoherenceNode>,
    /// Network edges (coherence relations)
    pub edges: Vec<CoherenceEdge>,
    /// Network density measure
    pub density: f64,
    /// Network connectivity score
    pub connectivity: f64,
    /// Central nodes analysis
    pub central_nodes: Vec<usize>,
}

/// Node in coherence network
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CoherenceNode {
    /// Node identifier
    pub node_id: usize,
    /// Text content
    pub content: String,
    /// Centrality measures
    pub centrality: NodeCentrality,
    /// Node importance score
    pub importance: f64,
}

/// Centrality measures for network nodes
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeCentrality {
    /// Degree centrality
    pub degree: f64,
    /// Betweenness centrality
    pub betweenness: f64,
    /// Closeness centrality
    pub closeness: f64,
    /// Eigenvector centrality
    pub eigenvector: f64,
}

/// Edge in coherence network
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CoherenceEdge {
    /// Source node
    pub source: usize,
    /// Target node
    pub target: usize,
    /// Relation type
    pub relation_type: RhetoricalRelationType,
    /// Edge weight (strength)
    pub weight: f64,
    /// Confidence score
    pub confidence: f64,
}

/// Information-theoretic measures for discourse
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiscourseInformationMeasures {
    /// Entropy measures
    pub entropy: EntropyMeasures,
    /// Information flow metrics
    pub information_flow: InformationFlowMetrics,
    /// Redundancy analysis
    pub redundancy: RedundancyAnalysis,
    /// Compression analysis
    pub compression: CompressionAnalysis,
}

/// Entropy-based information measures
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EntropyMeasures {
    /// Lexical entropy
    pub lexical_entropy: f64,
    /// Syntactic entropy
    pub syntactic_entropy: f64,
    /// Semantic entropy
    pub semantic_entropy: f64,
    /// Overall discourse entropy
    pub discourse_entropy: f64,
}

/// Information flow analysis metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InformationFlowMetrics {
    /// Information rate
    pub information_rate: f64,
    /// Flow consistency
    pub flow_consistency: f64,
    /// Information bottlenecks
    pub bottlenecks: Vec<InformationBottleneck>,
}

/// Information bottleneck in discourse
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InformationBottleneck {
    /// Position of bottleneck
    pub position: usize,
    /// Bottleneck severity
    pub severity: f64,
    /// Contributing factors
    pub factors: Vec<String>,
}

/// Redundancy analysis results
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RedundancyAnalysis {
    /// Overall redundancy score
    pub overall_redundancy: f64,
    /// Beneficial redundancy
    pub beneficial_redundancy: f64,
    /// Excessive redundancy
    pub excessive_redundancy: f64,
    /// Redundancy patterns
    pub patterns: Vec<RedundancyPattern>,
}

/// Individual redundancy pattern
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RedundancyPattern {
    /// Pattern type
    pub pattern_type: String,
    /// Instances of pattern
    pub instances: Vec<(usize, usize)>,
    /// Pattern strength
    pub strength: f64,
}

/// Text compression analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CompressionAnalysis {
    /// Compression ratio
    pub compression_ratio: f64,
    /// Information density
    pub information_density: f64,
    /// Compressibility score
    pub compressibility: f64,
}

/// Cognitive processing measures
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CognitiveMeasures {
    /// Processing load estimate
    pub processing_load: f64,
    /// Memory load estimate
    pub memory_load: f64,
    /// Attention tracking metrics
    pub attention_metrics: AttentionMetrics,
    /// Comprehension difficulty score
    pub comprehension_difficulty: f64,
    /// Cognitive accessibility score
    pub cognitive_accessibility: f64,
}

/// Attention-based discourse metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AttentionMetrics {
    /// Attention switching frequency
    pub attention_switches: usize,
    /// Focus maintenance score
    pub focus_maintenance: f64,
    /// Attention distribution
    pub attention_distribution: Vec<AttentionFocus>,
}

/// Individual attention focus point
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AttentionFocus {
    /// Position in text
    pub position: usize,
    /// Focus strength
    pub strength: f64,
    /// Duration estimate
    pub duration: f64,
}

/// Genre analysis results
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenreAnalysis {
    /// Predicted genre
    pub predicted_genre: String,
    /// Genre confidence score
    pub confidence: f64,
    /// Genre-specific features
    pub genre_features: GenreFeatures,
    /// Register analysis
    pub register_analysis: RegisterAnalysis,
}

/// Features characteristic of discourse genres
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenreFeatures {
    /// Argumentative features
    pub argumentative: ArgumentativeFeatures,
    /// Narrative features
    pub narrative: NarrativeFeatures,
    /// Expository features
    pub expository: ExpositoryFeatures,
    /// Descriptive features
    pub descriptive: DescriptiveFeatures,
}

/// Features of argumentative discourse
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArgumentativeFeatures {
    /// Claim-evidence patterns
    pub claim_evidence_patterns: usize,
    /// Logical connectors frequency
    pub logical_connectors: f64,
    /// Counter-argument presence
    pub counter_arguments: usize,
    /// Persuasive strength
    pub persuasive_strength: f64,
}

/// Features of narrative discourse
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NarrativeFeatures {
    /// Temporal progression markers
    pub temporal_markers: usize,
    /// Character reference frequency
    pub character_references: f64,
    /// Action verb density
    pub action_verb_density: f64,
    /// Narrative coherence score
    pub narrative_coherence: f64,
}

/// Features of expository discourse
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExpositoryFeatures {
    /// Definition patterns
    pub definition_patterns: usize,
    /// Classification markers
    pub classification_markers: usize,
    /// Explanation structures
    pub explanation_structures: usize,
    /// Technical vocabulary density
    pub technical_vocabulary: f64,
}

/// Features of descriptive discourse
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DescriptiveFeatures {
    /// Descriptive adjective density
    pub adjective_density: f64,
    /// Spatial markers frequency
    pub spatial_markers: f64,
    /// Sensory detail indicators
    pub sensory_details: usize,
    /// Descriptive vividness score
    pub vividness_score: f64,
}

/// Register analysis results
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisterAnalysis {
    /// Formality level
    pub formality_level: String,
    /// Formality score (0.0 = informal, 1.0 = very formal)
    pub formality_score: f64,
    /// Register features
    pub register_features: RegisterFeatures,
    /// Audience adaptation score
    pub audience_adaptation: f64,
}

/// Features indicating discourse register
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisterFeatures {
    /// Lexical sophistication
    pub lexical_sophistication: f64,
    /// Syntactic complexity
    pub syntactic_complexity: f64,
    /// Discourse marker formality
    pub marker_formality: f64,
    /// Technical language usage
    pub technical_usage: f64,
}