Пример #1
0
        public JMNedictLookup Creation()
        {
            var jmdict = JMNedictLookup.Create(TestDataPaths.JMnedict, TestDataPaths.JMnedictCache);

            jmdict.Dispose();
            return(jmdict);
        }
 public ReplRootModule(
     JMDictLookup jmdict,
     JMNedictLookup jmnedict,
     ReplCorpora corpora)
 {
     this.Jmdict   = jmdict;
     this.Jmnedict = jmnedict;
     this.Corpora  = corpora;
 }
Пример #3
0
 public JNeDictDataSource(JMNedictLookup dict)
 {
     this.dict = dict;
 }
Пример #4
0
 protected override async Task CreateCache()
 {
     using (var jmdictLookup = await JMNedictLookup.CreateAsync(newPath, newCachePath))
     {
     }
 }
        public static ICollection <Func <IReadOnlyKernel, IDataSource> > BindDidacticalEnigmaCoreServices(
            this Kernel kernel,
            string dataDirectory,
            string cacheDirectory)
        {
            kernel.Bind(() => KanjiDict.Create(Path.Combine(dataDirectory, "character", "kanjidic2.xml.gz")));
            kernel.Bind(() =>
                        new Kradfile(Path.Combine(dataDirectory, "character", "kradfile1_plus_2_utf8"), Encoding.UTF8));
            kernel.Bind(() =>
                        new Radkfile(Path.Combine(dataDirectory, "character", "radkfile1_plus_2_utf8"), Encoding.UTF8));
            kernel.Bind(() => JMDictLookup.Create(Path.Combine(dataDirectory, "dictionaries", "JMdict_e.gz"),
                                                  Path.Combine(cacheDirectory, "dictionaries", "JMdict_e.cache")));
            kernel.Bind(() => JMNedictLookup.Create(Path.Combine(dataDirectory, "dictionaries", "JMnedict.xml.gz"),
                                                    Path.Combine(cacheDirectory, "dictionaries", "JMnedict.xml.cache")));
            kernel.Bind(() =>
                        new FrequencyList(Path.Combine(dataDirectory, "other", "word_form_frequency_list.txt"), Encoding.UTF8));
            kernel.Bind(() => new Tanaka(Path.Combine(dataDirectory, "corpora", "examples.utf.gz"), Encoding.UTF8));
            kernel.Bind(() => new JESC(Path.Combine(dataDirectory, "corpora", "jesc_raw"), Encoding.UTF8));
            kernel.Bind(() =>
                        new BasicExpressionsCorpus(Path.Combine(dataDirectory, "corpora", "JEC_basic_sentence_v1-2.csv"),
                                                   Encoding.UTF8));
            kernel.Bind <IMorphologicalAnalyzer <IpadicEntry> >(() => new MeCabIpadic(new MeCabParam
            {
                DicDir = Path.Combine(dataDirectory, "mecab", "ipadic"),
                UseMemoryMappedFile = true
            }));
            kernel.Bind <IMorphologicalAnalyzer <UnidicEntry> >(() => new MeCabUnidic(new MeCabParam
            {
                DicDir = Path.Combine(dataDirectory, "mecab", "unidic"),
                UseMemoryMappedFile = true
            }));
            kernel.Bind <IMorphologicalAnalyzer <IEntry> >(get =>
            {
                // not sure if objects created this way will be disposed twice
                // probably doesn't matter (IDisposable.Dispose's contract says
                // it's not a problem), but still
                try
                {
                    return(get.Get <IMorphologicalAnalyzer <UnidicEntry> >());
                }
                catch (Exception)
                {
                    return(get.Get <IMorphologicalAnalyzer <IpadicEntry> >());
                }
            });
            kernel.Bind(get => new RadicalRemapper(get.Get <Kradfile>(), get.Get <Radkfile>()));
            kernel.Bind(get => EasilyConfusedKana.FromFile(Path.Combine(dataDirectory, "character", "confused.txt")));
            kernel.Bind <IKanjiProperties, KanjiProperties>();
            kernel.Bind(get => new KanjiProperties(
                            get.Get <KanjiDict>(),
                            get.Get <Kradfile>(),
                            get.Get <Radkfile>(),
                            null));
            kernel.Bind <IRomaji, ModifiedHepburn>();
            kernel.Bind(get => new ModifiedHepburn(
                            get.Get <IMorphologicalAnalyzer <IEntry> >(),
                            get.Get <IKanaProperties>()));
            kernel.Bind <IAutoGlosser, AutoGlosserNext>();
            kernel.Bind(get =>
                        new AutoGlosserNext(get.Get <ISentenceParser>(), get.Get <JMDictLookup>(), get.Get <IKanaProperties>()));
            kernel.Bind(get => new CharacterDataSource(get.Get <IKanjiProperties>(), get.Get <IKanaProperties>()));
            kernel.Bind(get => new CharacterStrokeOrderDataSource());
            kernel.Bind(get => new JMDictDataSource(get.Get <JMDictLookup>(), get.Get <IKanaProperties>()));
            kernel.Bind(get => new JMDictCompactDataSource(get.Get <JMDictLookup>(), get.Get <IKanaProperties>()));
            kernel.Bind(get => new JNeDictDataSource(get.Get <JMNedictLookup>()));
            kernel.Bind(get => new VerbConjugationDataSource(get.Get <JMDictLookup>()));
            kernel.Bind(get => new WordFrequencyRatingDataSource(get.Get <FrequencyList>()));
            kernel.Bind(get => new PartialExpressionJMDictDataSource(get.Get <IdiomDetector>()));
            kernel.Bind(get => new JGramDataSource(get.Get <IJGramLookup>()));
            kernel.Bind(get => new AutoGlosserDataSource(get.Get <IAutoGlosser>()));
            kernel.Bind(get => new CustomNotesDataSource(Path.Combine(dataDirectory, "custom", "custom_notes.txt")));
            kernel.Bind(get => new TanakaCorpusFastDataSource(get.Get <Corpus>()));
            kernel.Bind(get => new TanakaCorpusDataSource(get.Get <Tanaka>()));
            kernel.Bind(get => new BasicExpressionCorpusDataSource(get.Get <BasicExpressionsCorpus>()));
            kernel.Bind(get => new PartialWordLookupJMDictDataSource(get.Get <PartialWordLookup>(), get.Get <FrequencyList>()));
            kernel.Bind(get => new JESCDataSource(get.Get <JESC>()));
            kernel.Bind(get => new RomajiDataSource(get.Get <IRomaji>()));

            var epwingDictionaries = CreateEpwing(dataDirectory, cacheDirectory);

            ICollection <Func <IReadOnlyKernel, IDataSource> > dataSourceCollection =
                new List <Func <IReadOnlyKernel, IDataSource> >(new Func <IReadOnlyKernel, IDataSource>[]
            {
                get => get.Get <CharacterDataSource>(),
                get => get.Get <CharacterStrokeOrderDataSource>(),
                get => get.Get <JMDictDataSource>(),
                get => get.Get <JNeDictDataSource>(),
                get => get.Get <JMDictCompactDataSource>(),
                get => get.Get <VerbConjugationDataSource>(),
                get => get.Get <WordFrequencyRatingDataSource>(),
                get => get.Get <PartialExpressionJMDictDataSource>(),
                get => get.Get <JGramDataSource>(),
                get => get.Get <AutoGlosserDataSource>(),
                get => get.Get <CustomNotesDataSource>(),
                get => get.Get <TanakaCorpusFastDataSource>(),
                get => get.Get <TanakaCorpusDataSource>(),
                get => get.Get <BasicExpressionCorpusDataSource>(),
                get => get.Get <PartialWordLookupJMDictDataSource>(),
                get => get.Get <JESCDataSource>(),
                get => get.Get <RomajiDataSource>(),
            }.Concat(epwingDictionaries.Dictionaries
                     .Select(dict => new Func <IReadOnlyKernel, IDataSource>(
                                 get => new EpwingDataSource(dict, get.Get <IKanaProperties>())))));

            kernel.Bind <IEnumerable <IDataSource> >(get => dataSourceCollection.Select(factory => factory(get)));

            kernel.Bind <IKanaProperties, KanaProperties2>();
            kernel.Bind(get =>
                        new KanaProperties2(Path.Combine(dataDirectory, "character", "kana.txt"), Encoding.UTF8));
            kernel.Bind(get =>
                        new SimilarKanji(Path.Combine(dataDirectory, "character", "kanji.tgz_similars.ut8"), Encoding.UTF8));
            kernel.Bind(get => new SentenceParser(get.Get <IMorphologicalAnalyzer <IEntry> >(), get.Get <JMDictLookup>(), get.Get <IKanaProperties>()));
            kernel.Bind <ISentenceParser, SentenceParser>();
            kernel.Bind <IRelated>(get =>
                                   new CompositeRelated(
                                       get.Get <KanaProperties2>(),
                                       get.Get <EasilyConfusedKana>(),
                                       get.Get <SimilarKanji>()));
            kernel.Bind(get => new IdiomDetector(get.Get <JMDictLookup>(),
                                                 get.Get <IMorphologicalAnalyzer <IpadicEntry> >(), Path.Combine(cacheDirectory, "dictionaries", "idioms.cache")));
            kernel.Bind <IKanjiLookupService, KanjiLookupService>();
            kernel.Bind(get => new KanjiLookupService(
                            get.Get <KanjiRadicalLookup>(),
                            get.Get <IRadicalSearcher>(),
                            get.Get <IKanjiProperties>(),
                            get.Get <KanjiAliveJapaneseRadicalInformation>(),
                            get.Get <RadkfileKanjiAliveCorrelator>(),
                            CreateTextRadicalMappings(get.Get <KanjiRadicalLookup>().AllRadicals, get.Get <RadkfileKanjiAliveCorrelator>())));
            kernel.Bind(get => new PartialWordLookup(get.Get <JMDictLookup>(), get.Get <IRadicalSearcher>(),
                                                     get.Get <KanjiRadicalLookup>()));
            kernel.Bind(get =>
            {
                using (var reader = File.OpenText(Path.Combine(dataDirectory, "character", "radkfile1_plus_2_utf8")))
                    return(new KanjiRadicalLookup(Radkfile.Parse(reader), get.Get <KanjiDict>()));
            });
            kernel.Bind(get => new DisclaimersGetter(Path.Combine(dataDirectory, @"about.txt")));
            kernel.Bind <IJGramLookup, JGramLookup>();
            kernel.Bind(get => new JGramLookup(
                            Path.Combine(dataDirectory, "dictionaries", "jgram"),
                            Path.Combine(dataDirectory, "dictionaries", "jgram_lookup"),
                            Path.Combine(cacheDirectory, "dictionaries", "jgram.cache")));
            kernel.Bind(get =>
                        new RadkfileKanjiAliveCorrelator(Path.Combine(dataDirectory, "character",
                                                                      "radkfile_kanjilive_correlation_data.txt")));
            kernel.Bind <IRadicalSearcher, RadicalSearcher>();
            kernel.Bind(get => new RadicalSearcher(
                            get.Get <KanjiRadicalLookup>().AllRadicals,
                            get.Get <KanjiAliveJapaneseRadicalInformation>(),
                            get.Get <RadkfileKanjiAliveCorrelator>()));
            kernel.Bind(get => new Corpus(get.Get <Tanaka>().AllSentences,
                                          get.Get <IMorphologicalAnalyzer <IpadicEntry> >(), Path.Combine(cacheDirectory, "corpora", "tanaka.cache")));
            kernel.Bind(get => new DataSourceDispatcher(get.Get <IEnumerable <IDataSource> >()));
            kernel.Bind(get => new XmlRichFormattingRenderer());
            kernel.Bind(get => new KanjiAliveJapaneseRadicalInformation(
                            KanjiAliveJapaneseRadicalInformation.Parse(
                                Path.Combine(dataDirectory, "character", "japanese-radicals.csv"))));
            return(dataSourceCollection);
        }
Пример #6
0
        public static Kernel Configure(string dataDir)
        {
            var kernel = new Kernel();

            kernel.Bind(() => KanjiDict.Create(Path.Combine(dataDir, "character", "kanjidic2.xml.gz")));
            kernel.Bind(() => new Kradfile(Path.Combine(dataDir, "character", "kradfile1_plus_2_utf8"), Encoding.UTF8));
            kernel.Bind(() => new Radkfile(Path.Combine(dataDir, "character", "radkfile1_plus_2_utf8"), Encoding.UTF8));
            kernel.Bind(() => JMDictLookup.Create(Path.Combine(dataDir, "dictionaries", "JMdict_e.gz"), Path.Combine(dataDir, "dictionaries", "JMdict_e.cache")));
            kernel.Bind(() => JMNedictLookup.Create(Path.Combine(dataDir, "dictionaries", "JMnedict.xml.gz"), Path.Combine(dataDir, "dictionaries", "JMnedict.xml.cache")));
            kernel.Bind(() =>
                        new FrequencyList(Path.Combine(dataDir, "other", "word_form_frequency_list.txt"), Encoding.UTF8));
            kernel.Bind(() => new Tanaka(Path.Combine(dataDir, "corpora", "examples.utf.gz"), Encoding.UTF8));
            kernel.Bind(() => new JESC(Path.Combine(dataDir, "corpora", "jesc_raw"), Encoding.UTF8));
            kernel.Bind(() => new BasicExpressionsCorpus(Path.Combine(dataDir, "corpora", "JEC_basic_sentence_v1-2.csv"), Encoding.UTF8));
            kernel.Bind <IFontResolver>(() => new DefaultFontResolver(Path.Combine(dataDir, "character", "KanjiStrokeOrders")));
            kernel.Bind <IMorphologicalAnalyzer <IpadicEntry> >(() => new MeCabIpadic(new MeCabParam
            {
                DicDir = Path.Combine(dataDir, "mecab", "ipadic"),
                UseMemoryMappedFile = true
            }));
            kernel.Bind <IMorphologicalAnalyzer <UnidicEntry> >(() => new MeCabUnidic(new MeCabParam
            {
                DicDir = Path.Combine(dataDir, "mecab", "unidic"),
                UseMemoryMappedFile = true
            }));
            kernel.Bind <IMorphologicalAnalyzer <IEntry> >(get =>
            {
                // not sure if objects created this way will be disposed twice
                // probably doesn't matter (IDisposable.Dispose's contract says
                // it's not a problem), but still
                try
                {
                    return(get.Get <IMorphologicalAnalyzer <UnidicEntry> >());
                }
                catch (Exception)
                {
                    return(get.Get <IMorphologicalAnalyzer <IpadicEntry> >());
                }
            });
            kernel.Bind <Models.Settings>(get =>
            {
                try
                {
                    return(JsonConvert.DeserializeObject <Models.Settings>(File.ReadAllText("settings.config")));
                }
                catch (FileNotFoundException)
                {
                    return(Models.Settings.CreateDefault());
                }
            });
            kernel.Bind(get => new ReplRootModule(
                            get.Get <JMDictLookup>(),
                            get.Get <JMNedictLookup>(),
                            new ReplCorpora(
                                get.Get <BasicExpressionsCorpus>(),
                                get.Get <Tanaka>(),
                                get.Get <JESC>())));
            kernel.Bind(get => new RadicalRemapper(get.Get <Kradfile>(), get.Get <Radkfile>()));
            kernel.Bind(get => EasilyConfusedKana.FromFile(Path.Combine(dataDir, "character", "confused.txt")));
            kernel.Bind <IKanjiProperties, KanjiProperties>();
            kernel.Bind(get => new KanjiProperties(
                            get.Get <KanjiDict>(),
                            get.Get <Kradfile>(),
                            get.Get <Radkfile>(),
                            null));
            kernel.Bind(get => new MainWindowVM(
                            get.Get <ISentenceParser>(),
                            new KanaBoardVM(Path.Combine(dataDir, "character", "hiragana_romaji.txt"), Encoding.UTF8),
                            new KanaBoardVM(Path.Combine(dataDir, "character", "katakana_romaji.txt"), Encoding.UTF8),
                            get.Get <IEnumerable <UsageDataSourcePreviewVM> >(),
                            get.Get <KanjiRadicalLookupControlVM>(),
                            get.Get <IRelated>(),
                            get.Get <IKanjiProperties>(),
                            get.Get <IKanaProperties>(),
                            get.Get <IWebBrowser>(),
                            () =>
            {
                var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)
                              .ProductVersion;
                return
                ($"Didactical Enigma {version}\n\n{File.ReadAllText(Path.Combine(dataDir, @"about.txt"), Encoding.UTF8)}");
            },
                            get.Get <ITextInsertCommand>(),
                            get.Get <Models.Settings>(),
                            get.Get <ReplVM>(),
                            get.Get <DidacticalEnigma.Mem.Client.DidacticalEnigmaMemViewModel>()));
            kernel.Bind(get => new KanjiRadicalLookupControlVM(
                            get.Get <KanjiRadicalLookup>(),
                            get.Get <IKanjiProperties>(),
                            get.Get <IRadicalSearcher>(),
                            CreateTextRadicalMappings(get.Get <KanjiRadicalLookup>().AllRadicals, get.Get <RadkfileKanjiAliveCorrelator>())));
            kernel.Bind <IRomaji, ModifiedHepburn>();
            kernel.Bind(get => new ModifiedHepburn(
                            get.Get <IMorphologicalAnalyzer <IEntry> >(),
                            get.Get <IKanaProperties>()));
            kernel.Bind <IAutoGlosser, AutoGlosserNext>();
            kernel.Bind(get => new AutoGlosserNext(get.Get <ISentenceParser>(), get.Get <JMDictLookup>(), get.Get <IKanaProperties>()));
            kernel.Bind(get => new[] {
                new DataSourceVM(new CharacterDataSource(get.Get <IKanjiProperties>(), get.Get <IKanaProperties>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new CharacterStrokeOrderDataSource(), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new JMDictDataSource(get.Get <JMDictLookup>(), get.Get <IKanaProperties>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new JNeDictDataSource(get.Get <JMNedictLookup>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new VerbConjugationDataSource(get.Get <JMDictLookup>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new WordFrequencyRatingDataSource(get.Get <FrequencyList>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new PartialExpressionJMDictDataSource(get.Get <IdiomDetector>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new JGramDataSource(get.Get <IJGramLookup>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new AutoGlosserDataSource(get.Get <IAutoGlosser>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new CustomNotesDataSource(Path.Combine(dataDir, "custom", "custom_notes.txt")), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new TanakaCorpusFastDataSource(get.Get <Corpus>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new TanakaCorpusDataSource(get.Get <Tanaka>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new BasicExpressionCorpusDataSource(get.Get <BasicExpressionsCorpus>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new PartialWordLookupJMDictDataSource(get.Get <PartialWordLookup>(), get.Get <FrequencyList>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new JESCDataSource(get.Get <JESC>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new RomajiDataSource(get.Get <IRomaji>()), get.Get <IFlowDocumentRichFormattingRenderer>()),
                new DataSourceVM(new DidacticalEnigmaMemDataSource(get.Get <DidacticalEnigma.Mem.Client.DidacticalEnigmaMemViewModel>().ClientAccessor), get.Get <IFlowDocumentRichFormattingRenderer>())
            }.Concat(get.Get <EpwingDictionaries>().Dictionaries.Select(dict => new DataSourceVM(new EpwingDataSource(dict, get.Get <IKanaProperties>()), get.Get <IFlowDocumentRichFormattingRenderer>(), dict.Revision))));
            kernel.Bind <IKanaProperties, KanaProperties2>();
            kernel.Bind(get => new KanaProperties2(Path.Combine(dataDir, "character", "kana.txt"), Encoding.UTF8));
            kernel.Bind(get => new SimilarKanji(Path.Combine(dataDir, "character", "kanji.tgz_similars.ut8"), Encoding.UTF8));
            kernel.Bind(get => new SentenceParser(get.Get <IMorphologicalAnalyzer <IEntry> >(), get.Get <JMDictLookup>()));
            kernel.Bind <ISentenceParser, SentenceParser>();
            kernel.Bind <IRelated>(get =>
                                   new CompositeRelated(
                                       get.Get <KanaProperties2>(),
                                       get.Get <EasilyConfusedKana>(),
                                       get.Get <SimilarKanji>()));
            kernel.Bind <IEnumerable <UsageDataSourcePreviewVM> >(get => new [] {
                new UsageDataSourcePreviewVM(get.Get <IEnumerable <DataSourceVM> >(), "view.config"),
                new UsageDataSourcePreviewVM(get.Get <IEnumerable <DataSourceVM> >(), "view_2.config"),
                new UsageDataSourcePreviewVM(get.Get <IEnumerable <DataSourceVM> >(), "view_3.config")
            });
            kernel.Bind(get => CreateEpwing(Path.Combine(dataDir, "epwing")));
            kernel.Bind(get => new IdiomDetector(get.Get <JMDictLookup>(), get.Get <IMorphologicalAnalyzer <IpadicEntry> >(), Path.Combine(dataDir, "dictionaries", "idioms.cache")));
            kernel.Bind(get => new PartialWordLookup(get.Get <JMDictLookup>(), get.Get <IRadicalSearcher>(), get.Get <KanjiRadicalLookup>()));
            kernel.Bind(get =>
            {
                using (var reader = File.OpenText(Path.Combine(dataDir, "character", "radkfile1_plus_2_utf8")))
                    return(new KanjiRadicalLookup(Radkfile.Parse(reader), get.Get <KanjiDict>()));
            });
            kernel.Bind <IWebBrowser>(get => new WebBrowser());
            kernel.Bind <IFlowDocumentRichFormattingRenderer>(get => new FlowDocumentRichFormattingRenderer(get.Get <IFontResolver>(), get.Get <IWebBrowser>()));
            kernel.Bind <IJGramLookup>(get => new JGramLookup(
                                           Path.Combine(dataDir, "dictionaries", "jgram"),
                                           Path.Combine(dataDir, "dictionaries", "jgram_lookup"),
                                           Path.Combine(dataDir, "dictionaries", "jgram.cache")));
            kernel.Bind(get => new RadkfileKanjiAliveCorrelator(Path.Combine(dataDir, "character", "radkfile_kanjilive_correlation_data.txt")));
            kernel.Bind <IRadicalSearcher, RadicalSearcher>();
            kernel.Bind(get => new RadicalSearcher(
                            get.Get <KanjiRadicalLookup>().AllRadicals,
                            KanjiAliveJapaneseRadicalInformation.Parse(Path.Combine(dataDir, "character", "japanese-radicals.csv")),
                            get.Get <RadkfileKanjiAliveCorrelator>()));
            kernel.Bind(get => new Corpus(get.Get <Tanaka>().AllSentences, get.Get <IMorphologicalAnalyzer <IpadicEntry> >(), Path.Combine(dataDir, "corpora", "tanaka.cache")));

            kernel.Bind(get => new DidacticalEnigma.Mem.Client.DidacticalEnigmaMemViewModel());
            return(kernel);

            IReadOnlyDictionary <CodePoint, string> CreateTextRadicalMappings(IEnumerable <CodePoint> radicals, IReadOnlyDictionary <int, int> remapper)
            {
                var dict = radicals.ToDictionary(
                    r => r,
                    r => char.ConvertFromUtf32(remapper.GetValueOrNone(r.Utf32).ValueOr(r.Utf32)));

                /*var d = new Dictionary<int, int>
                 * {
                 *  {'化', '⺅'},
                 *  {'刈', '⺉'},
                 *  {'込', '⻌'},
                 *  {'汁', '氵'},
                 *  {'初', '衤'},
                 *  {'尚', '⺌'},
                 *  {'買', '罒'},
                 *  {'犯', '犭'},
                 *  {'忙', '忄'},
                 *  {'礼', '礻'},
                 *  {'个', 131490},
                 *  {'老', '⺹'},
                 *  {'扎', '扌'},
                 *  {'杰', '灬'},
                 *  {'疔', '疒'},
                 *  {'禹', '禸'},
                 *  {'艾', '⺾'},
                 *  //{'邦', '⻏'},
                 *  //{'阡', '⻖'},
                 *  // 并 none available - upside-down ハ
                 * };*/
                dict[CodePoint.FromInt('邦')] = "邦";
                dict[CodePoint.FromInt('阡')] = "阡";
                dict[CodePoint.FromInt('老')] = "⺹";
                dict[CodePoint.FromInt('并')] = "丷";
                dict[CodePoint.FromInt('乞')] = "𠂉";
                return(dict);
            }

            EpwingDictionaries CreateEpwing(string targetPath)
            {
                var dictionaries = new EpwingDictionaries();

                try
                {
                    var zipFiles = new Dictionary <string, ZipFile2>();
                    try
                    {
                        zipFiles = Directory.EnumerateFiles(targetPath, "*.zip")
                                   .ToDictionary(path => path, path => new ZipFile2(path));
                        var dicts = zipFiles
                                    .Select(file => new YomichanTermDictionary(file.Value, file.Key + ".cache"));
                        foreach (var dict in dicts)
                        {
                            dictionaries.Add(dict);
                        }
                    }
                    finally
                    {
                        foreach (var entry in zipFiles)
                        {
                            entry.Value.Dispose();
                        }
                    }
                }
                catch (DirectoryNotFoundException)
                {
                }
                catch (InvalidOperationException ex)
                {
                    MessageBox.Show(
                        ex.Message + "\nIt was not possible to load the EPWING external dictionary.",
                        "Error",
                        MessageBoxButton.OK,
                        MessageBoxImage.Warning);
                }

                return(dictionaries);
            }
        }
Пример #7
0
        public static Kernel Configure(string dataDir)
        {
            var kernel = new Kernel();

            kernel.BindFactory(() => KanjiDict.Create(Path.Combine(dataDir, "character", "kanjidic2.xml.gz")));
            kernel.BindFactory(() => new JDict.Kradfile(Path.Combine(dataDir, "character", "kradfile1_plus_2_utf8"), Encoding.UTF8));
            kernel.BindFactory(() => new Radkfile(Path.Combine(dataDir, "character", "radkfile1_plus_2_utf8"), Encoding.UTF8));
            kernel.BindFactory(() => JMDictLookup.Create(Path.Combine(dataDir, "dictionaries", "JMdict_e.gz"), Path.Combine(dataDir, "dictionaries", "JMdict_e.cache")));
            kernel.BindFactory(() => JMNedictLookup.Create(Path.Combine(dataDir, "dictionaries", "JMnedict.xml.gz"), Path.Combine(dataDir, "dictionaries", "JMnedict.xml.cache")));
            kernel.BindFactory(() =>
                               new FrequencyList(Path.Combine(dataDir, "other", "word_form_frequency_list.txt"), Encoding.UTF8));
            kernel.BindFactory(() => new Tanaka(Path.Combine(dataDir, "corpora", "examples.utf.gz"), Encoding.UTF8));
            kernel.BindFactory(() => new JESC(Path.Combine(dataDir, "corpora", "jesc_raw"), Encoding.UTF8));
            kernel.BindFactory(() => new BasicExpressionsCorpus(Path.Combine(dataDir, "corpora", "JEC_basic_sentence_v1-2.csv"), Encoding.UTF8));
            kernel.BindFactory <IMorphologicalAnalyzer <IpadicEntry> >(() => new MeCabIpadic(new MeCabParam
            {
                DicDir = Path.Combine(dataDir, "mecab", "ipadic")
            }));
            kernel.Bind <IMorphologicalAnalyzer <IEntry>, IMorphologicalAnalyzer <IpadicEntry> >();
            kernel.BindFactory(get => new RadicalRemapper(get.Get <JDict.Kradfile>(), get.Get <Radkfile>()));
            kernel.BindFactory(get => EasilyConfusedKana.FromFile(Path.Combine(dataDir, "character", "confused.txt")));
            kernel.Bind <IKanjiProperties, KanjiProperties>();
            kernel.BindFactory(get => new KanjiProperties(
                                   get.Get <KanjiDict>(),
                                   get.Get <JDict.Kradfile>(),
                                   get.Get <Radkfile>(),
                                   null));
            kernel.Bind <IRomaji, ModifiedHepburn>();
            kernel.BindFactory(get => new ModifiedHepburn(
                                   get.Get <IMorphologicalAnalyzer <IEntry> >(),
                                   get.Get <IKanaProperties>()));
            kernel.BindFactory(get => new AutoGlosserNext(get.Get <ISentenceParser>(), get.Get <JMDictLookup>(), get.Get <IKanaProperties>()));
            kernel.Bind <IKanaProperties, KanaProperties2>();
            kernel.BindFactory(get => new KanaProperties2(Path.Combine(dataDir, "character", "kana.txt"), Encoding.UTF8));
            kernel.BindFactory(get => new SimilarKanji(Path.Combine(dataDir, "character", "kanji.tgz_similars.ut8"), Encoding.UTF8));
            kernel.BindFactory <IRelated>(get =>
                                          new CompositeRelated(
                                              get.Get <KanaProperties2>(),
                                              get.Get <EasilyConfusedKana>(),
                                              get.Get <SimilarKanji>()));
            kernel.BindFactory(get => CreateEpwing(Path.Combine(dataDir, "epwing")));
            kernel.BindFactory(get => new IdiomDetector(get.Get <JMDictLookup>(), get.Get <IMorphologicalAnalyzer <IpadicEntry> >(), Path.Combine(dataDir, "dictionaries", "idioms.cache")));
            kernel.BindFactory(get => new PartialWordLookup(get.Get <JMDictLookup>(), get.Get <IRadicalSearcher>(), get.Get <KanjiRadicalLookup>()));
            kernel.BindFactory(get =>
            {
                using (var reader = File.OpenText(Path.Combine(dataDir, "character", "radkfile1_plus_2_utf8")))
                    return(new KanjiRadicalLookup(Radkfile.Parse(reader), get.Get <KanjiDict>()));
            });

            kernel.BindFactory <IJGramLookup>(get => new JGramLookup(
                                                  Path.Combine(dataDir, "dictionaries", "jgram"),
                                                  Path.Combine(dataDir, "dictionaries", "jgram_lookup"),
                                                  Path.Combine(dataDir, "dictionaries", "jgram.cache")));
            kernel.BindFactory(get => new RadkfileKanjiAliveCorrelator(Path.Combine(dataDir, "character", "radkfile_kanjilive_correlation_data.txt")));
            kernel.Bind <IRadicalSearcher, RadicalSearcher>();
            kernel.BindFactory(get => new SentenceParser(get.Get <IMorphologicalAnalyzer <IEntry> >(), get.Get <JMDictLookup>(), get.Get <IKanaProperties>()));
            kernel.Bind <ISentenceParser, SentenceParser>();
            kernel.BindFactory(get => new RadicalSearcher(
                                   get.Get <KanjiRadicalLookup>().AllRadicals,
                                   KanjiAliveJapaneseRadicalInformation.Parse(Path.Combine(dataDir, "character", "japanese-radicals.csv")),
                                   get.Get <RadkfileKanjiAliveCorrelator>()));
            kernel.BindFactory(get => new Corpus(get.Get <Tanaka>().AllSentences, get.Get <IMorphologicalAnalyzer <IpadicEntry> >(), Path.Combine(dataDir, "corpora", "tanaka.cache")));

            /*
             * kernel.BindFactory<IFontResolver>(() => new DefaultFontResolver(Path.Combine(dataDir, "character", "KanjiStrokeOrders")));
             * kernel.BindFactory(get => new MainWindowVM(
             *  get.Get<IMorphologicalAnalyzer<IEntry>>(),
             *  new KanaBoardVM(Path.Combine(dataDir, "character", "hiragana_romaji.txt"), Encoding.UTF8),
             *  new KanaBoardVM(Path.Combine(dataDir, "character", "katakana_romaji.txt"), Encoding.UTF8),
             *  get.Get<IEnumerable<UsageDataSourcePreviewVM>>(),
             *  get.Get<KanjiRadicalLookupControlVM>(),
             *  get.Get<IRelated>(),
             *  get.Get<IKanjiProperties>(),
             *  get.Get<IKanaProperties>(),
             *  get.Get<IWebBrowser>(),
             *  () => File.ReadAllText(Path.Combine(dataDir, @"about.txt"), Encoding.UTF8),
             *  get.Get<ITextInsertCommand>()));
             * kernel.BindFactory(get => new KanjiRadicalLookupControlVM(
             *  get.Get<KanjiRadicalLookup>(),
             *  get.Get<IKanjiProperties>(),
             *  get.Get<IRadicalSearcher>(),
             *  CreateTextRadicalMappings(get.Get<KanjiRadicalLookup>().AllRadicals, get.Get<RadkfileKanjiAliveCorrelator>())));
             * kernel.BindFactory(get => new[] {
             *  new DataSourceVM(new CharacterDataSource(get.Get<IKanjiProperties>(), get.Get<IKanaProperties>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new CharacterStrokeOrderDataSource(), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new JMDictDataSource(get.Get<JMDict>(), get.Get<IKanaProperties>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new JNeDictDataSource(get.Get<Jnedict>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new VerbConjugationDataSource(get.Get<JMDict>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new WordFrequencyRatingDataSource(get.Get<FrequencyList>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new PartialExpressionJMDictDataSource(get.Get<IdiomDetector>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new JGramDataSource(get.Get<IJGramLookup>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new AutoGlosserDataSource(get.Get<AutoGlosser>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new CustomNotesDataSource(Path.Combine(dataDir, "custom", "custom_notes.txt")), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new TanakaCorpusFastDataSource(get.Get<Corpus>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new TanakaCorpusDataSource(get.Get<Tanaka>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new BasicExpressionCorpusDataSource(get.Get<BasicExpressionsCorpus>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new PartialWordLookupJMDictDataSource(get.Get<PartialWordLookup>(), get.Get<FrequencyList>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new JESCDataSource(get.Get<JESC>()), get.Get<IFlowDocumentRichFormattingRenderer>()),
             *  new DataSourceVM(new RomajiDataSource(get.Get<IRomaji>()), get.Get<IFlowDocumentRichFormattingRenderer>())
             * }.Concat(get.Get<EpwingDictionaries>().Dictionaries.Select(dict => new DataSourceVM(new EpwingDataSource(dict, get.Get<IKanaProperties>()), get.Get<IFlowDocumentRichFormattingRenderer>(), dict.Revision))));
             * kernel.BindFactory<IEnumerable<UsageDataSourcePreviewVM>>(get => new[]{
             *  new UsageDataSourcePreviewVM(get.Get<IEnumerable<DataSourceVM>>(), "view.config"),
             *  new UsageDataSourcePreviewVM(get.Get<IEnumerable<DataSourceVM>>(), "view_2.config"),
             *  new UsageDataSourcePreviewVM(get.Get<IEnumerable<DataSourceVM>>(), "view_3.config")
             * });
             * kernel.BindFactory<IWebBrowser>(get => new WebBrowser());
             * kernel.BindFactory<IFlowDocumentRichFormattingRenderer>(get => new FlowDocumentRichFormattingRenderer(get.Get<IFontResolver>(), get.Get<IWebBrowser>()));
             */

            return(kernel);

            IReadOnlyDictionary <CodePoint, string> CreateTextRadicalMappings(IEnumerable <CodePoint> radicals, IReadOnlyDictionary <int, int> remapper)
            {
                var dict = radicals.ToDictionary(
                    r => r,
                    r => char.ConvertFromUtf32(remapper.GetValueOrNone(r.Utf32).ValueOr(r.Utf32)));

                /*var d = new Dictionary<int, int>
                 * {
                 *  {'化', '⺅'},
                 *  {'刈', '⺉'},
                 *  {'込', '⻌'},
                 *  {'汁', '氵'},
                 *  {'初', '衤'},
                 *  {'尚', '⺌'},
                 *  {'買', '罒'},
                 *  {'犯', '犭'},
                 *  {'忙', '忄'},
                 *  {'礼', '礻'},
                 *  {'个', 131490},
                 *  {'老', '⺹'},
                 *  {'扎', '扌'},
                 *  {'杰', '灬'},
                 *  {'疔', '疒'},
                 *  {'禹', '禸'},
                 *  {'艾', '⺾'},
                 *  //{'邦', '⻏'},
                 *  //{'阡', '⻖'},
                 *  // 并 none available - upside-down ハ
                 * };*/
                dict[CodePoint.FromInt('邦')] = "邦";
                dict[CodePoint.FromInt('阡')] = "阡";
                dict[CodePoint.FromInt('老')] = "⺹";
                dict[CodePoint.FromInt('并')] = "丷";
                dict[CodePoint.FromInt('乞')] = "𠂉";
                return(dict);
            }

            EpwingDictionaries CreateEpwing(string targetPath)
            {
                var dictionaries = new EpwingDictionaries();

                try
                {
                    var dicts = Directory.EnumerateFiles(targetPath, "*.zip")
                                .Select(file => new YomichanTermDictionary(file, file + ".cache"));
                    foreach (var dict in dicts)
                    {
                        dictionaries.Add(dict);
                    }
                }
                catch (DirectoryNotFoundException)
                {
                }
                catch (InvalidOperationException ex)
                {
                    throw new InvalidOperationException(ex.Message + "\nIt was not possible to load the EPWING external dictionary.");
                }

                return(dictionaries);
            }
        }
Пример #8
0
 public void SetUp()
 {
     jmNedictLookup = JMNedictLookup.Create(TestDataPaths.JMnedict, TestDataPaths.JMnedictCache);
 }