Exemplo n.º 1
0
        private static void RunAutomaticGlossing(string dataDir, string input)
        {
            var kana = new KanaProperties2(Path.Combine(dataDir, "character", "kana.txt"), Encoding.UTF8);

            using (var mecab = new MeCabIpadic(new MeCabParam {
                DicDir = Path.Combine(dataDir, "mecab", "ipadic"), UseMemoryMappedFile = true
            }))
                using (var dict = JMDictLookup.Create(Path.Combine(dataDir, "dictionaries", "JMdict_e.gz"), Path.Combine(dataDir, "dictionaries", "JMdict_e.cache")))
                {
                    var parser     = new SentenceParser(mecab, dict);
                    var glosser    = new AutoGlosserNext(parser, dict, kana);
                    var glosses    = glosser.Gloss(input);
                    var jsonWriter = new JsonTextWriter(Console.Out);
                    jsonWriter.WriteStartArray();
                    foreach (var gloss in glosses)
                    {
                        jsonWriter.WriteStartObject();
                        jsonWriter.WritePropertyName("word");
                        jsonWriter.WriteValue(gloss.Foreign);
                        jsonWriter.WritePropertyName("definitions");
                        jsonWriter.WriteStartArray();
                        foreach (var glossCandidate in gloss.GlossCandidates)
                        {
                            jsonWriter.WriteValue(glossCandidate);
                        }
                        jsonWriter.WriteEndArray();
                        jsonWriter.WriteEndObject();
                    }
                    jsonWriter.WriteEndArray();
                }
        }
        public void SetUp()
        {
            var kanjidict      = JDict.KanjiDict.Create(TestDataPaths.KanjiDic);
            var kradfile       = new JDict.Kradfile(TestDataPaths.Kradfile, Encoding.UTF8);
            var radkfile       = new Radkfile(TestDataPaths.Radkfile, Encoding.UTF8);
            var kanaProperties = new KanaProperties2(
                TestDataPaths.Kana,
                Encoding.UTF8);

            this.mecab = new MeCabIpadic(new MeCabParam
            {
                DicDir = TestDataPaths.Ipadic,
                UseMemoryMappedFile = true
            });
            this.jmdict = JDict.JMDictLookup.Create(TestDataPaths.JMDict, TestDataPaths.JMDictCache);
            var parser = new SentenceParser(mecab, jmdict, kanaProperties);

            glosser = new AutoGlosserNext(parser, jmdict, kanaProperties);
        }