public void DictionaryCounterInt32_Increment_2() { DictionaryCounterInt32 <string> dictionary = _GetDictionary2(); dictionary.Increment("SECOND"); dictionary.Increment("THIRD"); dictionary.Increment("FIRST"); Assert.AreEqual(11, dictionary.GetValue("first")); Assert.AreEqual(11, dictionary.GetValue("FIRST")); Assert.AreEqual(21, dictionary.GetValue("second")); Assert.AreEqual(21, dictionary.GetValue("SECOND")); Assert.AreEqual(31, dictionary.GetValue("third")); Assert.AreEqual(31, dictionary.GetValue("THIRD")); Assert.AreEqual(0, dictionary.GetValue("fourth")); Assert.AreEqual(0, dictionary.GetValue("FOURTH")); }
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); }
// 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); } }
static void Main() { Console.CancelKeyPress += Console_CancelKeyPress; try { using (connection = new IrbisConnection()) { connection.ParseConnectionString(ConnectionString); connection.Connect(); connection.Database = DatabaseName; Console.WriteLine("Подключились"); IEnumerable <MarcRecord> records = BatchRecordReader.WholeDatabase ( connection, DatabaseName, 500 //, rdr => //{ // Console.WriteLine // ( // "{0} из {1}", // rdr.RecordsRead, // rdr.TotalRecords // ); //} ); foreach (MarcRecord record in records) { if (Cancel) { break; } if (record.Deleted) { continue; } ReaderInfo reader = ReaderInfo.Parse(record); if (reader.WorkPlace.SafeContains("ИОГУНБ")) { continue; } int age = reader.Age; int visits = reader.Visits.Count(v => v.IsVisit); if (reader.Gender.SameString("ж")) { FemaleCount++; FemaleAge.Increment(age); FemaleVisits.Augment(age, visits); } else { MaleCount++; MaleAge.Increment(age); MaleVisits.Augment(age, visits); } } } Console.WriteLine("Отключились"); Console.WriteLine(";Муж;Жен;М пос;Ж пос"); Console.WriteLine ( "Всего;{0};{1};{2};{3}", MaleCount, FemaleCount, MaleVisits.Total, FemaleVisits.Total ); for (int age = 12; age < 100; age++) { Console.WriteLine ( "{0};{1};{2};{3};{4}", age, MaleAge.GetValue(age), FemaleAge.GetValue(age), MaleVisits.GetValue(age), FemaleVisits.GetValue(age) ); } } catch (Exception exception) { Console.WriteLine(exception); } }
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()); }