public void SetUp() { if (Directory.Exists(TestUtils.CompiledPath)) { Directory.Delete(TestUtils.CompiledPath, true); } Directory.CreateDirectory(TestUtils.CompiledPath); using (var outputStream = File.Create(charDef)) { CharacterDefinitionsCompiler compiler = new CharacterDefinitionsCompiler(CodePagesEncodingProvider.Instance); string assetFileName = @"./Core/Resource/char.def"; using (var defStream = File.OpenRead(assetFileName)) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); compiler.ReadCharacterDefinition(defStream, "euc-jp"); categoryIdMap = Invert(compiler.MakeCharacterCategoryMap()); compiler.Compile(outputStream); } } using (var input = File.OpenRead(charDef)) using (BinaryReader reader = new BinaryReader(input)) { int[][] definitions = IntegerArrayIO.ReadSparseArray2D(reader); int[][] mappings = IntegerArrayIO.ReadSparseArray2D(reader); string[] symbols = StringArrayIO.ReadArray(reader); characterDefinition = new CharacterDefinitions(definitions, mappings, symbols); } }
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); } }
public void Setup() { CharDefFileName = Path.GetTempFileName(); using (var fs = new FileStream(CharDefFileName, FileMode.Create, FileAccess.ReadWrite)) using (var resource = GetResource("char.def")) { var compiler = new CharacterDefinitionsCompiler(fs); compiler.ReadCharacterDefinition(resource, Encoding.GetEncoding("euc-jp")); CategoryIdMap = Invert(compiler.MakeCharacterCategoryMap()); compiler.Compile(); } using (var fs = new FileStream(CharDefFileName, FileMode.Open, FileAccess.Read)) { var definitions = IntArrayIO.ReadSparseArray2D(fs); var mappings = IntArrayIO.ReadSparseArray2D(fs); var symbols = StringArrayIO.ReadArray(fs); CharacterDefinition = new CharacterDefinitions(definitions, mappings, symbols); } }