Skip to content

Commit

Permalink
Replaced duplicate constants with a single authority
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel committed Mar 14, 2018
1 parent 3a01905 commit 9dfcaf9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 36 deletions.
14 changes: 14 additions & 0 deletions Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SETextToSpeechMod
{
static class Constants
{
public static char SPACE = ' ';
public static string EMPTY = "";
}
}
18 changes: 8 additions & 10 deletions OptionalDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace SETextToSpeechMod
{
public class OptionalDebugger
{
const string SPACE = " ";

//const string currentComputer = "pavilion";
const string currentComputer = "thinkpad";

Expand Down Expand Up @@ -164,7 +162,7 @@ void RemoveFromTestTable()
{
for (int i = 0; i < castValue.Count; i++)
{
if (castValue[i] == SPACE)
if (castValue[i] == Constants.SPACE.ToString())
{
var newRemoveIndex = new KeyValuePair<string, int> (castKey, i);
indexesToRemove.Add (newRemoveIndex); //I cant use RemoveWhiteSpaceFromRef() because altering the order of an ordered dictionary, inside a loop, throws exception.
Expand Down Expand Up @@ -205,7 +203,7 @@ string RollOutAdjacentWords()

foreach (DictionaryEntry entry in adjacentWords)
{
rolledOut += entry.Key + SPACE;
rolledOut += entry.Key + Constants.SPACE.ToString();
}
return rolledOut;
}
Expand All @@ -214,7 +212,7 @@ void StoreDictionaryWords (IEnumerable <KeyValuePair <string, List <string>>> di
{
foreach (KeyValuePair <string, List <string>> entry in dictionaryWords)
{
if (entry.Key != SPACE)
if (entry.Key != Constants.SPACE.ToString())
{
var collectionCopy = new List<string>(entry.Value);
dictionaryResults.Add(entry.Key, collectionCopy);
Expand All @@ -229,7 +227,7 @@ void StoreRuleBasedWords (IEnumerable <KeyValuePair <string, List <string>>> rul
{
var noSpaces = new List <string>();

if (entry.Key != SPACE)
if (entry.Key != Constants.SPACE.ToString())
{
var valueCopy = new List <string> (entry.Value);
RemoveEmptySpaceFromRef (ref valueCopy);
Expand All @@ -254,7 +252,7 @@ void RemoveEmptySpaceFromRef (ref List <string> listToReference)
{
for (int i = 0; i < listToReference.Count; i++)
{
if (listToReference[i] == SPACE ||
if (listToReference[i] == Constants.SPACE.ToString() ||
listToReference[i] == string.Empty)
{
listToReference.RemoveAt (i);
Expand All @@ -271,7 +269,7 @@ byte[] GetTestPacket (string testSentence)

for (int i = 0; i < leftoverSpace; i++)
{
signatureBuild += SPACE;
signatureBuild += Constants.SPACE.ToString();
}
string packaged = signatureBuild + upperCase;
byte[] packet = encode.GetBytes (packaged);
Expand All @@ -296,7 +294,7 @@ void PrintResults (int wrongFormatMatchers, int wrongFormatNonMatchers)
{
throw new Exception ("Something went wrong when attempting to read previous data from file.");
}
previousReadings = previousReadings[1].Split(SPACE.ToCharArray());
previousReadings = previousReadings[1].Split(Constants.SPACE);

string[] tallies = {"Total Words: ",
"Total Incorrect: ",
Expand All @@ -318,7 +316,7 @@ void PrintResults (int wrongFormatMatchers, int wrongFormatNonMatchers)
int dictionaryWordCount = dictionaryResults.Count;

Process[] processes;
string[] testWords = allTestWords.Split (SPACE.ToCharArray());
string[] testWords = allTestWords.Split (Constants.SPACE);

for (int i = tallies.Length; i < (testWords.Length + tallies.Length); i++)
{
Expand Down
30 changes: 14 additions & 16 deletions Processing/Pronunciation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class Pronunciation : ISentenceReset
/// </summary>
public const int ALGORITHM_PHRASE_SIZE = 5;
public const int SENTENCE_END_ZONES_LENGTH = 3;
const string SPACE = " ";

//objects
public WordIsolator WordIsolator {get; private set;}
Expand Down Expand Up @@ -48,7 +47,6 @@ public void FactoryReset(Sentence newSentence)
dictionaryMatch = null;

tempSentence = newSentence;
tempLetterIndex = 0;

pushingDictionaryWordOut = false;

Expand All @@ -70,7 +68,7 @@ public void FactoryReset(Sentence newSentence)
currentResults.Clear();
surroundingPhrase = string.Empty;

if (WordIsolator.Current != SPACE)
if (WordIsolator.Current != Constants.SPACE.ToString())
{
if (WordIsolator.CurrentWordIsNew == true)
{
Expand Down Expand Up @@ -102,7 +100,7 @@ public void FactoryReset(Sentence newSentence)

else
{
currentResults.Add (SPACE); //avoids setting WordIsolator.LetterIndex in this scenario since an empty space cant reset it when needed.
currentResults.Add (Constants.SPACE.ToString()); //avoids setting WordIsolator.LetterIndex in this scenario since an empty space cant reset it when needed.
}

if (OutputManager.IsDebugging == false) //debugger only checks that the correct phonemes were selected; doesnt care about intonation
Expand Down Expand Up @@ -158,18 +156,18 @@ private void AdjacentEvaluation (int tempLetterIndex)
{
//const string VOWELS = "AEIOU";
const string CONSONANTS = "BCDFGHJKLMNPQRSTVWXYZ";
string primary = "";
string secondary = "";
string primary = string.Empty;
string secondary = string.Empty;

int intBefore = (tempLetterIndex - 1 >= 0) ? (tempLetterIndex - 1) : tempLetterIndex; //these wil prevent out-of-bounds exception.
int intAfter = (tempLetterIndex + 1 < tempSentence.Length) ? (tempLetterIndex + 1) : tempLetterIndex;
int intTwoAfter = (tempLetterIndex + 2 < tempSentence.Length) ? (tempLetterIndex + 2) : tempLetterIndex;
int intTwoBefore = (tempLetterIndex - 2 >= 0) ? (tempLetterIndex - 2) : tempLetterIndex;

string before = (intBefore != tempLetterIndex) ? tempSentence[intBefore].ToString() : SPACE; //these 4 strings ensure i can correctly identify separate words.
string after = (intAfter != tempLetterIndex) ? tempSentence[intAfter].ToString() : SPACE; //using strings instead of chars saves lines since i need strings for Contains()
string twoBefore = (intTwoBefore != tempLetterIndex && before != SPACE) ? tempSentence[intTwoBefore].ToString() : SPACE; //the false path must return a space string because spaces signify the start/end of a word.
string twoAfter = (intTwoAfter != tempLetterIndex && after != SPACE) ? tempSentence[intTwoAfter].ToString() : SPACE;
string before = (intBefore != tempLetterIndex) ? tempSentence[intBefore].ToString() : Constants.SPACE.ToString(); //these 4 strings ensure i can correctly identify separate words.
string after = (intAfter != tempLetterIndex) ? tempSentence[intAfter].ToString() : Constants.SPACE.ToString(); //using strings instead of chars saves lines since i need strings for Contains()
string twoBefore = (intTwoBefore != tempLetterIndex && before != Constants.SPACE.ToString()) ? tempSentence[intTwoBefore].ToString() : Constants.SPACE.ToString(); //the false path must return a space string because spaces signify the start/end of a word.
string twoAfter = (intTwoAfter != tempLetterIndex && after != Constants.SPACE.ToString()) ? tempSentence[intTwoAfter].ToString() : Constants.SPACE.ToString();
string currentLetter = tempSentence[tempLetterIndex].ToString();

surroundingPhrase = twoBefore + before + currentLetter + after + twoAfter; //must update here before UnwantedMatchBypassed is used in this method.
Expand Down Expand Up @@ -304,7 +302,7 @@ private void AdjacentEvaluation (int tempLetterIndex)

else if (IsMatch ("..BL.")) //able
{
primary = SPACE;
primary = Constants.SPACE.ToString();
secondary = PrettyScaryDictionary.BIH;
}

Expand Down Expand Up @@ -481,7 +479,7 @@ private void AdjacentEvaluation (int tempLetterIndex)
))
{
primary = PrettyScaryDictionary.JIH;
secondary = SPACE; //such as "gin", judgement,
secondary = Constants.SPACE.ToString(); //such as "gin", judgement,
}

else
Expand Down Expand Up @@ -636,7 +634,7 @@ private void AdjacentEvaluation (int tempLetterIndex)

else
{
primary = SPACE;
primary = Constants.SPACE.ToString();
secondary = PrettyScaryDictionary.MIH; //such as "molten", drummer,
}
break;
Expand All @@ -658,7 +656,7 @@ private void AdjacentEvaluation (int tempLetterIndex)

else
{
primary = SPACE;
primary = Constants.SPACE.ToString();
secondary = PrettyScaryDictionary.NIH; //such as nickel,
}
break;
Expand Down Expand Up @@ -855,13 +853,13 @@ private void AdjacentEvaluation (int tempLetterIndex)
else if (UnwantedMatchBypassed ("..T.U") && //!github
IsMatch ("..TH.")) //think
{
primary = SPACE;
primary = Constants.SPACE.ToString();
secondary = PrettyScaryDictionary.THI;
}

else if (IsMatch (".ST..")) //emphasised T
{
primary = SPACE;
primary = Constants.SPACE.ToString();
secondary = PrettyScaryDictionary.TIH;
}

Expand Down
14 changes: 6 additions & 8 deletions Processing/WordIsolator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace SETextToSpeechMod
{
public class WordIsolator : IEnumerator<string>, ISentenceReset
{
const string EMPTY = ""; //cant be set to string.Empty because it must be a constant; not readonly.
const char SPACE = ' ';
public const int WORD_IS_SPACE = 0;

public bool CurrentWordIsNew
Expand Down Expand Up @@ -39,7 +37,7 @@ public int WordsIndexLimit

public void FactoryReset(Sentence newSentence)
{
currentWord = EMPTY;
currentWord = Constants.EMPTY;
CurrentWordIsNew = false;
LettersLeftInWord = newSentence.Length;
WordsIndexLimit = 0;
Expand Down Expand Up @@ -67,7 +65,7 @@ public bool MoveNext()

if(tempSentence.Length < tempLetterIndex)
{
if(tempSentence[tempLetterIndex] != SPACE)
if(tempSentence[tempLetterIndex] != Constants.SPACE)
{
if(CurrentWordIsNew)
{
Expand Down Expand Up @@ -101,18 +99,18 @@ private void ModifyStateAsSpace()
CurrentWordIsNew = true;
LettersLeftInWord = WORD_IS_SPACE;
WordsIndexLimit = WORD_IS_SPACE;
currentWord = SPACE.ToString();
currentWord = Constants.SPACE.ToString();
}

private void ModifyStateAsNewWord()
{
if(currentWord != SPACE.ToString())
if(currentWord != Constants.SPACE.ToString())
{
int workingIndex = tempLetterIndex;
string wordBuild = string.Empty;

while(workingIndex < tempSentence.Length && //prevents outofbounds
tempSentence[workingIndex] != SPACE)
tempSentence[workingIndex] != Constants.SPACE)
{
wordBuild += tempSentence[workingIndex];
workingIndex++;
Expand All @@ -131,7 +129,7 @@ private void ModifyStateAsOldWord()

private void ModifyStateAsEnd()
{
currentWord = EMPTY;
currentWord = Constants.EMPTY;
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions SE TextToSpeechMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AttendanceManager.cs" />
<Compile Include="Constants.cs" />
<Compile Include="LookUpTables\Commands.cs" />
<Compile Include="LookUpTables\RecognizedSymbols.cs" />
<Compile Include="Output\SpeechTask.cs" />
Expand Down
3 changes: 1 addition & 2 deletions VoiceCode/GladosVoice/GladosIntonation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace SETextToSpeechMod.VoiceCode.GladosVoice
class GladosIntonation : Intonation
{
Random rng = new Random();
const string SPACE = " ";

int smallSize
{
Expand Down Expand Up @@ -112,7 +111,7 @@ int[] ChoosePitchPattern(int sizeIndex)

protected override string DerivedIntonationChoice(string phoneme, string surroundingPhrase, bool sentenceEndInPhrase)
{
string choice = VoiceId + SPACE;
string choice = VoiceId + Constants.SPACE.ToString();

//if (phoneme != SPACE)
//{
Expand Down

0 comments on commit 9dfcaf9

Please sign in to comment.