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)

master
Henry Jameson 11年前
コミット 09c0d1da20
  1. 22
      .gitattributes
  2. 166
      .gitignore
  3. 9
      src/Launcher.scala
  4. 19
      src/Randomizer.scala
  5. 10
      src/Rarity.scala
  6. 12
      src/Syllable.scala
  7. 73
      src/SyllableGenerator.scala
  8. 35
      src/testing.sc

22
.gitattributes vendored

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

166
.gitignore vendored

@ -0,0 +1,166 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
# ReSharper is a .NET coding add-in
_ReSharper*
# Installshield output folder
[Ee]xpress
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
############
## Windows
############
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
# Mac crap
.DS_Store
# idea conf files
.idea
*.iml
*.ipr
*.iws

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

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

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

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

@ -0,0 +1,73 @@
/**
* Created with IntelliJ IDEA.
* User: jcd
* Date: 4/25/13
* Time: 9:54 PM
*/
class SyllableGenerator (val useX: Boolean, val sInsteadOfsh: Boolean = false, val righto: Boolean = true){
val sh = if (sInsteadOfsh) "s" else "sh"
val r = if (righto) "r" else "l"
val j = "j" // add option to replace with z?
val commonConsonants = "k" :: sh :: "t" :: "h" :: "n" :: "m" :: r ::Nil
val uncommonConsonants = "g" :: j :: "d" :: "p" :: "b" ::Nil //gojūon
val youonConsonants = "y"::Nil //or youon
val epicConsonants = "w"::Nil
val epicConsonantsAlt = "v"::Nil
//if (useX) consonants = consonants :+ "x"
val forW = "a"::"o"::Nil // wa\wo
val forWRare = "i"::"e"::Nil //wi\we
val forAll = "u"::Nil
val forCommon = forW:::forWRare:::forAll
val forYouon = forW:::forAll
def generateSyllableF(youon:Boolean):Syllable = {
var rarity:Rarity.Value = null
val consonants =
if (youon){
rarity = Rarity.Youon
youonConsonants
} else if (Randomizer.pickWithProb(0.50)){
rarity = Rarity.Common
commonConsonants
} else if (Randomizer.pickWithProb(0.50)){
rarity = Rarity.Uncommon
uncommonConsonants
} else if (Randomizer.pickWithProb(0.50)){
rarity = Rarity.Youon
youonConsonants
} else if (Randomizer.pickWithProb(0.50)) {
rarity = Rarity.Epic
epicConsonants
} else {
rarity = Rarity.EpicAlt
epicConsonantsAlt
}
val consonant = Randomizer.pickFrom(consonants)
val probOfYouon = if (consonant == j) 0.05 else 0.15
val vowel =
if (!youon && rarity != Rarity.Youon && Randomizer.pickWithProb(probOfYouon)){
generateSyllableF(youon = true).toString
} else {
val vowels = rarity match {
case Rarity.Uncommon | Rarity.Common => forCommon
case Rarity.Epic => if (Randomizer.pickWithProb(0.65)) forW else forWRare
case Rarity.Youon => forYouon
case Rarity.EpicAlt => forAll
}
Randomizer.pickFrom(vowels)
}
new Syllable(consonant,vowel)
}
def generateSyllableF:Syllable = generateSyllableF(youon = false)
def generateSyllableV(includeN:Boolean):Syllable = {
val letters = if (includeN) forAll:+"n" else forAll
new Syllable("",Randomizer.pickFrom(letters))
}
}

@ -0,0 +1,35 @@
/**
* Created with IntelliJ IDEA.
* User: jcd
* Date: 4/25/13
* Time: 10:43 PM
*
* sample workspace file to view how generator behaves.
*/
val s:SyllableGenerator = new SyllableGenerator(false, false, true)
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
s.generateSyllableF.toString()
読み込み中…
キャンセル
保存