Beispiel #1
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: FormatBenchmark <rootPath> <format>");

                return;
            }

            string rootPath = args[0];
            string format   = args[1];

            try
            {
                IrbisEncoding.RelaxUtf8();

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                using (LocalProvider provider = new LocalProvider(rootPath))
                {
                    provider.Database = "IBIS";
                    int maxMfn = provider.GetMaxMfn();
                    Console.WriteLine("Max MFN={0}", maxMfn);

                    PftContext context = new PftContext(null);
                    context.SetProvider(provider);
                    PftFormatter formatter = new PftFormatter(context);
                    formatter.ParseProgram(format);

                    for (int mfn = 1; mfn <= maxMfn; mfn++)
                    {
                        MarcRecord record = provider.ReadRecord(mfn);
                        if (ReferenceEquals(record, null))
                        {
                            continue;
                        }

                        string text = formatter.FormatRecord(record);
                        Console.WriteLine(text);
                    }
                }

                stopwatch.Stop();

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine
                (
                    "Elapsed: {0} sec",
                    stopwatch.Elapsed.ToSecondString()
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Beispiel #2
0
        static void ProcessRecord
        (
            [NotNull] MarcRecord record
        )
        {
            string worklist = record.FM(920);

            if (worklist != "PAZK" && worklist != "SPEC")
            {
                return;
            }

            int count = record.FM(999).SafeToInt32();

            string     formatted = formatter.FormatRecord(record);
            List <int> words     = new List <int>();

            foreach (Match match in regex.Matches(formatted))
            {
                string word = match.Value.ToUpperInvariant();
                if (word.Length >= 3 && !stopwords.IsStopWord(word))
                {
                    int id;
                    if (!dictionary.TryGetValue(word, out id))
                    {
                        id = ++lastId;
                        dictionary.Add(word, id);
                    }

                    if (!words.Contains(id))
                    {
                        words.Add(id);
                    }
                }
            }

            if (words.Count != 0)
            {
                goodRecords++;
                if (words.Count > longest)
                {
                    longest = words.Count;
                }
                BookData data = new BookData
                {
                    Count = count,
                    Mfn   = record.Mfn,
                    Words = words.ToArray()
                };
                data.SaveToStream(writer);
            }
        }
Beispiel #3
0
        private static string _GetDescription
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_briefProgram, null))
            {
                string source = File.ReadAllText("sbrief_istu.pft", IrbisEncoding.Ansi);
                _briefProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_briefProgram);
            string       result    = formatter.FormatRecord(record);

            return(result.Limit(500));
        }
Beispiel #4
0
        private static string _GetLink
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_linkProgram, null))
            {
                string source = File.ReadAllText("link.pft", IrbisEncoding.Ansi);
                _linkProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_linkProgram);
            string       result    = formatter.FormatRecord(record).Limit(200);

            return(result.EmptyToNull());
        }
Beispiel #5
0
        private static int _GetExemplars
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_exemplarsProgram, null))
            {
                string source = File.ReadAllText("exemplars.pft", IrbisEncoding.Ansi);
                _exemplarsProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_exemplarsProgram);
            string       result    = formatter.FormatRecord(record);

            return(result.SafeToInt32());
        }
Beispiel #6
0
        private static string _GetType
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_typeProgram, null))
            {
                string source = File.ReadAllText("type.pft", IrbisEncoding.Ansi);
                _typeProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_typeProgram);
            string       formatted = formatter.FormatRecord(record);
            string       result    = formatted.Contains("1")
                ? "электронный"
                : "традиционный";

            return(result);
        }
Beispiel #7
0
        private static string _GetAuthors
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_authorsProgram, null))
            {
                string source = File.ReadAllText("authors.pft", IrbisEncoding.Ansi);
                _authorsProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = _GetFormatter(_authorsProgram);
            string       merged    = formatter.FormatRecord(record);

            string[] lines  = merged.SplitLines().NonEmptyLines().ToArray();
            string   result = string.Join("; ", lines).Limit(200);

            return(result.EmptyToNull());
        }
Beispiel #8
0
        private static string _GetTitle
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_titleProgram, null))
            {
                string source = File.ReadAllText("title.pft");
                _titleProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = new PftFormatter
            {
                Program = _titleProgram
            };
            string result = formatter.FormatRecord(record);

            return(result.Limit(250));
        }
Beispiel #9
0
        private static string _GetHeading
        (
            [NotNull] MarcRecord record
        )
        {
            if (ReferenceEquals(_headingProgram, null))
            {
                string source = File.ReadAllText("heading.pft");
                _headingProgram = PftUtility.CompileProgram(source);
            }

            PftFormatter formatter = new PftFormatter
            {
                Program = _headingProgram
            };
            string result = formatter.FormatRecord(record).Limit(128);

            return(result.EmptyToNull());
        }
Beispiel #10
0
        private void _goButton_Click
        (
            object sender,
            EventArgs e
        )
        {
            _console.Clear();

            string searchExpression = _searchBox.Text.Trim();

            if (string.IsNullOrEmpty(searchExpression))
            {
                return;
            }

            try
            {
                int counter = 0;

                string        programText = _programBox.Text;
                IrbisProvider provider
                    = new ConnectedClient(Connection);
                PftFormatter formatter = new PftFormatter();
                formatter.SetProvider(provider);
                formatter.ParseProgram(programText);

                formatter.Context.Functions.Add("print", _Printer);

                DatabaseInfo     database     = (DatabaseInfo)_dbBox.SelectedItem;
                string           databaseName = database.Name.ThrowIfNull();
                SearchParameters parameters   = new SearchParameters
                {
                    Database         = databaseName,
                    SearchExpression = searchExpression
                };

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                int[] found = Connection.SequentialSearch(parameters);
                Output.WriteLine("Found: {0}", found.Length);

                BatchRecordReader batch = new BatchRecordReader
                                          (
                    Connection,
                    databaseName,
                    500,
                    found
                                          );
                using (BatchRecordWriter buffer = new BatchRecordWriter
                                                  (
                           Connection,
                           databaseName,
                           100
                                                  ))
                {
                    foreach (MarcRecord record in batch)
                    {
                        record.Modified = false;
                        formatter.Context.ClearAll();
                        string text = formatter.FormatRecord(record);
                        if (!string.IsNullOrEmpty(text))
                        {
                            Output.WriteLine(text);
                        }

                        if (record.Modified)
                        {
                            counter++;
                            Output.WriteLine
                            (
                                "[{0}] modified",
                                record.Mfn
                            );
                            buffer.Append(record);
                        }

                        Application.DoEvents();
                    }
                }

                stopwatch.Stop();

                Output.WriteLine(string.Empty);
                Output.WriteLine("Done: {0}", stopwatch.Elapsed);
                Output.WriteLine("Records modified: {0}", counter);
                Output.WriteLine(string.Empty);
            }
            catch (Exception ex)
            {
                Output.WriteLine("Exception: {0}", ex);
            }
        }
Beispiel #11
0
        private void Run()
        {
            PftFormatter formatter = new PftFormatter
            {
                Program = _program
            };

            PftUiDebugger debugger
                = new PftUiDebugger(formatter.Context);

            formatter.Context.Debugger = debugger;

            DatabaseInfo database = _databaseBox.SelectedItem
                                    as DatabaseInfo;

            if (!ReferenceEquals(database, null))
            {
                _provider.Database = database.Name
                                     .ThrowIfNull("database.Name");
            }
            formatter.SetProvider(_provider);

            string result = formatter.FormatRecord(_record);

            _resutlBox.Text = result;
            try
            {
                _rtfBox.Rtf = result;
            }
            catch
            {
                _rtfBox.Text = result;
            }

            if (ReferenceEquals(_htmlBox.Document, null))
            {
                _htmlBox.Navigate("about:blank");
                while (_htmlBox.IsBusy)
                {
                    Application.DoEvents();
                }
            }
            if (!ReferenceEquals(_htmlBox.Document, null))
            {
                _htmlBox.Document.Write(result);
            }
            try
            {
                _htmlBox.DocumentText =
                    "<html>"
                    + result
                    + "</html>";
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // Nothing to do
            }

            _recordGrid.SetRecord(_record);

            _warningBox.Text = formatter.Warning;

            _varsGrid.SetVariables(formatter.Context.Variables);
            _globalsGrid.SetGlobals(formatter.Context.Globals);
        }