Ejemplo n.º 1
0
        private static void DisplayStatistics(IBible bible)
        {
            Console.WriteLine("Bible Statistics: ");
            Console.WriteLine("Total case sensitive words: {0}",
                              bible.GetService<IWordsCaseSensitive>().Words().Count());
            Console.WriteLine("Total case insensitive words: {0}",
                              bible.GetService<IWordsCaseInsensitive>().Words().Count());

            const int limit = 10;
            var topWordsByFrequency =
                bible.GetService<ITokenToVerseMap>().TokenFrequency()
                    .Where(tokFreq => tokFreq.Token.IsWord)
                    .Select(tokFreq => new {tokFreq.Token, Frequency = tokFreq.RelatedVerses().Sum(rv => rv.Frequency)})
                    .OrderByDescending(tokFreq => tokFreq.Frequency)
                    .Take(limit)
                    .Select(tokFreq => tokFreq.Token + ": " + tokFreq.Frequency);
            Console.WriteLine();
            Console.WriteLine("Top {0} words by frequency: {1}",
                limit,
                string.Join(", ", topWordsByFrequency));

            var nonWordsByFrequency =
                bible.GetService<ITokenToVerseMap>().TokenFrequency()
                    .Where(tokFreq => !tokFreq.Token.IsWord)
                    .Select(tokFreq => new {tokFreq.Token, Frequency = tokFreq.RelatedVerses().Sum(rv => rv.Frequency)})
                    .OrderByDescending(tokFreq => tokFreq.Frequency)
                    .Select(tokFreq => "'" + tokFreq.Token + "': " + tokFreq.Frequency);
            Console.WriteLine();
            Console.WriteLine("Non-word tokens: {0}", string.Join(", ", nonWordsByFrequency));
        }
Ejemplo n.º 2
0
        public void Write(BinaryWriter output, IBible bible, IEnumerable<IBibleTableWriter> tables)
        {
            if(output == null)
                throw new ArgumentNullException("output");
            if(bible == null)
                throw new ArgumentNullException("bible");

            tables = tables ?? Enumerable.Empty<IBibleTableWriter>();
            var processedTables = ProcessTables(bible, tables);

            OutputFileType(output);
            OutputFileVersion(output);
            OutputRecordCount(output, processedTables.Count());

            OutputHeaderRecs(output, processedTables);
            OutputTableData(output, processedTables);
        }
Ejemplo n.º 3
0
 private static IEnumerable<TableData> ProcessTables(IBible bible, IEnumerable<IBibleTableWriter> tables)
 {
     return
         (from table in tables
          let tableInfo = table.BuildTable(bible)
          let data = ReadStreamData(tableInfo.DataStream)
          select new TableData
                     {
                         Id = table.TableId,
                         Flags = tableInfo.Flags,
                         Data = data,
                         StoredData = data
                     })
             .ToArray();
 }
Ejemplo n.º 4
0
        private static bool ParseBible(out IBible bible)
        {
            bible = null;

            var args = Environment.GetCommandLineArgs();
            if (args.Length < 2)
            {
                ShowHelp();
                return false;
            }
            var fileName = args[1];

            if (!File.Exists(fileName))
            {
                Console.WriteLine("Input file '{0}' not found.", fileName);
                return false;
            }

            try
            {
                var parser = new BibleParser();
                using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read,
                    FileShare.Read))
                {
                    bible = parser.Parse(stream);
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to parse input file:");
                Console.WriteLine(ex.Message);
                return false;
            }
        }
Ejemplo n.º 5
0
 private static Book CreateBookUnderTest(IBible bible = null, BookName id = BookName.None)
 {
     return new Book(bible ?? new BibleStub(), id);
 }
Ejemplo n.º 6
0
        private static IBibleTableWriter CreateBibleTableWriter(IBible bible, byte[] data)
        {
            var stream = new MemoryStream(data, false);

            var tableInfo = MockRepository.GenerateStub<IBibleTableInfo>();
            tableInfo.Stub(ti => ti.Flags).Return(HeaderFlags.None);
            tableInfo.Stub(ti => ti.DataStream).Return(stream);

            var tableWriter = MockRepository.GenerateStub<IBibleTableWriter>();
            tableWriter.Stub(tw => tw.TableId).Return(BibleTableId.Verses);
            tableWriter.Stub(tw => tw.BuildTable(bible)).Return(tableInfo);

            return tableWriter;
        }