Revision | ebc3b4203933f6c0bece593021d12e3ee78c0b4f (tree) |
---|---|
Zeit | 2016-10-26 21:23:11 |
Autor | azyobuzin <azyobuzin@user...> |
Commiter | azyobuzin |
DicDir の Func<Stream> 化に成功
@@ -35,8 +35,15 @@ namespace NMeCab.Core | ||
35 | 35 | |
36 | 36 | public void Open(MeCabParam param) |
37 | 37 | { |
38 | +#if STREAM | |
39 | + using (var reader = new BinaryReader(param.Matrix())) | |
40 | + { | |
41 | + this.Open(reader); | |
42 | + } | |
43 | +#else | |
38 | 44 | string fileName = Path.Combine(param.DicDir, MatrixFile); |
39 | 45 | this.Open(fileName); |
46 | +#endif | |
40 | 47 | } |
41 | 48 | |
42 | 49 | #if MMF_MTX |
@@ -4,8 +4,8 @@ | ||
4 | 4 | // Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation |
5 | 5 | using System; |
6 | 6 | using System.Collections.Generic; |
7 | -using System.Text; | |
8 | 7 | using System.IO; |
8 | +using System.Text; | |
9 | 9 | #if NeedId |
10 | 10 | using System.Threading; |
11 | 11 | #endif |
@@ -47,16 +47,35 @@ namespace NMeCab.Core | ||
47 | 47 | { |
48 | 48 | this.dic = new MeCabDictionary[param.UserDic.Length + 1]; |
49 | 49 | |
50 | +#if STREAM | |
51 | + using (var reader = new BinaryReader(param.CharProperty())) | |
52 | + { | |
53 | + this.property.Open(reader); | |
54 | + } | |
55 | + | |
56 | + using(var reader = new BinaryReader(param.UnkDic())) | |
57 | + { | |
58 | + this.unkDic.Open(reader); | |
59 | + } | |
60 | +#else | |
50 | 61 | string prefix = param.DicDir; |
51 | 62 | |
52 | 63 | this.property.Open(prefix); |
53 | 64 | |
54 | 65 | this.unkDic.Open(Path.Combine(prefix, UnkDicFile)); |
66 | +#endif | |
55 | 67 | if (this.unkDic.Type != DictionaryType.Unk) |
56 | 68 | throw new MeCabInvalidFileException("not a unk dictionary", this.unkDic.FileName); |
57 | 69 | |
58 | 70 | MeCabDictionary sysDic = new MeCabDictionary(); |
71 | +#if STREAM | |
72 | + using(var reader = new BinaryReader(param.SysDic())) | |
73 | + { | |
74 | + sysDic.Open(reader); | |
75 | + } | |
76 | +#else | |
59 | 77 | sysDic.Open(Path.Combine(prefix, SysDicFile)); |
78 | +#endif | |
60 | 79 | if (sysDic.Type != DictionaryType.Sys) |
61 | 80 | throw new MeCabInvalidFileException("not a system dictionary", sysDic.FileName); |
62 | 81 | this.dic[0] = sysDic; |
@@ -64,7 +83,14 @@ namespace NMeCab.Core | ||
64 | 83 | for (int i = 0; i < param.UserDic.Length; i++) |
65 | 84 | { |
66 | 85 | MeCabDictionary d = new MeCabDictionary(); |
86 | +#if STREAM | |
87 | + using (var reader = new BinaryReader(param.UserDic[i]())) | |
88 | + { | |
89 | + d.Open(reader); | |
90 | + } | |
91 | +#else | |
67 | 92 | d.Open(Path.Combine(prefix, param.UserDic[i])); |
93 | +#endif | |
68 | 94 | if (d.Type != DictionaryType.Usr) |
69 | 95 | throw new MeCabInvalidFileException("not a user dictionary", d.FileName); |
70 | 96 | if (!sysDic.IsCompatible(d)) |
@@ -4,9 +4,9 @@ | ||
4 | 4 | // Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation |
5 | 5 | using System; |
6 | 6 | using System.Collections.Generic; |
7 | +using System.IO; | |
7 | 8 | using System.Text; |
8 | 9 | using NMeCab.Core; |
9 | -using System.IO; | |
10 | 10 | |
11 | 11 | namespace NMeCab |
12 | 12 | { |
@@ -15,8 +15,9 @@ namespace NMeCab | ||
15 | 15 | #if STREAM |
16 | 16 | public Func<Stream> UnkDic { get; set; } |
17 | 17 | public Func<Stream> SysDic { get; set; } |
18 | - public List<Func<Stream>> UserDic { get; set; } = new List<Func<Stream>>(); | |
18 | + public Func<Stream>[] UserDic { get; set; } | |
19 | 19 | public Func<Stream> CharProperty { get; set; } |
20 | + public Func<Stream> Matrix { get; set; } | |
20 | 21 | #else |
21 | 22 | public string DicDir { get; set; } |
22 | 23 |
@@ -69,9 +70,13 @@ namespace NMeCab | ||
69 | 70 | |
70 | 71 | public string OutputFormatType { get; set; } |
71 | 72 | |
73 | +#if STREAM | |
74 | + public Func<Stream> Rc { get; set; } | |
75 | +#else | |
72 | 76 | public const string DefaultRcFile = "dicrc"; |
73 | 77 | |
74 | 78 | public string RcFile { get; set; } |
79 | +#endif | |
75 | 80 | |
76 | 81 | /// <summary> |
77 | 82 | /// コンストラクタ |
@@ -79,19 +84,42 @@ namespace NMeCab | ||
79 | 84 | public MeCabParam() |
80 | 85 | { |
81 | 86 | this.Theta = MeCabParam.DefaultTheta; |
87 | +#if !STREAM | |
82 | 88 | this.RcFile = MeCabParam.DefaultRcFile; |
89 | +#endif | |
83 | 90 | |
84 | 91 | Properties.Settings settings = Properties.Settings.Default; |
92 | +#if !STREAM | |
85 | 93 | this.DicDir = settings.DicDir; |
86 | 94 | this.UserDic = this.SplitStringArray(settings.UserDic, ','); |
95 | +#endif | |
87 | 96 | this.OutputFormatType = settings.OutputFormatType; |
88 | 97 | } |
89 | 98 | |
99 | +#if STREAM | |
100 | + public void LoadDicRC() | |
101 | + { | |
102 | + using (var reader = new StreamReader(this.Rc(), Encoding.ASCII)) | |
103 | + { | |
104 | + this.Load(reader); | |
105 | + } | |
106 | + } | |
107 | + | |
108 | + public void Load(TextReader rc) | |
109 | + { | |
110 | + var ini = new IniParser(); | |
111 | + ini.Load(rc); | |
112 | + | |
113 | + this.CostFactor = int.Parse(ini["cost-factor"] ?? "0"); | |
114 | + this.BosFeature = ini["bos-feature"]; | |
115 | + } | |
116 | +#else | |
90 | 117 | public void LoadDicRC() |
91 | 118 | { |
92 | 119 | string rc = Path.Combine(this.DicDir, this.RcFile); |
93 | 120 | this.Load(rc); |
94 | 121 | } |
122 | +#endif | |
95 | 123 | |
96 | 124 | public void Load(string path) |
97 | 125 | { |