init
This commit is contained in:
102
WordGen/Model/ClassDiagram.cd
Normal file
102
WordGen/Model/ClassDiagram.cd
Normal file
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ClassDiagram MajorVersion="1" MinorVersion="1">
|
||||
<Comment CommentText="C'te SyllabaryWrapper mal foutu est censé contenir une seule et unique instance de tout les Syllabaires gérés dans l'application. Sa forme peux varier : Static, Singleton, Controleur ou Wrapper selon le bon usage, mais il doit être existant et accessible en tout point de l'application.">
|
||||
<Position X="2.229" Y="0.5" Height="1.844" Width="1.971" />
|
||||
</Comment>
|
||||
<Comment CommentText="Ces classes ont pour fonction d'assurer la persistance des objets métiers au delà de la vie de l'application. Le SyllabaryIoManager est spécialisé dans la sauvegarde des Syllabaire sur disque, que celà soit un import/export voulu par l'utilisateur ou la persistance automatique de l'application. C'est pour cette dernière raison qu'il existe un chemin spécifique à l'AppData. Le FileIoManager pourra être spécialiser dans d'autres cas suivant si l'application à des besoins futurs d'enregistrer autre chose que des Syllabaires.">
|
||||
<Position X="2.479" Y="4.073" Height="1.969" Width="3.158" />
|
||||
</Comment>
|
||||
<Class Name="WordGen.Model.Syllabary">
|
||||
<Position X="7" Y="0.5" Width="2" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAEAEAAQEAAAAAAAAAABAAAEAAAAAAAAAAAAAACABA=</HashCode>
|
||||
<FileName>Model\Syllabary.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
<ShowAsAssociation>
|
||||
<Field Name="beforeSyllable" />
|
||||
<Field Name="afterSyllable" />
|
||||
</ShowAsAssociation>
|
||||
<Lollipop Position="0.2" />
|
||||
</Class>
|
||||
<Class Name="WordGen.Program">
|
||||
<Position X="0.5" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAA=</HashCode>
|
||||
<FileName>Controler\Program.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="WordGen.SyllabaryWrapper">
|
||||
<Position X="4.5" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>CAIAAAAAAAAAAABABCAAACAAAAEQAAAAAgAAAAAEACA=</HashCode>
|
||||
<FileName>Model\SyllabaryWrapper.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
<ShowAsCollectionAssociation>
|
||||
<Field Name="_Sillabaries" />
|
||||
</ShowAsCollectionAssociation>
|
||||
</Class>
|
||||
<Class Name="WordGen.Model.SyllabaryIoManager">
|
||||
<Position X="0.5" Y="3.75" Width="1.75" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAQAAAAAAAAAAAAAAABAAQAABAAAQAA=</HashCode>
|
||||
<FileName>Controler\Persistance\SyllabaryIoManager.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="WordGen.Model.FileIoManager">
|
||||
<Position X="0.5" Y="2.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Controler\Persistance\FileManager.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="WordGen.Model.Exceptions.NoBeforeSyllableMatchException">
|
||||
<Position X="9.25" Y="5.25" Width="2.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Model\Exceptions\NoBeforeSyllableMatchException.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="WordGen.Model.Exceptions.EmptyVowelListException">
|
||||
<Position X="9.25" Y="3.75" Width="2" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Model\Exceptions\EmptyVowelListException.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="WordGen.Model.Exceptions.EmptySyllableListException">
|
||||
<Position X="12" Y="5.75" Width="2.25" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Model\Exceptions\EmptySyllableListException.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="WordGen.Model.Exceptions.EmptyConsonnantListException">
|
||||
<Position X="11.75" Y="4" Width="2.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Model\Exceptions\EmptyConsonnantListException.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="WordGen.Model.Exceptions.GeneratorException">
|
||||
<Position X="6" Y="3.75" Width="2.75" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>ABAAAQAAAAAAAAAAAAAAAAAAEAAiAAIAAgAAAAACBAA=</HashCode>
|
||||
<FileName>Model\Exceptions\GeneratorException.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Enum Name="AfterSyllable">
|
||||
<Position X="10.25" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAEAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Model\Enumerations\AfterSyllable.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Enum>
|
||||
<Enum Name="BeforeSyllable">
|
||||
<Position X="10.25" Y="0.5" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAEAAAAAAAACCAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Model\Enumerations\BeforeSyllable.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Enum>
|
||||
<Font Name="Segoe UI" Size="9" />
|
||||
</ClassDiagram>
|
7
WordGen/Model/Enumerations/AfterSyllable.cs
Normal file
7
WordGen/Model/Enumerations/AfterSyllable.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
|
||||
[Flags]
|
||||
public enum AfterSyllable : int {
|
||||
AsIs,
|
||||
AutoInsert
|
||||
}
|
8
WordGen/Model/Enumerations/BeforeSyllable.cs
Normal file
8
WordGen/Model/Enumerations/BeforeSyllable.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System;
|
||||
|
||||
[Flags]
|
||||
public enum BeforeSyllable : int {
|
||||
AsIs,
|
||||
AutoSelect,
|
||||
AutoInsert
|
||||
}
|
26
WordGen/Model/Exceptions/EmptyConsonnantListException.cs
Normal file
26
WordGen/Model/Exceptions/EmptyConsonnantListException.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using WordGen.Model.Exceptions;
|
||||
using WordGen.View.LocalizationString;
|
||||
|
||||
namespace WordGen.Model.Exceptions {
|
||||
/// <summary>
|
||||
/// Aucune consonne n'as été trouvée. Ajoutez des consonnes à votre syllabaire, retirez les consonnes de la syntaxe de votre mot (caractère 'c') ou paramétrez votre syllabaire pour ne pas insérer automatiquement une consonne entre une voyelle et une syllabe.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class EmptyConsonnantListException : GeneratorException {
|
||||
|
||||
public EmptyConsonnantListException() : base(Messages.GeneratorError_EmptyConsonnantListException) {
|
||||
}
|
||||
|
||||
public EmptyConsonnantListException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, Messages.GeneratorError_EmptyConsonnantListException) {
|
||||
}
|
||||
|
||||
public EmptyConsonnantListException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary, string message) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, message) {
|
||||
}
|
||||
|
||||
public EmptyConsonnantListException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary, string message, Exception innerException) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, message, innerException) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
24
WordGen/Model/Exceptions/EmptySyllableListException.cs
Normal file
24
WordGen/Model/Exceptions/EmptySyllableListException.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using WordGen.Model.Exceptions;
|
||||
using WordGen.View.LocalizationString;
|
||||
|
||||
namespace WordGen.Model.Exceptions {
|
||||
/// <summary>
|
||||
/// Aucune syllabe n'as été trouvée. Ajoutez des syllabe à votre syllabaire ou retirez les syllabes de la syntaxe de votre mot (caractère 's').
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class EmptySyllableListException : GeneratorException {
|
||||
public EmptySyllableListException() : base(Messages.GeneratorError_EmptySyllableListException) {
|
||||
}
|
||||
|
||||
public EmptySyllableListException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, Messages.GeneratorError_EmptySyllableListException) {
|
||||
}
|
||||
|
||||
public EmptySyllableListException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary, string message) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, message) {
|
||||
}
|
||||
|
||||
protected EmptySyllableListException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary, string message, Exception innerException) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, message, innerException) {
|
||||
}
|
||||
}
|
||||
}
|
24
WordGen/Model/Exceptions/EmptyVowelListException.cs
Normal file
24
WordGen/Model/Exceptions/EmptyVowelListException.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using WordGen.Model.Exceptions;
|
||||
using WordGen.View.LocalizationString;
|
||||
|
||||
namespace WordGen.Model.Exceptions {
|
||||
/// <summary>
|
||||
/// Aucune voyelle n'as été trouvée. Ajoutez des voyelles à votre syllabaire, retirez les voyelles de la syntaxe de votre mot (caractère 'v') ou paramétrez votre syllabaire pour ne pas insérer automatiquement une voyelle entre une consonne et une syllabe.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class EmptyVowelListException : GeneratorException {
|
||||
public EmptyVowelListException() : base(Messages.GeneratorError_EmptyVowelListException) {
|
||||
}
|
||||
|
||||
public EmptyVowelListException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, Messages.GeneratorError_EmptyVowelListException) {
|
||||
}
|
||||
|
||||
public EmptyVowelListException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary, string message) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, message) {
|
||||
}
|
||||
|
||||
protected EmptyVowelListException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary, string message, Exception innerException) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, message, innerException) {
|
||||
}
|
||||
}
|
||||
}
|
92
WordGen/Model/Exceptions/GeneratorException.cs
Normal file
92
WordGen/Model/Exceptions/GeneratorException.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WordGen.View.LocalizationString;
|
||||
|
||||
namespace WordGen.Model.Exceptions {
|
||||
/// <summary>
|
||||
/// Une exception n'as pas permis de générer entièrement le mot.
|
||||
/// </summary>
|
||||
class GeneratorException : Exception {
|
||||
|
||||
/// <summary>
|
||||
/// Le mot généré auparavant.
|
||||
/// </summary>
|
||||
protected string _wordSoFar;
|
||||
/// <summary>
|
||||
/// Obtient le mot généré auparavant.
|
||||
/// </summary>
|
||||
public string wordSoFar
|
||||
{
|
||||
get { return _wordSoFar; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Le caractère (consonne, voyelle, syllabe) qui allait être ajouté.
|
||||
/// </summary>
|
||||
protected string _currentSyllable;
|
||||
/// <summary>
|
||||
/// Obtient le caractère (consonne, voyelle, syllabe) qui allait être ajouté.
|
||||
/// </summary>
|
||||
public string currentSyllable
|
||||
{
|
||||
get { return _currentSyllable; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// La syntaxe utilisée pour générer le mot.
|
||||
/// </summary>
|
||||
protected string _currentSyntaxe;
|
||||
/// <summary>
|
||||
/// Obtient la syntaxe utilisée pour générer le mot.
|
||||
/// </summary>
|
||||
public string currentSyntaxe
|
||||
{
|
||||
get { return _currentSyntaxe; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Le syllabaire utilisé pour générer le mot.
|
||||
/// </summary>
|
||||
protected Syllabary _currentSyllabary;
|
||||
/// <summary>
|
||||
/// Obtient le syllabaire utilisé pour générer le mot.
|
||||
/// </summary>
|
||||
public Syllabary currentSyllabary
|
||||
{
|
||||
get { return _currentSyllabary; }
|
||||
}
|
||||
|
||||
public GeneratorException() : base(Messages.GeneratorError_GenericGeneratorException) {
|
||||
}
|
||||
|
||||
public GeneratorException(string message) : base(message) {
|
||||
}
|
||||
|
||||
public GeneratorException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary) : base(Messages.GeneratorError_GenericGeneratorException) {
|
||||
init(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary);
|
||||
}
|
||||
|
||||
public GeneratorException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary, string message) : base(message) {
|
||||
init(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary);
|
||||
}
|
||||
|
||||
public GeneratorException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary, string message, Exception innerException) : base(message, innerException) {
|
||||
init(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Associe les éléments passé en paramètre avec les champs de manière factorisée.
|
||||
/// </summary>
|
||||
protected void init(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary) {
|
||||
this._wordSoFar = wordSoFar;
|
||||
this._currentSyllable = currentSyllable;
|
||||
this._currentSyntaxe = currentSyntaxe;
|
||||
this._currentSyllabary = currentSyllabary;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
23
WordGen/Model/Exceptions/NoBeforeSyllableMatchException.cs
Normal file
23
WordGen/Model/Exceptions/NoBeforeSyllableMatchException.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace WordGen.Model.Exceptions {
|
||||
/// <summary>
|
||||
/// Aucune syllabe adaptée n'as été trouvée. Completez le syllabaire avec d'avantages de syllabes ou changez le comportement de celui-ci lors de l'ajout d'une syllabe.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class NoBeforeSyllableMatchException : GeneratorException {
|
||||
|
||||
public NoBeforeSyllableMatchException() : base() {
|
||||
}
|
||||
|
||||
public NoBeforeSyllableMatchException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary) {
|
||||
}
|
||||
|
||||
public NoBeforeSyllableMatchException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary, string message) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, message) {
|
||||
}
|
||||
|
||||
public NoBeforeSyllableMatchException(string wordSoFar, string currentSyllable, string currentSyntaxe, Syllabary currentSyllabary, string message, Exception innerException) : base(wordSoFar, currentSyllable, currentSyntaxe, currentSyllabary, message, innerException) {
|
||||
}
|
||||
}
|
||||
}
|
235
WordGen/Model/Generator.cs
Normal file
235
WordGen/Model/Generator.cs
Normal file
@@ -0,0 +1,235 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WordGen.Model.Exceptions;
|
||||
using WordGen.View.LocalizationString;
|
||||
|
||||
namespace WordGen.Model {
|
||||
/// <summary>
|
||||
/// Représente un générateur de mot utilisant un syllabaire donnée et d'autres informations sur la manière de générer des mots.
|
||||
/// </summary>
|
||||
class Generator {
|
||||
|
||||
protected Syllabary _syllabary;
|
||||
protected uint _lenght = 0;
|
||||
protected string _syntaxe;
|
||||
protected Random _r = new Random();
|
||||
protected StringBuilder _word;
|
||||
protected GeneratorSettings _genSett;
|
||||
|
||||
/// <summary>
|
||||
/// Instantie un générateur de mot en utilisant un syllabaire et une longueure de mot.
|
||||
/// </summary>
|
||||
/// <param name="thisSyllabary">Le syllabaire dans lequel l'application puise ses éléments.</param>
|
||||
/// <param name="wordLenght">La longueur (approximative) des mots à produire.</param>
|
||||
/// <param name="allowSyllable">Autorise l'utilisation de syllabes dans la composition.</param>
|
||||
public Generator(Syllabary thisSyllabary, uint wordLenght, GeneratorSettings mySettings = null) {
|
||||
this._syllabary = thisSyllabary;
|
||||
this._lenght = wordLenght;
|
||||
if (mySettings == null)
|
||||
mySettings = new GeneratorSettings();
|
||||
this._genSett = mySettings;
|
||||
this._syntaxe = convertLenghtToSyntaxe();
|
||||
}
|
||||
|
||||
public Generator(Syllabary thisSyllabary, string thisSyntax) {
|
||||
this._syllabary = thisSyllabary;
|
||||
this._syntaxe = thisSyntax;
|
||||
}
|
||||
|
||||
protected string convertLenghtToSyntaxe() {
|
||||
|
||||
StringBuilder syntaxer = new StringBuilder();
|
||||
for (int i = 0; i < _lenght; i++) {
|
||||
if (i == 0) {
|
||||
if (_syllabary.vowels.Count > 0 && _r.Next(101) < _genSett._vowelBeginProba) {
|
||||
syntaxer.Append('v');
|
||||
continue;
|
||||
} else if (_syllabary.syllables.Count > 0 && _r.Next(101) < _genSett._syllableBeginProba) {
|
||||
syntaxer.Append('s');
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
// s'il y a des syllabes et que le hazard veux qu'on utilise une syllabe maintenant...
|
||||
if (_syllabary.syllables.Count > 0 && _r.Next(101) < _genSett._syllableProba) {
|
||||
// ...on ajoute une syllabe.
|
||||
syntaxer.Append('s');
|
||||
// si c'est le premier charactère et que le hazard le veux...
|
||||
} else if (_syllabary.consonants.Count > 0 && _syllabary.vowels.Count > 0) {
|
||||
// si rien de tout ça n'est arrivé, on met une consonne et une voyelle.
|
||||
syntaxer.Append("cv");
|
||||
} else if (_syllabary.vowels.Count > 0) {
|
||||
syntaxer.Append('v');
|
||||
} else if (_syllabary.consonants.Count > 0) {
|
||||
syntaxer.Append('c');
|
||||
} else if (_syllabary.syllables.Count > 0) {
|
||||
syntaxer.Append('s');
|
||||
} else {
|
||||
throw new GeneratorException("Impossible de générer des mots à partir du syllabaire choisit. Le syllabaire doit contenir des voyelles, des consonnes ou des syllabes.");
|
||||
}
|
||||
}
|
||||
return syntaxer.ToString();
|
||||
}
|
||||
|
||||
public Dictionary<string, GeneratorException> generateWords(decimal thisMuch) {
|
||||
var results = new Dictionary<string, GeneratorException>();
|
||||
var courage = 5;
|
||||
for (int i = 0; i < thisMuch; i++) {
|
||||
_syntaxe = convertLenghtToSyntaxe();
|
||||
try {
|
||||
// generation of a word.
|
||||
string aWord = this.generateOneWord();
|
||||
results.Add(aWord, null);
|
||||
|
||||
} catch (NoBeforeSyllableMatchException nbsme) {
|
||||
results.Add(nbsme.wordSoFar, nbsme);
|
||||
} catch (EmptyConsonnantListException ecle) {
|
||||
results.Add(ecle.wordSoFar, ecle);
|
||||
} catch (EmptySyllableListException esle) {
|
||||
results.Add(esle.wordSoFar, esle);
|
||||
} catch (EmptyVowelListException evle) {
|
||||
results.Add(evle.wordSoFar, evle);
|
||||
} catch (GeneratorException ge) {
|
||||
results.Add(ge.wordSoFar, ge);
|
||||
//} catch(ArgumentNullException ) {
|
||||
// continue;
|
||||
} catch (ArgumentException) {
|
||||
if (courage <= 0) {
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
courage--;
|
||||
continue;
|
||||
}
|
||||
|
||||
// other exception are managed upstair
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
protected string generateOneWord() {
|
||||
_word = new StringBuilder();
|
||||
char previousLetter = '0';
|
||||
foreach (char letter in _syntaxe) {
|
||||
switch (letter) {
|
||||
case 'c':
|
||||
//if counsonne.count != 0
|
||||
_word.Append(selectAConsonnant());
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
_word.Append(selectAVowel());
|
||||
break;
|
||||
|
||||
case 's':
|
||||
_word.Append(selectASyllable(previousLetter));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
previousLetter = letter;
|
||||
}
|
||||
return _word.ToString();
|
||||
}
|
||||
|
||||
protected string selectAVowel() {
|
||||
int aNumber = _r.Next(_syllabary.vowels.Count);
|
||||
return _syllabary.vowels.ElementAt(aNumber);
|
||||
}
|
||||
|
||||
protected string selectAConsonnant() {
|
||||
int aNumber = _r.Next(_syllabary.consonants.Count);
|
||||
return _syllabary.consonants.ElementAt(aNumber);
|
||||
}
|
||||
|
||||
protected string selectASyllable(char previousLetter = '0') {
|
||||
int aNumber = _r.Next(_syllabary.syllables.Count);
|
||||
string candidat = _syllabary.syllables.ElementAt(aNumber);
|
||||
|
||||
switch (_syllabary.beforeSyllable) {
|
||||
// Comble d'un caractère adpaté avant la syllabe.
|
||||
case BeforeSyllable.AutoInsert:
|
||||
if (!isAttachable(previousLetter, candidat)) {
|
||||
switch (previousLetter) {
|
||||
case 'c':
|
||||
candidat = this.selectASyllable() + candidat;
|
||||
break;
|
||||
case 'v':
|
||||
candidat = this.selectAConsonnant() + candidat;
|
||||
break;
|
||||
case 's':
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
// Choisit une syllable compatible avec le caractère précéent.
|
||||
case BeforeSyllable.AutoSelect:
|
||||
// Toutes les syllables peuvent candidater.
|
||||
List<string> remaningCandidats = new List<string>();
|
||||
remaningCandidats.AddRange(_syllabary.syllables);
|
||||
|
||||
// tant que la syllabe candidate n'est pas attachable avec le caractère précedent, on en choisit un autre
|
||||
while (!isAttachable(previousLetter, candidat)) {
|
||||
remaningCandidats.Remove(candidat);
|
||||
// Si à la fin aucun candidat ne peux prétendre aller avec le caractère précédent, on lève une exception.
|
||||
if (remaningCandidats.Count() == 0) {
|
||||
throw new NoBeforeSyllableMatchException(_word.ToString(), candidat, _syntaxe, _syllabary);
|
||||
}
|
||||
aNumber = _r.Next(remaningCandidats.Count());
|
||||
candidat = _syllabary.syllables.ElementAt(aNumber);
|
||||
}
|
||||
|
||||
break;
|
||||
// Ne fais pas de changement de la syllabe choisit
|
||||
case BeforeSyllable.AsIs:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return candidat;
|
||||
}
|
||||
|
||||
protected bool isAttachable(char previousLetter, string candidat) {
|
||||
switch (previousLetter) {
|
||||
// cas consonne
|
||||
case 'c':
|
||||
// pour chaque consonne dans la syllabaire
|
||||
foreach (string aCons in _syllabary.consonants) {
|
||||
// si le candidat commence avec cette consomne.
|
||||
if (candidat.StartsWith(aCons)) {
|
||||
// alors ce candidat ne peux pas être utilisé.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// cas voyelle
|
||||
case 'v':
|
||||
foreach (string aVow in _syllabary.vowels) {
|
||||
if (candidat.StartsWith(aVow)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// cas syllabe
|
||||
case 's':
|
||||
// toute syllabe est compatible avec les autres.
|
||||
return true;
|
||||
|
||||
// autres cas (dont '0')
|
||||
default:
|
||||
// tout les syllables sont compatible
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
28
WordGen/Model/GeneratorSettings.cs
Normal file
28
WordGen/Model/GeneratorSettings.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WordGen.Model {
|
||||
class GeneratorSettings {
|
||||
|
||||
|
||||
public decimal _vowelBeginProba { get; set; }
|
||||
public decimal _syllableProba { get; set; }
|
||||
public decimal _syllableBeginProba { get; set; }
|
||||
|
||||
public GeneratorSettings() {
|
||||
_vowelBeginProba = 50;
|
||||
_syllableProba = -1; //10;
|
||||
_syllableBeginProba = -1; // 0;
|
||||
}
|
||||
|
||||
public GeneratorSettings(UInt16 vowelBeginProba, UInt16 syllableProba, UInt16 syllableBeginProba) {
|
||||
_vowelBeginProba = vowelBeginProba;
|
||||
_syllableBeginProba = syllableBeginProba;
|
||||
_syllableProba = syllableProba;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
69
WordGen/Model/Syllabary.cs
Normal file
69
WordGen/Model/Syllabary.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace WordGen.Model {
|
||||
/// <summary>
|
||||
/// Represends a manageable collection of syllables, consonants and/or vowels.
|
||||
/// </summary>
|
||||
[XmlRoot]
|
||||
public class Syllabary : ICloneable {
|
||||
/// <summary>
|
||||
/// The title of the syllabary, like a language.
|
||||
/// </summary>
|
||||
[XmlElement("Title")]
|
||||
public string title { get; set; }
|
||||
/// <summary>
|
||||
/// The list of syllable the syllabary contains. A syllable is a combination of consonants and vowels.
|
||||
/// </summary>
|
||||
[XmlArray("Syllables")]
|
||||
[XmlArrayItem("Syllable")]
|
||||
public List<string> syllables { get; set; }
|
||||
/// <summary>
|
||||
/// The list of consonants the syllabary contains. A consonant is a speech sound that is articulated with complete or partial closure of the vocal tract.
|
||||
/// </summary>
|
||||
[XmlArray("Consonants")]
|
||||
[XmlArrayItem("consonant")]
|
||||
public List<string> consonants { get; set; }
|
||||
/// <summary>
|
||||
/// The list of vowels or semivowels the syllabary contains. A vowel is a sound pronounced with an open vocal tract so that there is no build-up of air pressure at any point above the glottis.
|
||||
/// </summary>
|
||||
[XmlArray("Vowels")]
|
||||
[XmlArrayItem("Vowel")]
|
||||
public List<string> vowels { get; set; }
|
||||
/// <summary>
|
||||
/// The way the software will join a syllable with the previous added element.
|
||||
/// </summary>
|
||||
[XmlElement("beforeSyllable")]
|
||||
public BeforeSyllable beforeSyllable;
|
||||
/// <summary>
|
||||
/// The way the software will join the next element with the added syllable.
|
||||
/// </summary>
|
||||
[XmlElement("afterSyllable")]
|
||||
public AfterSyllable afterSyllable;
|
||||
|
||||
public Syllabary() {
|
||||
this.syllables = new List<string>();
|
||||
this.consonants = new List<string>();
|
||||
this.vowels = new List<string>();
|
||||
}
|
||||
|
||||
protected Syllabary(Syllabary aSyllabary) {
|
||||
title = aSyllabary.title;
|
||||
syllables = new List<string>(aSyllabary.syllables);
|
||||
consonants = new List<string>(aSyllabary.consonants);
|
||||
vowels = new List<string>(aSyllabary.vowels);
|
||||
beforeSyllable = aSyllabary.beforeSyllable;
|
||||
afterSyllable = aSyllabary.afterSyllable;
|
||||
}
|
||||
|
||||
public object Clone() {
|
||||
return new Syllabary(this);
|
||||
}
|
||||
|
||||
public string toString() {
|
||||
return this.title;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
131
WordGen/Model/SyllabaryWrapper.cs
Normal file
131
WordGen/Model/SyllabaryWrapper.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using WordGen.Model;
|
||||
|
||||
namespace WordGen {
|
||||
public static class SyllabaryWrapper {
|
||||
|
||||
/// <summary>
|
||||
/// La liste des Syllabaire géré par l'application.
|
||||
/// </summary>
|
||||
private static List<Syllabary> _Sillabaries = new List<Syllabary>();
|
||||
|
||||
internal static int count() {
|
||||
return _Sillabaries.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Vérifie que le nom fournit n'existe pas déjà dans la liste. Propose un nom alternatif également vérifié. La fonction est récustive à chaque modifications et garantie qu'il n'est pas possible de posséder le même nom dans la liste.
|
||||
/// </summary>
|
||||
/// <param name="Name">Le nom a vérifier.</param>
|
||||
/// <param name="Original">Si le nom est déjà utilisé, le nom nom original</param>
|
||||
/// <param name="Version">Le numéro utilisé pour différentier le nom a vérifier d'un nom déjà existant</param>
|
||||
/// <returns></returns>
|
||||
private static string CheckName(string Name, string Original = null, uint Version = 1) {
|
||||
// Nous comparons le nom avec chaque item existant dans la liste.
|
||||
foreach (Syllabary item in _Sillabaries ) {
|
||||
// Si l'un des item à un nom identique au nom spécifié ...
|
||||
if (item.title.Equals(Name)) {
|
||||
|
||||
// ... et si la fonction n'as pas déjà suggéré un nouveau nom ...
|
||||
if (Original == null) {
|
||||
// on sauvegarde le nom original pour les appels ultérieurs.
|
||||
Original = Name;
|
||||
// On suggère un nouveau nom basé sur l'ancien et une version.
|
||||
Name = Name + " (" + Version + ")";
|
||||
|
||||
} else {
|
||||
// Sinon...
|
||||
// ...On reprends le nom original et on utilise la version (qui a été incrémenté dans la méthode appelante)
|
||||
Name = Original + " (" + Version + ")";
|
||||
}
|
||||
|
||||
// On vérifie que le nom suggéré n'existe pas déjà, en fournissant l'original et une version supérieure.
|
||||
Name = CheckName(Name, Original, ++Version);
|
||||
}
|
||||
}
|
||||
return Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enregistre dans le répertoire AppData les syllabaires de l'application sous forme de fichier XML. Les fichiers existant sont remplacé.
|
||||
/// </summary>
|
||||
public static void SaveToDrive() {
|
||||
SyllabaryIoManager siom = new SyllabaryIoManager();
|
||||
siom.saveAllSyllabaries(_Sillabaries, SyllabaryIoManager.UserAppData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Récupère depuis le répertoire AppData les fichier de syllabaires existants.
|
||||
/// </summary>
|
||||
public static void LoadFromDrive() {
|
||||
SyllabaryIoManager siom = new SyllabaryIoManager();
|
||||
AddRange(siom.loadAllSyllabaries(SyllabaryIoManager.UserAppData));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtient le syllabaire de la liste des syllabaires géré par le wrapper, spécifié par son titre. Lève une exception si aucun syllabaire avec le titre spécifié n'est trouvé.
|
||||
/// </summary>
|
||||
public static Syllabary Get(string thisSyllabary) {
|
||||
foreach (Syllabary item in _Sillabaries) {
|
||||
if (item.title.Equals(thisSyllabary)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtient la liste complète des syllabaires géré par le wrapper.
|
||||
/// </summary>
|
||||
public static List<Syllabary> GetAll() {
|
||||
return _Sillabaries;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ajoute le syllabaire spécifié à la liste des syllabaires géré par le wrapper.
|
||||
/// </summary>
|
||||
/// <param name="aSyllabary">Le syllabaire qui sera ajouté.</param>
|
||||
public static void Add(Syllabary aSyllabary) {
|
||||
aSyllabary.title = CheckName(aSyllabary.title);
|
||||
_Sillabaries.Add(aSyllabary);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remplace un syllabaire de la liste des syllabaires géré par le wrapper, spécifié par son titre, par un nouveau syllabaire spécifié. Lève une exception si aucun syllabaire avec le titre spécifié n'est trouvé.
|
||||
/// </summary>
|
||||
/// <param name="thisSyllabaryTitle">Le titre du syllabaire à remplacer.</param>
|
||||
/// <param name="withThisSyllabary">Le syllabaire qui sera gardé.</param>
|
||||
public static void Replace(string thisSyllabaryTitle, Syllabary withThisSyllabary) {
|
||||
foreach (Syllabary item in _Sillabaries) {
|
||||
if (item.title.Equals(thisSyllabaryTitle)) {
|
||||
_Sillabaries.Remove(item);
|
||||
withThisSyllabary.title = CheckName(withThisSyllabary.title);
|
||||
_Sillabaries.Add(withThisSyllabary);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Supprime un syllabaire de la liste des syllabaires géré par le wrapper, spécifié par son titre. Lève une exception si aucun syllabaire avec le titre spécifié n'est trouvé.
|
||||
/// </summary>
|
||||
/// <param name="thisSyllabaryTitle">Le titre du syllabaire à supprimer.</param>
|
||||
public static void Delete(string thisSyllabaryTitle) {
|
||||
foreach (Syllabary item in _Sillabaries) {
|
||||
if (item.title.Equals(thisSyllabaryTitle)) {
|
||||
_Sillabaries.Remove(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ajoute la liste des syllabaies spécifiés à la liste des syllabires géré par le wrapper.
|
||||
/// </summary>
|
||||
public static void AddRange(IEnumerable<Syllabary> thesesSyllabaries) {
|
||||
_Sillabaries.AddRange(thesesSyllabaries);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user