public IFitness CreateFitness() { var db = ""; foreach (var file in Directory.GetFiles(@"C:\Users\giacomelli\Downloads\wn3.1.dict\dict\dbfiles", "*.*")) { db += File.ReadAllText(file).ToUpperInvariant(); } var f = new GhostwriterFitness(); f.EvaluateFunc = (text) => { //Console.WriteLine("Evaluating text: {0}", text); var words = text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); var points = 0.0; var wordsNotFound = 0.0; foreach (var word in words) { try { if (db.Contains(word)) { points += word.Length; } else { wordsNotFound += word.Length * 2; } } catch { points--; continue; } } if (points > 100) { points = 100; } else if (points < 0) { points = 0; } var fitness = (points / wordsNotFound) / 100.0; //onsole.WriteLine("Fitness: {0}", fitness); return fitness; }; return f; }
public IFitness CreateFitness() { var f = new GhostwriterFitness(); f.EvaluateFunc = (text) => { var minDistance = m_quotes.Min(q => LevenshteinDistance(q, text)); return 1 - (minDistance/100f); }; return f; }