Beispiel #1
0
        public void DictionaryCounterInt32_Construction_2()
        {
            DictionaryCounterInt32 <string> dictionary
                = new DictionaryCounterInt32 <string>(100);

            Assert.AreEqual(0, dictionary.Count);
        }
Beispiel #2
0
        public void DictionaryCounterInt32_Construction_4()
        {
            DictionaryCounterInt32 <string> dictionary
                = new DictionaryCounterInt32 <string>(_GetComparer());

            Assert.AreEqual(0, dictionary.Count);
        }
Beispiel #3
0
        public void DictionaryCounterInt32_Construction_3()
        {
            DictionaryCounterInt32 <string> first = _GetDictionary1();
            DictionaryCounterInt32 <string> second
                = new DictionaryCounterInt32 <string>(first);

            Assert.AreEqual(first.Count, second.Count);
        }
Beispiel #4
0
        static void AnalyzeCategories
        (
            int year,
            int month
        )
        {
            string expression = string.Format
                                (
                CultureInfo.InvariantCulture,
                "RD={0:0000}{1:00}$",
                year,
                month
                                );

            int[]             found   = connection.Search(expression);
            List <MarcRecord> records = new BatchRecordReader
                                        (
                connection,
                connection.Database,
                500,
                true,
                found
                                        )
                                        .ReadAll(true);

            ReaderInfo[] readers = records.Select(ReaderInfo.Parse).ToArray();
            DictionaryCounterInt32 <string> counter = new DictionaryCounterInt32 <string>();

            foreach (ReaderInfo reader in readers)
            {
                string category = reader.Category;
                if (!string.IsNullOrEmpty(category))
                {
                    counter.Increment(category);
                }
            }

            CultureInfo        culture = CultureInfo.CurrentCulture;
            DateTimeFormatInfo format  = culture.DateTimeFormat;

            Console.Write("{0} {1}", format.GetAbbreviatedMonthName(month), year);
            foreach (string category in knownCategories)
            {
                Console.Write("\t{0}", counter.GetValue(category));
            }
            int others = 0;

            foreach (string key in counter.Keys)
            {
                if (!knownCategories.Contains(key))
                {
                    int value = counter[key];
                    others += value;
                }
            }

            Console.WriteLine("\t{0}", others);
        }
Beispiel #5
0
        public void DictionaryCounterInt32_Augment_2()
        {
            DictionaryCounterInt32 <string> dictionary
                = new DictionaryCounterInt32 <string>(_GetComparer());

            dictionary.Augment("first", 2);
            Assert.AreEqual(2, dictionary.GetValue("first"));

            dictionary.Augment("FIRST", 2);
            Assert.AreEqual(4, dictionary.GetValue("first"));
        }
Beispiel #6
0
        public void DictionaryCounterInt32_Augment_1()
        {
            DictionaryCounterInt32 <string> dictionary
                = new DictionaryCounterInt32 <string>();

            dictionary.Augment("first", 2);
            Assert.AreEqual(2, dictionary.GetValue("first"));

            dictionary.Augment("first", 2);
            Assert.AreEqual(4, dictionary.GetValue("first"));
        }
Beispiel #7
0
        public void DictionaryCounterInt32_Clear_2()
        {
            DictionaryCounterInt32 <string> dictionary = _GetDictionary2();

            dictionary.Clear();

            Assert.AreEqual(0, dictionary.GetValue("first"));
            Assert.AreEqual(0, dictionary.GetValue("second"));
            Assert.AreEqual(0, dictionary.GetValue("third"));
            Assert.AreEqual(0, dictionary.GetValue("fourth"));
        }
Beispiel #8
0
        private DictionaryCounterInt32 <string> _GetDictionary2()
        {
            DictionaryCounterInt32 <string> result
                = new DictionaryCounterInt32 <string>(_GetComparer())
                {
                { "first", 10 },
                { "second", 20 },
                { "third", 30 }
                };

            return(result);
        }
Beispiel #9
0
        public void DictionaryCounterInt32_GetValue_2()
        {
            DictionaryCounterInt32 <string> dictionary = _GetDictionary2();

            Assert.AreEqual(10, dictionary.GetValue("first"));
            Assert.AreEqual(10, dictionary.GetValue("FIRST"));
            Assert.AreEqual(20, dictionary.GetValue("second"));
            Assert.AreEqual(20, dictionary.GetValue("SECOND"));
            Assert.AreEqual(30, dictionary.GetValue("third"));
            Assert.AreEqual(30, dictionary.GetValue("THIRD"));
            Assert.AreEqual(0, dictionary.GetValue("fourth"));
            Assert.AreEqual(0, dictionary.GetValue("FOURTH"));
        }
Beispiel #10
0
        public void DictionaryCounterInt32_Increment_1()
        {
            DictionaryCounterInt32 <string> dictionary = _GetDictionary1();

            dictionary.Increment("second");
            dictionary.Increment("third");
            dictionary.Increment("first");

            Assert.AreEqual(11, dictionary.GetValue("first"));
            Assert.AreEqual(0, dictionary.GetValue("FIRST"));
            Assert.AreEqual(21, dictionary.GetValue("second"));
            Assert.AreEqual(0, dictionary.GetValue("SECOND"));
            Assert.AreEqual(31, dictionary.GetValue("third"));
            Assert.AreEqual(0, dictionary.GetValue("THIRD"));
            Assert.AreEqual(0, dictionary.GetValue("fourth"));
            Assert.AreEqual(0, dictionary.GetValue("FOURTH"));
        }
Beispiel #11
0
        // ReSharper disable InconsistentNaming

        internal void _RenumberFields()
        {
            if (_dontRenumber)
            {
                return;
            }

            DictionaryCounterInt32 <int> seen
                = new DictionaryCounterInt32 <int>();

            foreach (RecordField field in this)
            {
                int tag = field.Tag;
                field.Repeat = tag <= 0
                    ? 0
                    : seen.Increment(tag);
            }
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Need 1 argument");
                return;
            }

            string inputFileName = args[0];

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                stopwords = IrbisStopWords.ParseFile("IBIS.STW");

                string source = File.ReadAllText("words.pft");
                formatter = new PftFormatter()
                {
                    Program = PftUtility.CompileProgram(source)
                };

                //DataflowLinkOptions linkOptions = new DataflowLinkOptions
                //{
                //    PropagateCompletion = true
                //};
                //ExecutionDataflowBlockOptions executionOptions
                //    = new ExecutionDataflowBlockOptions
                //{
                //    MaxDegreeOfParallelism = 4
                //};
                //processBlock = new ActionBlock<MarcRecord>
                //    (
                //        (Action<MarcRecord>)ProcessRecord,
                //        executionOptions
                //    );

                using (FileStream stream = File.Create("words.bin"))
                    using (writer = new BinaryWriter(stream))
                        using (accessor = new DirectAccess64(inputFileName))
                        {
                            //maxMfn = accessor.GetMaxMfn();
                            maxMfn = 150000;
                            Console.WriteLine("Max MFN={0}", maxMfn);

                            // Сначала считываем все записи
                            for (int mfn = 1; mfn < maxMfn; mfn++)
                            {
                                ReadRecord(mfn);
                            }
                        }

                using (StreamWriter textWriter = File.CreateText("words.dic"))
                {
                    string[] keys = dictionary.Keys.ToArray();
                    Array.Sort(keys);
                    foreach (string key in keys)
                    {
                        textWriter.WriteLine("{0}\t{1}", key, dictionary[key]);
                    }
                }

                // Дожидаемся завершения
                // processBlock.Complete();
                // processBlock.Completion.Wait();

                Console.WriteLine
                (
                    "Good records={0}, dictionary size={1}, longest array={2}",
                    goodRecords,
                    dictionary.Count,
                    longest
                );

                DictionaryCounterInt32 <int> counter = new DictionaryCounterInt32 <int>();
                using (FileStream stream = File.OpenRead("words.bin"))
                    using (BinaryReader reader = new BinaryReader(stream))
                    {
                        while (stream.Position < stream.Length)
                        {
                            BookData data = new BookData();
                            data.RestoreFromStream(reader);
                            foreach (int word in data.Words)
                            {
                                counter.Increment(word);
                            }
                        }
                    }

                int maxCount  = counter.Values.Max();
                int threshold = maxCount / 5 + 1;
                Console.WriteLine
                (
                    "Max count={0}, threshold={1}",
                    maxCount,
                    threshold
                );

                using (FileStream stream = File.OpenRead("words.bin"))
                    using (BinaryReader reader = new BinaryReader(stream))
                        using (StreamWriter textWriter = File.CreateText("words.csv"))
                        {
                            while (stream.Position < stream.Length)
                            {
                                BookData data = new BookData();
                                data.RestoreFromStream(reader);

                                int i;
                                for (i = 0; i < data.Words.Length; i++)
                                {
                                    textWriter.Write("{0},", data.Words[i]);
                                }
                                for (; i < longest; i++)
                                {
                                    textWriter.Write("0,");
                                }
                                textWriter.WriteLine("{0}", data.Count);
                            }
                        }

                Console.WriteLine("Complete");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            stopwatch.Stop();
            TimeSpan elapsed = stopwatch.Elapsed;

            Console.WriteLine("Elapsed: {0}", elapsed.ToAutoString());
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                return;
            }

            magazines = new CaseInsensitiveDictionary <string>();
            counter   = new DictionaryCounterInt32 <string>();
            string databasePath = args[0];

            filter = args[1];

            try
            {
                ServerConfiguration configuration
                    = ServerConfiguration.FromIniFile(databasePath);
                using (irbis = new Irbis64Dll(configuration))
                {
                    irbis.Layout = SpaceLayout.Version2014();
                    irbis.SetStandardIniFile("irbisc.ini");
                    int[] found = null;
                    irbis.UseDatabase("ibis");
                    string briefPft = irbis.GetPftPath("sbrief");
                    irbis.SetFormat("@" + briefPft);

                    found = irbis.Search(filter);
                    if (found.Length == 0)
                    {
                        Console.WriteLine("Noting found");
                        return;
                    }
                    Console.WriteLine("Found: {0}", found.Length);

                    foreach (int mfn in found)
                    {
                        ProcessRecord(mfn);
                    }

                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine("Всего выдач: {0}", counter.Total);
                    Console.WriteLine();

                    KeyValuePair <string, int>[] pairs = counter
                                                         .OrderByDescending(pair => pair.Value)
                                                         .ToArray();

                    foreach (KeyValuePair <string, int> pair in pairs)
                    {
                        Console.WriteLine
                        (
                            "{0}\t{1}",
                            pair.Key,
                            pair.Value
                        );
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Beispiel #14
0
        public void DictionaryCounterInt32_Total_1()
        {
            DictionaryCounterInt32 <string> dictionary = _GetDictionary1();

            Assert.AreEqual(60, dictionary.Total);
        }