Language

Struct Language 

Source
pub struct Language {
    pub id: String,
    pub genome: LinguisticGenome,
    /* private fields */
}
Expand description

A complete language with its genome and optional caching.

Fields§

§id: String

Unique identifier for this language

§genome: LinguisticGenome

The linguistic genome (complete language specification)

Implementations§

Source§

impl Language

Source

pub fn from_culture( culture: CulturalProfile, geography: Geography, seed: u64, ) -> Self

Create a new language from a cultural profile and geography.

§Arguments
  • culture - The cultural personality profile
  • geography - The geographic environment
  • seed - Seed for deterministic generation
§Example
use phyla_lang::{Language, CulturalProfile, Geography};

let culture = CulturalProfile::new(4.0, 3.0, 2.0, 3.0, 3.0, 4.0);
let language = Language::from_culture(culture, Geography::Coastal, 12345);
Examples found in repository?
examples/compare_with_js.rs (line 90)
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}
More examples
Hide additional examples
examples/basic_usage.rs (line 37)
5fn main() {
6    println!("=== Phyla-Lang: Procedural Language Generation ===\n");
7
8    // Define different cultures
9    let coastal_folk = CulturalProfile::new(
10        4.0, // High agreeableness - cooperative, empathetic
11        3.0, // Moderate openness
12        2.0, // Lower conscientiousness - more flexible
13        3.0, // Moderate extraversion
14        3.0, // Moderate honesty-humility
15        4.0, // High emotionality - sensitive, expressive
16    );
17
18    let mountain_warriors = CulturalProfile::new(
19        1.0, // Low agreeableness - more competitive
20        2.0, // Lower openness - traditional
21        4.0, // High conscientiousness - disciplined
22        3.0, // Moderate extraversion
23        3.0, // Moderate honesty-humility
24        2.0, // Lower emotionality - stoic
25    );
26
27    let river_scholars = CulturalProfile::new(
28        3.0, // Moderate agreeableness
29        4.0, // High openness - innovative, curious
30        4.0, // High conscientiousness - organized
31        3.0, // Moderate extraversion
32        4.0, // High honesty-humility - modest, sincere
33        3.0, // Moderate emotionality
34    );
35
36    // Create languages
37    let melodic = Language::from_culture(coastal_folk, Geography::Coastal, 1001);
38    let harsh = Language::from_culture(mountain_warriors, Geography::Mountains, 1002);
39    let scholarly = Language::from_culture(river_scholars, Geography::RiverValley, 1003);
40
41    println!("1. MELODIC COASTAL LANGUAGE (Agreeable, Emotional, Coastal)");
42    println!("   Word order: {:?}", melodic.word_order());
43    demonstrate_language(&melodic);
44
45    println!("\n2. MOUNTAIN WARRIOR LANGUAGE (Disagreeable, Conscientious, Mountains)");
46    println!("   Word order: {:?}", harsh.word_order());
47    demonstrate_language(&harsh);
48
49    println!("\n3. RIVER VALLEY SCHOLAR LANGUAGE (Open, Conscientious, River Valley)");
50    println!("   Word order: {:?}", scholarly.word_order());
51    demonstrate_language(&scholarly);
52
53    // Demonstrate determinism
54    println!("\n=== DETERMINISM DEMONSTRATION ===");
55    println!("Creating two identical languages with the same parameters...\n");
56
57    let lang1 = Language::from_culture(coastal_folk, Geography::Coastal, 5555);
58    let lang2 = Language::from_culture(coastal_folk, Geography::Coastal, 5555);
59
60    let word1 = lang1.translate_word("forever");
61    let word2 = lang2.translate_word("forever");
62
63    println!("Language 1 translates 'forever' as: {}", word1);
64    println!("Language 2 translates 'forever' as: {}", word2);
65    println!("Are they the same? {}", word1 == word2);
66
67    // Demonstrate word variation
68    println!("\n=== VOCABULARY SAMPLE ===");
69    let concepts = vec![
70        "water", "fire", "earth", "wind", "sun", "moon", "star", "tree", "stone", "mountain",
71    ];
72
73    println!("\nCoastal Language:");
74    for concept in &concepts {
75        println!("  {} → {}", concept, melodic.translate_word(concept));
76    }
77
78    println!("\nMountain Language:");
79    for concept in &concepts {
80        println!("  {} → {}", concept, harsh.translate_word(concept));
81    }
82
83    println!("\nScholar Language:");
84    for concept in &concepts {
85        println!("  {} → {}", concept, scholarly.translate_word(concept));
86    }
87}
Source

pub fn from_genome(genome: LinguisticGenome) -> Self

Create a language directly from a genome.

Source

pub fn translate_word(&self, concept: &str) -> String

Translate a single word/concept to this language.

§Example
use phyla_lang::{Language, CulturalProfile, Geography};

let culture = CulturalProfile::new(4.0, 3.0, 2.0, 3.0, 3.0, 4.0);
let language = Language::from_culture(culture, Geography::Coastal, 12345);

let word = language.translate_word("house");
// The same input always produces the same output
assert_eq!(word, language.translate_word("house"));
Examples found in repository?
examples/compare_with_js.rs (line 57)
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}
More examples
Hide additional examples
examples/basic_usage.rs (line 60)
5fn main() {
6    println!("=== Phyla-Lang: Procedural Language Generation ===\n");
7
8    // Define different cultures
9    let coastal_folk = CulturalProfile::new(
10        4.0, // High agreeableness - cooperative, empathetic
11        3.0, // Moderate openness
12        2.0, // Lower conscientiousness - more flexible
13        3.0, // Moderate extraversion
14        3.0, // Moderate honesty-humility
15        4.0, // High emotionality - sensitive, expressive
16    );
17
18    let mountain_warriors = CulturalProfile::new(
19        1.0, // Low agreeableness - more competitive
20        2.0, // Lower openness - traditional
21        4.0, // High conscientiousness - disciplined
22        3.0, // Moderate extraversion
23        3.0, // Moderate honesty-humility
24        2.0, // Lower emotionality - stoic
25    );
26
27    let river_scholars = CulturalProfile::new(
28        3.0, // Moderate agreeableness
29        4.0, // High openness - innovative, curious
30        4.0, // High conscientiousness - organized
31        3.0, // Moderate extraversion
32        4.0, // High honesty-humility - modest, sincere
33        3.0, // Moderate emotionality
34    );
35
36    // Create languages
37    let melodic = Language::from_culture(coastal_folk, Geography::Coastal, 1001);
38    let harsh = Language::from_culture(mountain_warriors, Geography::Mountains, 1002);
39    let scholarly = Language::from_culture(river_scholars, Geography::RiverValley, 1003);
40
41    println!("1. MELODIC COASTAL LANGUAGE (Agreeable, Emotional, Coastal)");
42    println!("   Word order: {:?}", melodic.word_order());
43    demonstrate_language(&melodic);
44
45    println!("\n2. MOUNTAIN WARRIOR LANGUAGE (Disagreeable, Conscientious, Mountains)");
46    println!("   Word order: {:?}", harsh.word_order());
47    demonstrate_language(&harsh);
48
49    println!("\n3. RIVER VALLEY SCHOLAR LANGUAGE (Open, Conscientious, River Valley)");
50    println!("   Word order: {:?}", scholarly.word_order());
51    demonstrate_language(&scholarly);
52
53    // Demonstrate determinism
54    println!("\n=== DETERMINISM DEMONSTRATION ===");
55    println!("Creating two identical languages with the same parameters...\n");
56
57    let lang1 = Language::from_culture(coastal_folk, Geography::Coastal, 5555);
58    let lang2 = Language::from_culture(coastal_folk, Geography::Coastal, 5555);
59
60    let word1 = lang1.translate_word("forever");
61    let word2 = lang2.translate_word("forever");
62
63    println!("Language 1 translates 'forever' as: {}", word1);
64    println!("Language 2 translates 'forever' as: {}", word2);
65    println!("Are they the same? {}", word1 == word2);
66
67    // Demonstrate word variation
68    println!("\n=== VOCABULARY SAMPLE ===");
69    let concepts = vec![
70        "water", "fire", "earth", "wind", "sun", "moon", "star", "tree", "stone", "mountain",
71    ];
72
73    println!("\nCoastal Language:");
74    for concept in &concepts {
75        println!("  {} → {}", concept, melodic.translate_word(concept));
76    }
77
78    println!("\nMountain Language:");
79    for concept in &concepts {
80        println!("  {} → {}", concept, harsh.translate_word(concept));
81    }
82
83    println!("\nScholar Language:");
84    for concept in &concepts {
85        println!("  {} → {}", concept, scholarly.translate_word(concept));
86    }
87}
Source

pub fn translate_phrase(&self, phrase: &str) -> String

Translate a phrase to this language.

This splits the phrase into words, translates each word, and applies the language’s word order rules.

§Example
use phyla_lang::{Language, CulturalProfile, Geography};

let culture = CulturalProfile::new(4.0, 3.0, 2.0, 3.0, 3.0, 4.0);
let language = Language::from_culture(culture, Geography::Coastal, 12345);

let phrase = language.translate_phrase("I bring the beer quickly");
assert!(!phrase.is_empty());
Examples found in repository?
examples/basic_usage.rs (line 97)
89fn demonstrate_language(language: &Language) {
90    let phrases = vec![
91        "I bring the beer quickly",
92        "the sun rises in the east",
93        "water flows down the mountain",
94    ];
95
96    for phrase in phrases {
97        println!("   \"{}\" → \"{}\"", phrase, language.translate_phrase(phrase));
98    }
99}
More examples
Hide additional examples
examples/compare_with_js.rs (line 28)
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}
Source

pub fn word_order(&self) -> WordOrder

Get the word order of this language.

Examples found in repository?
examples/compare_with_js.rs (line 27)
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}
More examples
Hide additional examples
examples/basic_usage.rs (line 42)
5fn main() {
6    println!("=== Phyla-Lang: Procedural Language Generation ===\n");
7
8    // Define different cultures
9    let coastal_folk = CulturalProfile::new(
10        4.0, // High agreeableness - cooperative, empathetic
11        3.0, // Moderate openness
12        2.0, // Lower conscientiousness - more flexible
13        3.0, // Moderate extraversion
14        3.0, // Moderate honesty-humility
15        4.0, // High emotionality - sensitive, expressive
16    );
17
18    let mountain_warriors = CulturalProfile::new(
19        1.0, // Low agreeableness - more competitive
20        2.0, // Lower openness - traditional
21        4.0, // High conscientiousness - disciplined
22        3.0, // Moderate extraversion
23        3.0, // Moderate honesty-humility
24        2.0, // Lower emotionality - stoic
25    );
26
27    let river_scholars = CulturalProfile::new(
28        3.0, // Moderate agreeableness
29        4.0, // High openness - innovative, curious
30        4.0, // High conscientiousness - organized
31        3.0, // Moderate extraversion
32        4.0, // High honesty-humility - modest, sincere
33        3.0, // Moderate emotionality
34    );
35
36    // Create languages
37    let melodic = Language::from_culture(coastal_folk, Geography::Coastal, 1001);
38    let harsh = Language::from_culture(mountain_warriors, Geography::Mountains, 1002);
39    let scholarly = Language::from_culture(river_scholars, Geography::RiverValley, 1003);
40
41    println!("1. MELODIC COASTAL LANGUAGE (Agreeable, Emotional, Coastal)");
42    println!("   Word order: {:?}", melodic.word_order());
43    demonstrate_language(&melodic);
44
45    println!("\n2. MOUNTAIN WARRIOR LANGUAGE (Disagreeable, Conscientious, Mountains)");
46    println!("   Word order: {:?}", harsh.word_order());
47    demonstrate_language(&harsh);
48
49    println!("\n3. RIVER VALLEY SCHOLAR LANGUAGE (Open, Conscientious, River Valley)");
50    println!("   Word order: {:?}", scholarly.word_order());
51    demonstrate_language(&scholarly);
52
53    // Demonstrate determinism
54    println!("\n=== DETERMINISM DEMONSTRATION ===");
55    println!("Creating two identical languages with the same parameters...\n");
56
57    let lang1 = Language::from_culture(coastal_folk, Geography::Coastal, 5555);
58    let lang2 = Language::from_culture(coastal_folk, Geography::Coastal, 5555);
59
60    let word1 = lang1.translate_word("forever");
61    let word2 = lang2.translate_word("forever");
62
63    println!("Language 1 translates 'forever' as: {}", word1);
64    println!("Language 2 translates 'forever' as: {}", word2);
65    println!("Are they the same? {}", word1 == word2);
66
67    // Demonstrate word variation
68    println!("\n=== VOCABULARY SAMPLE ===");
69    let concepts = vec![
70        "water", "fire", "earth", "wind", "sun", "moon", "star", "tree", "stone", "mountain",
71    ];
72
73    println!("\nCoastal Language:");
74    for concept in &concepts {
75        println!("  {} → {}", concept, melodic.translate_word(concept));
76    }
77
78    println!("\nMountain Language:");
79    for concept in &concepts {
80        println!("  {} → {}", concept, harsh.translate_word(concept));
81    }
82
83    println!("\nScholar Language:");
84    for concept in &concepts {
85        println!("  {} → {}", concept, scholarly.translate_word(concept));
86    }
87}
Source

pub fn clear_cache(&self)

Clear the lexicon cache.

Source

pub fn cache_size(&self) -> usize

Get the number of cached words.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.