Ejemplo n.º 1
0
        private static void ParseKanjiDict2(string file, string xsdFile)
        {
            var schemaSet = new XmlSchemaSet();

            schemaSet.ValidationEventHandler += ValidationCallback;
            schemaSet.Add("http://www.kanjidic2x.xsd", xsdFile);
            schemaSet.Compile();

            var settings = new XmlReaderSettings
            {
                Schemas        = schemaSet,
                ValidationType = ValidationType.Schema,
                DtdProcessing  = DtdProcessing.Parse,
            };

            XmlReader reader = XmlReader.Create(file, settings);

            var             dictReader = new KanjiDictReader();
            HashSet <Kanji> kanjis     = dictReader.GetAllKanji(reader);

            var kanjiLevelsDictionary = new Dictionary <int, List <Kanji> >
            {
                { 0, new List <Kanji>() },
                { 1, new List <Kanji>() },
                { 2, new List <Kanji>() },
                { 3, new List <Kanji>() },
                { 4, new List <Kanji>() },
                { 5, new List <Kanji>() }
            };

            foreach (Kanji kanji in kanjis)
            {
                kanjiLevelsDictionary[kanji.JLPT].Add(kanji);
            }

            for (int i = 0; i < kanjiLevelsDictionary.Count; i++)
            {
                var ankiWriter = new AnkiImportCreator(3, 3);

                using (
                    var fs = new FileStream(@"C:\dev\KanjiDicReader\KanjiDicReader\dictionary\kanjidic2-" + i + ".csv", FileMode.Create,
                                            FileAccess.Write))
                {
                    ankiWriter.WriteImportStream(fs, kanjiLevelsDictionary[i]);
                }
            }
        }
Ejemplo n.º 2
0
        private static void ParseJMDict(string file)
        {
            var settings = new XmlReaderSettings
            {
                ValidationType = ValidationType.DTD,
                DtdProcessing  = DtdProcessing.Parse,
            };
            XmlReader reader            = XmlReader.Create(file, settings);
            var       dictReader        = new JMDictReader();
            var       hashsetOfWords    = dictReader.GetAllWords(reader);
            var       ankiImportCreator = new AnkiImportCreator(3, 3);

            using (var fs = new FileStream(@"C:\dev\KanjiDicReader\KanjiDicReader\dictionary\JMDict\jmdict-out.csv", FileMode.Create, FileAccess.Write))
            {
                ankiImportCreator.WriteImportStream(fs, hashsetOfWords);
            }
        }