Skip to content

Commit

Permalink
Get started on additional letter sets
Browse files Browse the repository at this point in the history
  • Loading branch information
vantreeseba committed Apr 25, 2020
1 parent b3a5f4d commit 3b93be6
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 120 deletions.
79 changes: 18 additions & 61 deletions src/dropecho/langgen/Consts.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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(""),
Expand All @@ -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(""),
Expand Down Expand Up @@ -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];

Expand All @@ -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',
Expand Down
12 changes: 12 additions & 0 deletions src/dropecho/langgen/Language.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ typedef LanguageConfig = {
// Phonemes
var consonants:Array<String>;
var vowels:Array<String>;
var lset:Array<String>;
var sset:Array<String>;
var fset:Array<String>;

// Structures
var syllable_structure:String;
Expand Down Expand Up @@ -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]
};
Expand All @@ -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 _:
"";
}
Expand Down
4 changes: 2 additions & 2 deletions test/langgen/ConstsTest.hx
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
102 changes: 51 additions & 51 deletions test/langgen/LanguageTest.hx
Original file line number Diff line number Diff line change
@@ -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);
}
}
13 changes: 8 additions & 5 deletions test/langgen/RewriteTest.hx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package langgen;

import massive.munit.Assert;
import vantreeseba.langgen.*;
import dropecho.langgen.*;

class RewriteTest {
public var rewriter:Rewrite;

@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);
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion test/langgen/SpellTest.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package langgen;

import massive.munit.Assert;
import vantreeseba.langgen.*;
import dropecho.langgen.*;

class SpellTest {
public var speller:Spell;
Expand Down

0 comments on commit 3b93be6

Please sign in to comment.