Browse Source

added word generator. makes funny words. fixed bug with using only "u" for syllableV

Henry Jameson 9 years ago
parent
commit
0fb2d1019f
5 changed files with 99 additions and 27 deletions
  1. 3
    0
      src/Randomizer.scala
  2. 2
    2
      src/SyllableGenerator.scala
  3. 31
    0
      src/Word.scala
  4. 25
    0
      src/WordGenerator.scala
  5. 38
    25
      src/testing.sc

+ 3
- 0
src/Randomizer.scala View File

@@ -16,4 +16,7 @@ object Randomizer {
16 16
 	def pickFrom[T](prob:List[T]): T = {
17 17
 	    prob(secuRnd.nextInt(prob.size))
18 18
 	}
19
+	def pickInt(min:Int,max:Int):Int = {
20
+		min + secuRnd.nextInt(max - min)
21
+	}
19 22
 }

+ 2
- 2
src/SyllableGenerator.scala View File

@@ -73,8 +73,8 @@ class SyllableGenerator (val useX: Boolean, val sInsteadOfsh: Boolean = false, v
73 73
 	}
74 74
 	def generateSyllableF:Syllable = generateSyllableF(youonForce = false, youonProhibit = false)
75 75
 
76
-	def generateSyllableV(includeN:Boolean):Syllable = {
77
-		val letters = if (includeN) forAll:+"n" else forAll
76
+	def generateSyllableV(useN:Boolean):Syllable = {
77
+		val letters = if (useN) "n"::Nil else forCommon
78 78
 		new Syllable("",Randomizer.pickFrom(letters),false)
79 79
 	}
80 80
 

+ 31
- 0
src/Word.scala View File

@@ -0,0 +1,31 @@
1
+/**
2
+ * Created with IntelliJ IDEA.
3
+ * User: jcd
4
+ * Date: 4/26/13
5
+ * Time: 11:04 AM
6
+ */
7
+class Word (val lentgh:Int){
8
+	var numOfN = 0
9
+	var numOfYouon = 0
10
+	var numOfFSyllables = 0
11
+	var numOfVSyllables = 0
12
+	private val value:StringBuilder = new StringBuilder()
13
+	def append(syllable:Syllable){
14
+		value.append(syllable.toString)
15
+	}
16
+	override def toString:String = {
17
+		value.toString()
18
+	}
19
+	def n():Int = {
20
+		numOfN / lentgh * 100
21
+	}
22
+	def youyon():Int =  {
23
+		numOfYouon / lentgh * 100
24
+	}
25
+	def fsyl():Int = {
26
+		numOfFSyllables / lentgh * 100
27
+	}
28
+	def vsyl():Int = {
29
+		numOfVSyllables / lentgh * 100
30
+	}
31
+}

+ 25
- 0
src/WordGenerator.scala View File

@@ -0,0 +1,25 @@
1
+/**
2
+ * Created with IntelliJ IDEA.
3
+ * User: jcd
4
+ * Date: 4/26/13
5
+ * Time: 11:03 AM
6
+ */
7
+class WordGenerator(val sg:SyllableGenerator) {
8
+	def generateWord:Word= {
9
+		val word = new Word(Randomizer.pickInt(3,6))
10
+		var lastYouon = false
11
+		for (i <- 0 to word.lentgh){
12
+			val syllable =
13
+			if ((0 to 5 contains(word.n())) && Randomizer.pickWithProb(0.25)){
14
+				sg.generateSyllableV(useN = true)
15
+			} else if ((0 to 25 contains(word.vsyl())) && Randomizer.pickWithProb(0.49)){
16
+				sg.generateSyllableV(useN = false)
17
+			} else {
18
+				sg.generateSyllableF(youonForce = false, youonProhibit = lastYouon)
19
+			}
20
+			lastYouon = syllable.isYouon
21
+			word.append(syllable)
22
+		}
23
+		word
24
+	}
25
+}

+ 38
- 25
src/testing.sc View File

@@ -7,29 +7,42 @@
7 7
  * sample workspace file to view how generator behaves.
8 8
  */
9 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()
10
+val w:WordGenerator = new WordGenerator(s)
11
+for (i <- 1 to 50){
12
+	System.out.println (w.generateWord.toString+" ")
13
+}
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
35 48