compare_with_js/
compare_with_js.rs

1//! Example that demonstrates the Rust library producing similar results to the JavaScript implementation.
2//!
3//! This example creates languages that mirror the cultures from the HTML demo:
4//! - Melodic Coastal Folk
5//! - Mountain Warriors
6//! - River Valley Scholars
7//! - Desert Nomads
8
9use phyla_lang::{CulturalProfile, Geography, Language};
10
11fn main() {
12    println!("=== Comparing Rust Implementation with JavaScript Demo ===\n");
13
14    // Recreate the cultures from language_generator.html
15    let melodic = create_melodic_coastal();
16    let martial = create_mountain_warriors();
17    let scholarly = create_river_scholars();
18    let desert = create_desert_nomads();
19
20    // Test phrase from the JavaScript demo
21    let test_phrase = "I bring the beer quickly";
22
23    println!("Translating: \"{}\"\n", test_phrase);
24
25    println!("1. Melodic Coastal Folk (Agreeable, Emotional, Open)");
26    println!("   Geography: Coastal plains");
27    println!("   Word Order: {:?}", melodic.word_order());
28    println!("   Translation: \"{}\"", melodic.translate_phrase(test_phrase));
29    println!();
30
31    println!("2. Mountain Warriors (Disagreeable, Conscientious, Brave)");
32    println!("   Geography: Mountains");
33    println!("   Word Order: {:?}", martial.word_order());
34    println!("   Translation: \"{}\"", martial.translate_phrase(test_phrase));
35    println!();
36
37    println!("3. River Valley Scholars (Open, Conscientious, Intellectual)");
38    println!("   Geography: River valleys");
39    println!("   Word Order: {:?}", scholarly.word_order());
40    println!("   Translation: \"{}\"", scholarly.translate_phrase(test_phrase));
41    println!();
42
43    println!("4. Desert Nomads (Independent, Hardy, Traditional)");
44    println!("   Geography: Arid deserts");
45    println!("   Word Order: {:?}", desert.word_order());
46    println!("   Translation: \"{}\"", desert.translate_phrase(test_phrase));
47    println!();
48
49    // Demonstrate individual word translations
50    println!("=== Individual Word Translations ===\n");
51
52    let words = ["water", "sun", "mountain", "warrior", "peace"];
53
54    for word in &words {
55        println!("{:12} → Coastal: {:12} | Mountain: {:12} | Scholar: {:12} | Desert: {:12}",
56            word,
57            melodic.translate_word(word),
58            martial.translate_word(word),
59            scholarly.translate_word(word),
60            desert.translate_word(word),
61        );
62    }
63
64    println!("\n=== Phonological Characteristics ===\n");
65
66    println!("Melodic Coastal Folk:");
67    print_phonology(&melodic);
68
69    println!("\nMountain Warriors:");
70    print_phonology(&martial);
71
72    println!("\nRiver Valley Scholars:");
73    print_phonology(&scholarly);
74
75    println!("\nDesert Nomads:");
76    print_phonology(&desert);
77}
78
79fn create_melodic_coastal() -> Language {
80    // Based on JavaScript: agreeableness: 4, openness: 3, conscientiousness: 2
81    let culture = CulturalProfile::new(
82        4.0, // agreeableness
83        3.0, // openness
84        2.0, // conscientiousness
85        3.0, // extraversion
86        3.0, // honesty_humility
87        4.0, // emotionality (high for emotional culture)
88    );
89
90    Language::from_culture(culture, Geography::Coastal, 1001)
91}
92
93fn create_mountain_warriors() -> Language {
94    // Based on JavaScript: agreeableness: 1, openness: 2, conscientiousness: 4
95    let culture = CulturalProfile::new(
96        1.0, // agreeableness (disagreeable)
97        2.0, // openness
98        4.0, // conscientiousness
99        4.0, // extraversion (brave, assertive)
100        3.0, // honesty_humility
101        2.0, // emotionality (stoic)
102    );
103
104    Language::from_culture(culture, Geography::Mountains, 1002)
105}
106
107fn create_river_scholars() -> Language {
108    // Based on JavaScript: agreeableness: 3, openness: 4, conscientiousness: 4
109    let culture = CulturalProfile::new(
110        3.0, // agreeableness
111        4.0, // openness (intellectual, creative)
112        4.0, // conscientiousness (organized, precise)
113        3.0, // extraversion
114        4.0, // honesty_humility (modest scholars)
115        3.0, // emotionality
116    );
117
118    Language::from_culture(culture, Geography::RiverValley, 1003)
119}
120
121fn create_desert_nomads() -> Language {
122    // Based on JavaScript: agreeableness: 2, openness: 2, conscientiousness: 3
123    let culture = CulturalProfile::new(
124        2.0, // agreeableness (independent)
125        2.0, // openness (traditional)
126        3.0, // conscientiousness
127        3.0, // extraversion
128        3.0, // honesty_humility
129        2.0, // emotionality (hardy, resilient)
130    );
131
132    Language::from_culture(culture, Geography::Desert, 1004)
133}
134
135fn print_phonology(language: &Language) {
136    let genome = &language.genome;
137    let inventory = &genome.phoneme_inventory;
138
139    println!("  Stops: {:?}", inventory.stops.iter().map(|c| &c.0).collect::<Vec<_>>());
140    println!("  Fricatives: {:?}", inventory.fricatives.iter().map(|c| &c.0).collect::<Vec<_>>());
141    println!("  Nasals: {:?}", inventory.nasals.iter().map(|c| &c.0).collect::<Vec<_>>());
142    println!("  Liquids: {:?}", inventory.liquids.iter().map(|c| &c.0).collect::<Vec<_>>());
143    println!("  Vowels: {:?}", inventory.vowels.iter().map(|v| &v.0).collect::<Vec<_>>());
144    println!("  Morphology: {:?}", genome.morphology_type);
145}
146