private string[] SplitSameCase(string word, double noSplitScore)
{
List<string> bestSplit = new List<string>();
bestSplit.Add(word);
double maxScore = -1;
for (int i = 0; i < word.Length; i++)
{
string left = word.Substring(0, i + 1);
string right = word.Substring(i + 1);
double scoreLeft = Score(left);
double scoreRight = Score(right);
bool prefix = IsPrefix(left) || IsSuffix(right);
bool splitLeft = (Math.Sqrt(scoreLeft) > Math.Max(Score(word), noSplitScore));
bool splitRight = (Math.Sqrt(scoreRight) > Math.Max(Score(word), noSplitScore));
if (!prefix && splitLeft && splitRight)
{
if (scoreLeft + scoreRight > maxScore)
{
//found new best split
maxScore = scoreLeft + scoreRight;
bestSplit.Clear();
bestSplit.Add(left);
bestSplit.Add(right);
}
}
else if (!prefix && splitLeft)
{
string[] furtherSplit = SplitSameCase(right, noSplitScore);
if (furtherSplit.Length > 1)
{
bestSplit.Clear();
bestSplit.Add(left);
// maxScore = scoreLeft; //Emily doesn't set maxScore here, but shouldn't it be?
foreach (string w in furtherSplit)
{
bestSplit.Add(w);
// maxScore += Score(w); //Emily doesn't set maxScore here, but shouldn't it be?
}
}
}
}
return bestSplit.ToArray();
}