Browse Source

initial commit, syllable generator seems to be woking, but i probaly need to add some more youon control (e.g. it currently can generate several -ya syllables in a row, which isn't really good thing - try to say shyarya for example)

Henry Jameson 9 years ago
commit
09c0d1da20
8 changed files with 346 additions and 0 deletions
  1. 22
    0
      .gitattributes
  2. 166
    0
      .gitignore
  3. 9
    0
      src/Launcher.scala
  4. 19
    0
      src/Randomizer.scala
  5. 10
    0
      src/Rarity.scala
  6. 12
    0
      src/Syllable.scala
  7. 73
    0
      src/SyllableGenerator.scala
  8. 35
    0
      src/testing.sc

+ 22
- 0
.gitattributes View File

@@ -0,0 +1,22 @@
1
+# Auto detect text files and perform LF normalization
2
+* text=auto
3
+
4
+# Custom for Visual Studio
5
+*.cs     diff=csharp
6
+*.sln    merge=union
7
+*.csproj merge=union
8
+*.vbproj merge=union
9
+*.fsproj merge=union
10
+*.dbproj merge=union
11
+
12
+# Standard to msysgit
13
+*.doc	 diff=astextplain
14
+*.DOC	 diff=astextplain
15
+*.docx diff=astextplain
16
+*.DOCX diff=astextplain
17
+*.dot  diff=astextplain
18
+*.DOT  diff=astextplain
19
+*.pdf  diff=astextplain
20
+*.PDF	 diff=astextplain
21
+*.rtf	 diff=astextplain
22
+*.RTF	 diff=astextplain

+ 166
- 0
.gitignore View File

@@ -0,0 +1,166 @@
1
+#################
2
+## Eclipse
3
+#################
4
+
5
+*.pydevproject
6
+.project
7
+.metadata
8
+bin/
9
+tmp/
10
+*.tmp
11
+*.bak
12
+*.swp
13
+*~.nib
14
+local.properties
15
+.classpath
16
+.settings/
17
+.loadpath
18
+
19
+# External tool builders
20
+.externalToolBuilders/
21
+
22
+# Locally stored "Eclipse launch configurations"
23
+*.launch
24
+
25
+# CDT-specific
26
+.cproject
27
+
28
+# PDT-specific
29
+.buildpath
30
+
31
+
32
+#################
33
+## Visual Studio
34
+#################
35
+
36
+## Ignore Visual Studio temporary files, build results, and
37
+## files generated by popular Visual Studio add-ons.
38
+
39
+# User-specific files
40
+*.suo
41
+*.user
42
+*.sln.docstates
43
+
44
+# Build results
45
+[Dd]ebug/
46
+[Rr]elease/
47
+*_i.c
48
+*_p.c
49
+*.ilk
50
+*.meta
51
+*.obj
52
+*.pch
53
+*.pdb
54
+*.pgc
55
+*.pgd
56
+*.rsp
57
+*.sbr
58
+*.tlb
59
+*.tli
60
+*.tlh
61
+*.tmp
62
+*.vspscc
63
+.builds
64
+*.dotCover
65
+
66
+# Visual C++ cache files
67
+ipch/
68
+*.aps
69
+*.ncb
70
+*.opensdf
71
+*.sdf
72
+
73
+# Visual Studio profiler
74
+*.psess
75
+*.vsp
76
+
77
+# ReSharper is a .NET coding add-in
78
+_ReSharper*
79
+
80
+# Installshield output folder
81
+[Ee]xpress
82
+
83
+# DocProject is a documentation generator add-in
84
+DocProject/buildhelp/
85
+DocProject/Help/*.HxT
86
+DocProject/Help/*.HxC
87
+DocProject/Help/*.hhc
88
+DocProject/Help/*.hhk
89
+DocProject/Help/*.hhp
90
+DocProject/Help/Html2
91
+DocProject/Help/html
92
+
93
+# Click-Once directory
94
+publish
95
+
96
+# Others
97
+[Bb]in
98
+[Oo]bj
99
+sql
100
+TestResults
101
+*.Cache
102
+ClientBin
103
+stylecop.*
104
+~$*
105
+*.dbmdl
106
+Generated_Code #added for RIA/Silverlight projects
107
+
108
+# Backup & report files from converting an old project file to a newer
109
+# Visual Studio version. Backup files are not needed, because we have git ;-)
110
+_UpgradeReport_Files/
111
+Backup*/
112
+UpgradeLog*.XML
113
+
114
+
115
+
116
+############
117
+## Windows
118
+############
119
+
120
+# Windows image file caches
121
+Thumbs.db
122
+
123
+# Folder config file
124
+Desktop.ini
125
+
126
+
127
+#############
128
+## Python
129
+#############
130
+
131
+*.py[co]
132
+
133
+# Packages
134
+*.egg
135
+*.egg-info
136
+dist
137
+build
138
+eggs
139
+parts
140
+bin
141
+var
142
+sdist
143
+develop-eggs
144
+.installed.cfg
145
+
146
+# Installer logs
147
+pip-log.txt
148
+
149
+# Unit test / coverage reports
150
+.coverage
151
+.tox
152
+
153
+#Translations
154
+*.mo
155
+
156
+#Mr Developer
157
+.mr.developer.cfg
158
+
159
+# Mac crap
160
+.DS_Store
161
+
162
+# idea conf files
163
+.idea
164
+*.iml
165
+*.ipr
166
+*.iws

+ 9
- 0
src/Launcher.scala View File

@@ -0,0 +1,9 @@
1
+/**
2
+ * Created with IntelliJ IDEA.
3
+ * User: jcd
4
+ * Date: 4/25/13
5
+ * Time: 9:46 PM
6
+ */
7
+object Launcher extends App{
8
+
9
+}

+ 19
- 0
src/Randomizer.scala View File

@@ -0,0 +1,19 @@
1
+import scala.util.Random
2
+
3
+/**
4
+ * Created with IntelliJ IDEA.
5
+ * User: jcd
6
+ * Date: 4/25/13
7
+ * Time: 11:54 PM
8
+ */
9
+object Randomizer {
10
+
11
+	val secuRnd: Random = Random.javaRandomToRandom(new java.security.SecureRandom())
12
+
13
+	def pickWithProb(prob:Double):Boolean = {
14
+		secuRnd.nextDouble() <= prob
15
+	}
16
+	def pickFrom[T](prob:List[T]): T = {
17
+	    prob(secuRnd.nextInt(prob.size))
18
+	}
19
+}

+ 10
- 0
src/Rarity.scala View File

@@ -0,0 +1,10 @@
1
+/**
2
+ * Created with IntelliJ IDEA.
3
+ * User: jcd
4
+ * Date: 4/26/13
5
+ * Time: 12:14 AM
6
+ */
7
+object Rarity extends Enumeration{
8
+	type Rarity = Value
9
+	val Common, Uncommon, Youon, Epic, EpicAlt = Value
10
+}

+ 12
- 0
src/Syllable.scala View File

@@ -0,0 +1,12 @@
1
+/**
2
+ * Created with IntelliJ IDEA.
3
+ * User: jcd
4
+ * Date: 4/25/13
5
+ * Time: 9:49 PM
6
+ */
7
+class Syllable (val consonant: String, val vowel: String){
8
+	val value: String = consonant + vowel
9
+	val consonantOnly : Boolean = vowel == "n"
10
+	val vowelOnly : Boolean = consonant == ""
11
+	override def toString:String = value
12
+}

+ 73
- 0
src/SyllableGenerator.scala View File

@@ -0,0 +1,73 @@
1
+/**
2
+ * Created with IntelliJ IDEA.
3
+ * User: jcd
4
+ * Date: 4/25/13
5
+ * Time: 9:54 PM
6
+ */
7
+class SyllableGenerator (val useX: Boolean, val sInsteadOfsh: Boolean = false, val righto: Boolean = true){
8
+	val sh = if (sInsteadOfsh) "s" else "sh"
9
+	val r = if (righto) "r" else "l"
10
+	val j = "j" // add option to replace with z?
11
+
12
+	val commonConsonants   = "k" :: sh :: "t" :: "h"        :: "n" :: "m" :: r ::Nil
13
+	val uncommonConsonants = "g" :: j  :: "d" :: "p" :: "b" ::Nil //gojūon
14
+	val youonConsonants = "y"::Nil //or youon
15
+	val epicConsonants = "w"::Nil
16
+	val epicConsonantsAlt = "v"::Nil
17
+
18
+	//if (useX) consonants = consonants :+ "x"
19
+
20
+	val forW = "a"::"o"::Nil // wa\wo
21
+	val forWRare = "i"::"e"::Nil //wi\we
22
+	val forAll = "u"::Nil
23
+
24
+	val forCommon = forW:::forWRare:::forAll
25
+	val forYouon = forW:::forAll
26
+
27
+
28
+	def generateSyllableF(youon:Boolean):Syllable = {
29
+		var rarity:Rarity.Value = null
30
+		val consonants =
31
+		if (youon){
32
+			rarity = Rarity.Youon
33
+			youonConsonants
34
+		} else if (Randomizer.pickWithProb(0.50)){
35
+			rarity = Rarity.Common
36
+			commonConsonants
37
+		} else if (Randomizer.pickWithProb(0.50)){
38
+			rarity = Rarity.Uncommon
39
+			uncommonConsonants
40
+		} else if (Randomizer.pickWithProb(0.50)){
41
+			rarity = Rarity.Youon
42
+			youonConsonants
43
+		} else if (Randomizer.pickWithProb(0.50)) {
44
+			rarity = Rarity.Epic
45
+			epicConsonants
46
+		} else {
47
+			rarity = Rarity.EpicAlt
48
+			epicConsonantsAlt
49
+		}
50
+		val consonant = Randomizer.pickFrom(consonants)
51
+		val probOfYouon = if (consonant == j) 0.05 else 0.15
52
+		val vowel =
53
+		if (!youon && rarity != Rarity.Youon && Randomizer.pickWithProb(probOfYouon)){
54
+			generateSyllableF(youon = true).toString
55
+		} else {
56
+			val vowels = rarity match {
57
+				case Rarity.Uncommon | Rarity.Common => forCommon
58
+				case Rarity.Epic => if (Randomizer.pickWithProb(0.65)) forW else forWRare
59
+				case Rarity.Youon => forYouon
60
+				case Rarity.EpicAlt => forAll
61
+			}
62
+			Randomizer.pickFrom(vowels)
63
+		}
64
+		new Syllable(consonant,vowel)
65
+	}
66
+	def generateSyllableF:Syllable = generateSyllableF(youon = false)
67
+
68
+	def generateSyllableV(includeN:Boolean):Syllable = {
69
+		val letters = if (includeN) forAll:+"n" else forAll
70
+		new Syllable("",Randomizer.pickFrom(letters))
71
+	}
72
+
73
+}

+ 35
- 0
src/testing.sc View File

@@ -0,0 +1,35 @@
1
+/**
2
+ * Created with IntelliJ IDEA.
3
+ * User: jcd
4
+ * Date: 4/25/13
5
+ * Time: 10:43 PM
6
+ *
7
+ * sample workspace file to view how generator behaves.
8
+ */
9
+val s:SyllableGenerator = new SyllableGenerator(false, false, true)
10
+s.generateSyllableF.toString()
11
+s.generateSyllableF.toString()
12
+s.generateSyllableF.toString()
13
+s.generateSyllableF.toString()
14
+s.generateSyllableF.toString()
15
+s.generateSyllableF.toString()
16
+s.generateSyllableF.toString()
17
+s.generateSyllableF.toString()
18
+s.generateSyllableF.toString()
19
+s.generateSyllableF.toString()
20
+s.generateSyllableF.toString()
21
+s.generateSyllableF.toString()
22
+s.generateSyllableF.toString()
23
+s.generateSyllableF.toString()
24
+s.generateSyllableF.toString()
25
+s.generateSyllableF.toString()
26
+s.generateSyllableF.toString()
27
+s.generateSyllableF.toString()
28
+s.generateSyllableF.toString()
29
+s.generateSyllableF.toString()
30
+s.generateSyllableF.toString()
31
+s.generateSyllableF.toString()
32
+s.generateSyllableF.toString()
33
+s.generateSyllableF.toString()
34
+s.generateSyllableF.toString()
35
+