public static void CalcWordsCount(JsonSerializerMaster jsonSerializer, int requestCount)
        {
            var words    = 0;
            var notWords = 0;

            for (var i = 0; i < requestCount; i++)
            {
                using (var web = new WebClient())
                {
                    web.BaseAddress = baseUrl;

                    var json = web.DownloadString("");

                    var data = jsonSerializer.Deserialize <Dictionary <string, bool> >(json);

                    var wordsHere    = data.Count(kvp => kvp.Value);
                    var notWordsHere = data.Count - wordsHere;

                    words    += wordsHere;
                    notWords += notWordsHere;

                    Console.WriteLine($"[{i}]: words {wordsHere}, not words {notWordsHere}");
                }
            }

            Console.WriteLine(new { words, notWords, wordsMean = (double)words / (words + notWords) });
        }
Ejemplo n.º 2
0
 public WordsGeneratorOld(JsonSerializerMaster jsonSerializer, string dir, string[] words, string alphabet)
 {
     this.jsonSerializer = jsonSerializer;
     this.alphabet       = alphabet;
     this.dir            = dir;
     this.words          = words.Where(w => w.Length == wordLen).ToArray();
     wordsHash           = this.words.ToHashSet();
     alphabetIndexes     = alphabet.Select((c, i) => new { c, i }).ToDictionary(a => a.c, a => a.i);
 }
        // Сохранить тесты с сайта
        // 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);
            }
        }
Ejemplo n.º 4
0
        public LettersCount(JsonSerializerMaster jsonSerializer)
        {
            this.jsonSerializer = jsonSerializer;

            var stats = new Dictionary <char, int[]>
            {
                { '\'', new int[] { 234279, 226, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'a', new int[] { 94043, 96525, 36614, 6568, 717, 39, 1, 0, 0, 0, 0, 0, 0 } },
                { 'b', new int[] { 201739, 30462, 2187, 113, 6, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'c', new int[] { 158387, 64089, 11043, 917, 63, 7, 1, 0, 0, 0, 0, 0, 0 } },
                { 'd', new int[] { 178320, 50227, 5613, 338, 9, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'e', new int[] { 91271, 95304, 39346, 7818, 727, 41, 0, 0, 0, 0, 0, 0, 0 } },
                { 'f', new int[] { 216231, 16081, 2109, 77, 9, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'g', new int[] { 196931, 34803, 2657, 107, 9, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'h', new int[] { 179544, 49839, 4991, 131, 2, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'i', new int[] { 105872, 95363, 28753, 4196, 317, 6, 0, 0, 0, 0, 0, 0, 0 } },
                { 'j', new int[] { 229921, 4513, 72, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'k', new int[] { 216418, 16803, 1227, 52, 7, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'l', new int[] { 146909, 71332, 14708, 1425, 131, 1, 1, 0, 0, 0, 0, 0, 0 } },
                { 'm', new int[] { 176480, 51811, 5883, 320, 13, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'n', new int[] { 134824, 81728, 16514, 1391, 49, 1, 0, 0, 0, 0, 0, 0, 0 } },
                { 'o', new int[] { 123124, 82043, 25070, 3869, 386, 15, 0, 0, 0, 0, 0, 0, 0 } },
                { 'p', new int[] { 180038, 47779, 6379, 306, 5, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'q', new int[] { 230828, 3602, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'r', new int[] { 119267, 95181, 18759, 1265, 35, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 's', new int[] { 147439, 69917, 15148, 1861, 127, 14, 1, 0, 0, 0, 0, 0, 0 } },
                { 't', new int[] { 133724, 80173, 18907, 1629, 74, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'u', new int[] { 175077, 53487, 5587, 332, 24, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'v', new int[] { 217794, 16096, 607, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'w', new int[] { 223053, 11001, 442, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'x', new int[] { 227921, 6534, 49, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'y', new int[] { 198793, 33684, 1986, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
                { 'z', new int[] { 226260, 7576, 633, 23, 15, 0, 0, 0, 0, 0, 0, 0, 0 } },
            };

            thresholds = stats.ToDictionary(
                kvp => kvp.Key,
                kvp => kvp.Value.FirstIndexOf(i => i < 1500));
        }
Ejemplo n.º 5
0
 public SubstCalc(JsonSerializerMaster jsonSerializer, string dir)
 {
     this.jsonSerializer = jsonSerializer;
     this.dir            = dir;
     replaceCommands     = new List <SubstReplaceCommand>();
 }
 public InfixCalc(JsonSerializerMaster jsonSerializer, string dir)
 {
     this.jsonSerializer = jsonSerializer;
     this.dir            = dir;
 }
 public WordsGenerator(JsonSerializerMaster jsonSerializer, string dir)
 {
     this.jsonSerializer = jsonSerializer;
     this.dir            = dir;
 }
        public static void Save(JsonSerializerMaster jsonSerializer, string dir, string[] words)
        {
            var wordFeatures = Convert(words);

            File.WriteAllText(Path.Combine(dir, "word_features.json"), jsonSerializer.Serialize(wordFeatures));
        }
 public static WordFeatureRow[] Read(JsonSerializerMaster jsonSerializer, string dir)
 {
     return(jsonSerializer.Deserialize <WordFeatureRow[]>(File.ReadAllText(Path.Combine(dir, "word_features.json"))));
 }