public static WordFeatureRow[] Convert(string[] words) { var result = new WordFeatureRow[words.Length]; for (var i = 0; i < words.Length; i++) { result[i] = new WordFeatureRow(words[i]); } return(result); }
private static void ApostropheEnd_Func_Bloom(Func <WordFeatureRow, bool> isWord_Word, Func <WordFeatureRow, bool> isUnknown_Word, int bloomFilterSize) { var n = 0; var filter = new BloomFilter(bloomFilterSize, 1); //var filter = new ArrayBloomFilter(6000, 60000 * 8, 2); foreach (var feature in wordFeatures) { filter.Add(feature.Word); n++; } filter.ShowInfo(); solutionCreator.WriteData(filter); var negativeStats = new WeightedSet <string>(); CalcErrors(word => { var w = GetApostropheEndBase(word); w = substCalc.SubstituteWordByCommands(w); if (!filter.Contains(w)) { negativeStats.Increment("!filter.Contains", 1); return(false); } var feature = new WordFeatureRow(w); if (!isWord_Word(feature)) { negativeStats.Increment("!isWord_Word", 1); return(false); } if (!isUnknown_Word(feature)) { negativeStats.Increment("!isUnknown_Word", 1); return(false); } return(true); }); Console.WriteLine("Negative stats:"); foreach (var kvp in negativeStats) { Console.WriteLine(new { reason = kvp.Key, count = kvp.Value }); } Console.WriteLine(); }
// Сохранить тесты с сайта // HolaWeb.SaveTests(9000, @"D:\Develop\holachallenge\js\testcases"); // Создать файл всех используемых в фильтре слов // File.WriteAllLines(Path.Combine(dir, "words_out.txt"), wordFeatures.Select(f => f.Word).ToArray()); public static void Main() { try { jsonSerializer = new JsonSerializerMaster(); infixCalc = new InfixCalc(jsonSerializer, dir); originalWords = File.ReadAllLines(Path.Combine(dir, "words_uniq.txt")); originalNotWords = File.ReadAllLines(Path.Combine(dir, "notwords_uniq.txt")); words = originalWords.Where(w => !w.EndsWith("'s")).ToArray(); substCalc = new SubstCalc(jsonSerializer, dir); lettersCount = new LettersCount(jsonSerializer); solutionCreator = new SolutionCreator(dir, substCalc); //substCalc.AddCommand(substCalc.GetAffixReplaceMap(words, "suffix first.json", 6), false); //substCalc.AddCommand(substCalc.GetAffixReplaceMap(words, "prefix first.json", 7), true); //substCalc.AddCommand(substCalc.GetAffixReplaceMap(words, "suffix second.json", 6), false); //substCalc.AddCommand(substCalc.GetAffixReplaceMap(words, "prefix second.json", 7), false); //substCalc.AddCommand(substCalc.GetAffixReplaceMap(words, "suffix third.json", 6), false); // 4.8 по "ing"->"ed" //words = substCalc.ReplaceByCommands(words); substCalc.AddCommand(substCalc.GetFirstPopularSuffixReplaces(), false); substCalc.AddCommand(substCalc.GetPrefixReplaceMap(words), true); substCalc.AddCommand(substCalc.GetAffixReplaceMap(words, "trash\\suffix second 3 5 50.json", 5), false); substCalc.AddCommand(substCalc.GetAffixReplaceMap(words, "trash\\prefix second 3 5 50.json", 6), true); substCalc.AddCommand(substCalc.GetAffixReplaceMap(words, "trash\\suffix third.json", 5), false); substCalc.AddCommand(substCalc.GetAffixReplaceMap(words, "trash\\prefix third.json", 6), true); words = substCalc.ReplaceByCommands(words); mainBloomLength = 61450; Func <WordFeatureRow, bool> isWord = w => w.Length <= 14 && w.VowInRow <= 3 && w.ConsInRow <= 4 && w.Word.Count(c => c == '\'') <= 1; wordFeatures = WordFeatureRow.Convert(words).Where(isWord).ToArray(); ApostropheEnd_C2_LetterPositions_BloomPrefix_Func_Bloom(isWord); } catch (Exception ex) { Console.WriteLine(ex); } }