public void Sandbox()
 {
     using (var reader = File.OpenText(TestDataPaths.JGram))
     {
         foreach (var entry in JGram.Parse(reader))
         {
             Console.WriteLine($"{entry.Id}\t{entry.Key}・{entry.Reading}");
         }
     }
 }
 public void Basic()
 {
     JGram.Entry entry;
     using (var reader = File.OpenText(TestDataPaths.JGram))
     {
         entry = JGram.Parse(reader).First(e => e.Id == 225);
         Assert.AreEqual("に加えて", entry.Key);
         Assert.AreEqual("にくわえて", entry.Reading);
         Assert.AreEqual("nikuwaete", entry.Romaji);
         Assert.AreEqual("in addition to", entry.Translation);
         Assert.AreEqual("Well, in addition to that, he also paid for the food.", entry.Example);
     }
 }
        public JGramLookup(string jgramPath, string jgramLookupPath, string cachePath)
        {
            var entrySerializer = Serializer.ForComposite()
                                  .With(Serializer.ForLong())
                                  .With(Serializer.ForStringAsUtf8())
                                  .With(Serializer.ForStringAsUtf8())
                                  .With(Serializer.ForStringAsUtf8())
                                  .With(Serializer.ForStringAsUtf8())
                                  .With(Serializer.ForStringAsUtf8())
                                  .Create()
                                  .Mapping(raw => new JGram.Entry(
                                               (long)raw[0],
                                               EmptyToNull((string)raw[1]),
                                               EmptyToNull((string)raw[2]),
                                               EmptyToNull((string)raw[3]),
                                               EmptyToNull((string)raw[4]),
                                               EmptyToNull((string)raw[5])),
                                           obj => new object[]
            {
                obj.Id,
                NullToEmpty(obj.Key),
                NullToEmpty(obj.Reading),
                NullToEmpty(obj.Romaji),
                NullToEmpty(obj.Translation),
                NullToEmpty(obj.Example)
            });

            var indexSerializer = Serializer.ForKeyValuePair(
                Serializer.ForStringAsUtf8(),
                Serializer.ForLong());

            db = Database.CreateOrOpen(cachePath, Version)
                 .AddIndirectArray(entrySerializer, db => JGram.Parse(jgramPath, Encoding.UTF8), e => e.Id)
                 .AddIndirectArray(indexSerializer, db => LoadIndexEntries(jgramLookupPath), kvp => kvp.Key)
                 .Build();

            entries = db.Get <JGram.Entry>(0);
            index   = db.Get <KeyValuePair <string, long> >(1);

            string NullToEmpty(string s)
            {
                return(s ?? "");
            }

            string EmptyToNull(string s)
            {
                return(s == "" ? null : s);
            }
        }