public void SetUp()
        {
            SortedDictionary <string, int> categoryMap;

            using (var outputStream = File.Create(charDef))
            {
                CharacterDefinitionsCompiler charDefCompiler = new CharacterDefinitionsCompiler(CodePagesEncodingProvider.Instance);
                string assetFileName = @"./Core/Resource/char.def";
                using (var defStream = File.OpenRead(assetFileName))
                {
                    charDefCompiler.ReadCharacterDefinition(defStream, "euc-jp");
                    charDefCompiler.Compile(outputStream);
                }

                categoryMap = charDefCompiler.MakeCharacterCategoryMap();
            }

            var unkDefFile = TestUtils.CompiledPath + Path.DirectorySeparatorChar + "kuromoji-unkdef-.bin";

            using (var outputStream = File.Create(unkDefFile))
            {
                UnknownDictionaryCompiler unkDefCompiler = new UnknownDictionaryCompiler(categoryMap);
                string assetFileName = @"./Core/Resource/unk.def";
                using (var defStream = File.OpenRead(assetFileName))
                {
                    unkDefCompiler.ReadUnknownDefinition(defStream, "euc-jp");
                    unkDefCompiler.Compile(outputStream);
                }
            }

            using (var charDefInput = File.OpenRead(charDef))
                using (var reader = new BinaryReader(charDefInput))
                {
                    int[][]  definitions = IntegerArrayIO.ReadSparseArray2D(reader);
                    int[][]  mappings    = IntegerArrayIO.ReadSparseArray2D(reader);
                    string[] symbols     = StringArrayIO.ReadArray(reader);

                    characterDefinitions = new CharacterDefinitions(definitions, mappings, symbols);
                }

            using (var unkDefInput = File.OpenRead(unkDefFile))
                using (var reader = new BinaryReader(unkDefInput))
                {
                    costs      = IntegerArrayIO.ReadArray2D(reader);
                    references = IntegerArrayIO.ReadArray2D(reader);
                    features   = StringArrayIO.ReadArray2D(reader);

                    unknownDictionary = new UnknownDictionary(characterDefinitions, references, costs, features);
                }
        }
コード例 #2
0
        public static UnknownDictionary NewInstance(string absoluteFolderPath,
                                                    CharacterDefinitions characterDefinitions,
                                                    int totalFeatures)
        {
            string filePath = absoluteFolderPath + Path.DirectorySeparatorChar + UnknownDictionary.UNKNOWN_DICTIONARY_FILENAME;

            using (Stream unkDefInput = File.OpenRead(filePath))
                using (BinaryReader reader = new BinaryReader(unkDefInput))
                {
                    int[][]    costs      = IntegerArrayIO.ReadArray2D(reader);
                    int[][]    references = IntegerArrayIO.ReadArray2D(reader);
                    string[][] features   = StringArrayIO.ReadArray2D(reader);

                    UnknownDictionary unknownDictionary = new UnknownDictionary(
                        characterDefinitions,
                        references,
                        costs,
                        features,
                        totalFeatures
                        );

                    return(unknownDictionary);
                }
        }