From 3b93be6adc99382e993fdd46e687a4d7ed0b7420 Mon Sep 17 00:00:00 2001 From: Benjamin Van Treese Date: Sat, 25 Apr 2020 14:17:16 -0500 Subject: [PATCH] Get started on additional letter sets --- src/dropecho/langgen/Consts.hx | 79 ++++++------------------ src/dropecho/langgen/Language.hx | 12 ++++ test/langgen/ConstsTest.hx | 4 +- test/langgen/LanguageTest.hx | 102 +++++++++++++++---------------- test/langgen/RewriteTest.hx | 13 ++-- test/langgen/SpellTest.hx | 2 +- 6 files changed, 92 insertions(+), 120 deletions(-) diff --git a/src/dropecho/langgen/Consts.hx b/src/dropecho/langgen/Consts.hx index 6c35603..89316bd 100644 --- a/src/dropecho/langgen/Consts.hx +++ b/src/dropecho/langgen/Consts.hx @@ -3,7 +3,6 @@ package dropecho.langgen; @:expose("Consts") class Consts { public static var consonant_sets = [ - "Test" => 'bcd'.split(""), 'Minimal' => 'ptkmnls'.split(""), 'English-ish' => 'ptkbdgmnlrsʃzʒʧ'.split(""), 'Pirahã (very simple)' => 'ptkmnh'.split(""), @@ -15,8 +14,7 @@ class Consts { ]; public static var vowel_sets = [ - "Test" => 'aeiou'.split(""), - 'Standard 5-vowel' => 'aeiou'.split(""), + 'Default' => 'aeiou'.split(""), '3-vowel a i u' => 'aiu'.split(""), 'Extra A E I' => 'aeiouAEI'.split(""), 'Extra U' => 'aeiouU'.split(""), @@ -69,6 +67,23 @@ class Consts { 'Doubles' => ['A' => 'aa', 'E' => 'ee', 'I' => 'ii', 'O' => 'oo', 'U' => 'uu'] ]; + static public var ssets = ['Just s' => ['s'], 's ʃ' => ['s', 'ʃ'], 's ʃ f' => ['s', 'ʃ', 'f']]; + + static public var lsets = [ + 'r l' => 'rl'.split(""), + 'Just r' => 'r'.split(""), + 'Just l' => 'l'.split(""), + 'w j' => 'wj'.split(""), + 'r l w j' => 'rlwj'.split("") + ]; + + static public var fsets = [ + 'm n' => 'mn'.split(""), + 's k' => 'sk'.split(""), + 'm n ŋ' => 'mnŋ'.split(""), + 's ʃ z ʒ' => 'sʃzʒ'.split("") + ]; + public static function getRandomConsonantSet(random) { var keys = [for (x in consonant_sets.keys()) x]; @@ -83,64 +98,6 @@ class Consts { } /* - - const ssets = [ - { - name: 'Just s', - S: 's' - }, - { - name: 's ʃ', - S: 'sʃ' - }, - { - name: 's ʃ f', - S: 'sʃf' - } - ]; - - const lsets = [ - { - name: 'r l', - L: 'rl' - }, - { - name: 'Just r', - L: 'r' - }, - { - name: 'Just l', - L: 'l' - }, - { - name: 'w j', - L: 'wj' - }, - { - name: 'r l w j', - L: 'rlwj' - } - ]; - - const fsets = [ - { - name: 'm n', - F: 'mn' - }, - { - name: 's k', - F: 'sk' - }, - { - name: 'm n ŋ', - F: 'mnŋ' - }, - { - name: 's ʃ z ʒ', - F: 'sʃzʒ' - } - ]; - const ressets = [ { name: 'None', diff --git a/src/dropecho/langgen/Language.hx b/src/dropecho/langgen/Language.hx index 19a5952..3812a5d 100644 --- a/src/dropecho/langgen/Language.hx +++ b/src/dropecho/langgen/Language.hx @@ -9,6 +9,9 @@ typedef LanguageConfig = { // Phonemes var consonants:Array; var vowels:Array; + var lset:Array; + var sset:Array; + var fset:Array; // Structures var syllable_structure:String; @@ -39,6 +42,9 @@ class Language { this.config = config != null ? config : { consonants: Consts.getRandomConsonantSet(random), vowels: Consts.getRandomVowelSet(random), + sset: [], + fset: [], + lset: [], syllable_structure: Consts.syllable_structures[0], phrase_structure: Consts.phrase_structures[0] }; @@ -60,6 +66,12 @@ class Language { random.choice(config.consonants); case "V" | "?V": random.choice(config.vowels); + case "S" | "?S": + random.choice(config.sset); + case "L" | "?L": + random.choice(config.lset); + case "F" | "?F": + random.choice(config.fset); case _: ""; } diff --git a/test/langgen/ConstsTest.hx b/test/langgen/ConstsTest.hx index 0a05745..8df2a5a 100644 --- a/test/langgen/ConstsTest.hx +++ b/test/langgen/ConstsTest.hx @@ -1,13 +1,13 @@ package langgen; import massive.munit.Assert; -import vantreeseba.langgen.*; +import dropecho.langgen.*; import seedyrng.Random; class ConstsTest { @Test public function canGetSet() { - var foo = Consts.consonant_sets["Test"]; + var foo = Consts.consonant_sets["Minimal"]; Assert.isNotNull(foo); } diff --git a/test/langgen/LanguageTest.hx b/test/langgen/LanguageTest.hx index 865a6e3..aab3e7e 100755 --- a/test/langgen/LanguageTest.hx +++ b/test/langgen/LanguageTest.hx @@ -1,74 +1,74 @@ package langgen; import massive.munit.Assert; -import vantreeseba.langgen.*; +import dropecho.langgen.*; class LanguageTest { public var language:Language; - @BeforeClass - public function suiteSetup() { - language = new Language(); - } + @BeforeClass + public function suiteSetup() {} - @Before - public function setup() {} + @Before + public function setup() { + language = new Language(); + } - @Test - public function canInstantiate() { - Assert.isNotNull(language); - } + @Test + public function canInstantiate() { + Assert.isNotNull(language); + } - @Test - public function createSyllable() { - var syl = language.createSyllable(); - Assert.isNotNull(syl); - } + @Test + public function createSyllable() { + var syl = language.createSyllable(); + Assert.isNotNull(syl); + } - @Test - public function createWord() { - var syl = language.createWord(); - Assert.isNotNull(syl); - } + @Test + public function createWord() { + var syl = language.createWord(); + Assert.isNotNull(syl); + } - @Test - public function createWordTwiceShouldGiveSameWord() { - var word = language.createWord("city"); - var word2 = language.createWord("city"); + @Test + public function createWordTwiceShouldGiveSameWord() { + var word = language.createWord("city"); + var word2 = language.createWord("city"); - Assert.areEqual(word, word2); - } + Assert.areEqual(word, word2); + } - @Test - public function createPhrase() { - var phrase = language.createPhrase(); + @Test + public function createPhrase() { + var phrase = language.createPhrase(); - Assert.isNotNull(phrase); - } + Assert.isNotNull(phrase); + } - @Test - public function createPhraseWithKey() { - var word = language.createWord("city"); - var phrase = language.createPhrase("city"); + @Test + public function createPhraseWithKey() { + var word = language.createWord("city"); + var phrase = language.createPhrase("city"); - Assert.isNotNull(phrase); - } + Assert.isNotNull(phrase); + } - @Test - public function createPhraseWithKeyAgain() { - var word = language.createWord("city"); - var phrase = language.createPhrase("city"); + @Test + public function createPhraseWithKeyAgain() { + var word = language.createWord("city"); + var phrase = language.createPhrase("city"); - Assert.isNotNull(phrase); - } + Assert.isNotNull(phrase); + } - @Test - public function createPhraseWithKeyAgainAndTranslate() { - var word = language.createWord("city"); - var phrase = language.createPhrase("city"); + @Test + public function createPhraseWithKeyAgainAndTranslate() { + var word = language.createWord("city"); + var phrase = language.createPhrase("city"); - var translated = language.translate(phrase); + var translated = language.translate(phrase); - Assert.isNotNull(translated); - } + Assert.isNotNull(translated); + } } diff --git a/test/langgen/RewriteTest.hx b/test/langgen/RewriteTest.hx index d2f48cd..69241c5 100644 --- a/test/langgen/RewriteTest.hx +++ b/test/langgen/RewriteTest.hx @@ -1,7 +1,7 @@ package langgen; import massive.munit.Assert; -import vantreeseba.langgen.*; +import dropecho.langgen.*; class RewriteTest { public var rewriter:Rewrite; @@ -9,10 +9,13 @@ class RewriteTest { @BeforeClass public function suiteSetup() { var config = { - consonants: Consts.consonant_sets['Test'], - vowels: Consts.vowel_sets['Test'], + consonants: Consts.consonant_sets['Minimal'], + vowels: Consts.vowel_sets['Default'], syllable_structure: Consts.syllable_structures[0], - phrase_structure: Consts.phrase_structures[0] + phrase_structure: Consts.phrase_structures[0], + fset: [], + sset: [], + lset: [] }; rewriter = new Rewrite(config); @@ -26,7 +29,7 @@ class RewriteTest { @Test public function parseRuleConsonant() { var test = '_C'; - var expected = '([d]{1})[bcd]{1}'; + var expected = '([d]{1})[ptkmnls]{1}'; var out = rewriter.parseRule('d', test); diff --git a/test/langgen/SpellTest.hx b/test/langgen/SpellTest.hx index 8c10e2e..52a7f93 100644 --- a/test/langgen/SpellTest.hx +++ b/test/langgen/SpellTest.hx @@ -1,7 +1,7 @@ package langgen; import massive.munit.Assert; -import vantreeseba.langgen.*; +import dropecho.langgen.*; class SpellTest { public var speller:Spell;