public static void Setup(TestContext context)
        {
            using (var charDefOutput = new MemoryStream())
                using (var unkDicOutput = new MemoryStream())
                    using (var charDefResource = GetResource("char.def"))
                        using (var unkDefResource = GetResource("unk.def"))
                        {
                            var charDefCompiler = new CharacterDefinitionsCompiler(charDefOutput);
                            charDefCompiler.ReadCharacterDefinition(charDefResource, Encoding.GetEncoding("euc-jp"));
                            charDefCompiler.Compile();

                            var categoryMap = charDefCompiler.MakeCharacterCategoryMap();

                            var unkDefCompiler = new UnknownDictionaryCompiler(unkDicOutput, categoryMap);
                            unkDefCompiler.ReadUnknownDefinition(unkDefResource, Encoding.GetEncoding("euc-jp"));
                            unkDefCompiler.Compile();

                            charDefOutput.Seek(0, SeekOrigin.Begin);
                            unkDicOutput.Seek(0, SeekOrigin.Begin);

                            var definitions = IntArrayIO.ReadSparseArray2D(charDefOutput);
                            var mappings    = IntArrayIO.ReadSparseArray2D(charDefOutput);
                            var symbols     = StringArrayIO.ReadArray(charDefOutput);

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

                            Costs      = IntArrayIO.ReadArray2D(unkDicOutput);
                            References = IntArrayIO.ReadArray2D(unkDicOutput);
                            Features   = StringArrayIO.ReadArray2D(unkDicOutput);

                            UnknownDictionary = new UnknownDictionary(CharacterDefinitions, References, Costs, Features);
                        }
        }
        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);
                }
        }
Ejemplo n.º 3
0
        public static UnknownDictionary NewInstance(IResourceResolver resolver, CharacterDefinitions characterDefinitions, int totalFeatures)
        {
            using (var unkDefInput = resolver.Resolve(UnknownDictionaryFileName))
            {
                var costs      = IntArrayIO.ReadArray2D(unkDefInput);
                var references = IntArrayIO.ReadArray2D(unkDefInput);
                var features   = StringArrayIO.ReadArray2D(unkDefInput);

                return(new UnknownDictionary(
                           characterDefinitions,
                           references,
                           costs,
                           features,
                           totalFeatures
                           ));
            }
        }
        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);
                }
        }