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); } }