• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisionebc3b4203933f6c0bece593021d12e3ee78c0b4f (tree)
Zeit2016-10-26 21:23:11
Autorazyobuzin <azyobuzin@user...>
Commiterazyobuzin

Log Message

DicDir の Func<Stream> 化に成功

Ändern Zusammenfassung

Diff

--- a/src/LibNMeCab/Core/Connector.cs
+++ b/src/LibNMeCab/Core/Connector.cs
@@ -35,8 +35,15 @@ namespace NMeCab.Core
3535
3636 public void Open(MeCabParam param)
3737 {
38+#if STREAM
39+ using (var reader = new BinaryReader(param.Matrix()))
40+ {
41+ this.Open(reader);
42+ }
43+#else
3844 string fileName = Path.Combine(param.DicDir, MatrixFile);
3945 this.Open(fileName);
46+#endif
4047 }
4148
4249 #if MMF_MTX
--- a/src/LibNMeCab/Core/Tokenizer.cs
+++ b/src/LibNMeCab/Core/Tokenizer.cs
@@ -4,8 +4,8 @@
44 // Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
55 using System;
66 using System.Collections.Generic;
7-using System.Text;
87 using System.IO;
8+using System.Text;
99 #if NeedId
1010 using System.Threading;
1111 #endif
@@ -47,16 +47,35 @@ namespace NMeCab.Core
4747 {
4848 this.dic = new MeCabDictionary[param.UserDic.Length + 1];
4949
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
5061 string prefix = param.DicDir;
5162
5263 this.property.Open(prefix);
5364
5465 this.unkDic.Open(Path.Combine(prefix, UnkDicFile));
66+#endif
5567 if (this.unkDic.Type != DictionaryType.Unk)
5668 throw new MeCabInvalidFileException("not a unk dictionary", this.unkDic.FileName);
5769
5870 MeCabDictionary sysDic = new MeCabDictionary();
71+#if STREAM
72+ using(var reader = new BinaryReader(param.SysDic()))
73+ {
74+ sysDic.Open(reader);
75+ }
76+#else
5977 sysDic.Open(Path.Combine(prefix, SysDicFile));
78+#endif
6079 if (sysDic.Type != DictionaryType.Sys)
6180 throw new MeCabInvalidFileException("not a system dictionary", sysDic.FileName);
6281 this.dic[0] = sysDic;
@@ -64,7 +83,14 @@ namespace NMeCab.Core
6483 for (int i = 0; i < param.UserDic.Length; i++)
6584 {
6685 MeCabDictionary d = new MeCabDictionary();
86+#if STREAM
87+ using (var reader = new BinaryReader(param.UserDic[i]()))
88+ {
89+ d.Open(reader);
90+ }
91+#else
6792 d.Open(Path.Combine(prefix, param.UserDic[i]));
93+#endif
6894 if (d.Type != DictionaryType.Usr)
6995 throw new MeCabInvalidFileException("not a user dictionary", d.FileName);
7096 if (!sysDic.IsCompatible(d))
--- a/src/LibNMeCab/MeCabParam.cs
+++ b/src/LibNMeCab/MeCabParam.cs
@@ -4,9 +4,9 @@
44 // Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
55 using System;
66 using System.Collections.Generic;
7+using System.IO;
78 using System.Text;
89 using NMeCab.Core;
9-using System.IO;
1010
1111 namespace NMeCab
1212 {
@@ -15,8 +15,9 @@ namespace NMeCab
1515 #if STREAM
1616 public Func<Stream> UnkDic { get; set; }
1717 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; }
1919 public Func<Stream> CharProperty { get; set; }
20+ public Func<Stream> Matrix { get; set; }
2021 #else
2122 public string DicDir { get; set; }
2223
@@ -69,9 +70,13 @@ namespace NMeCab
6970
7071 public string OutputFormatType { get; set; }
7172
73+#if STREAM
74+ public Func<Stream> Rc { get; set; }
75+#else
7276 public const string DefaultRcFile = "dicrc";
7377
7478 public string RcFile { get; set; }
79+#endif
7580
7681 /// <summary>
7782 /// コンストラクタ
@@ -79,19 +84,42 @@ namespace NMeCab
7984 public MeCabParam()
8085 {
8186 this.Theta = MeCabParam.DefaultTheta;
87+#if !STREAM
8288 this.RcFile = MeCabParam.DefaultRcFile;
89+#endif
8390
8491 Properties.Settings settings = Properties.Settings.Default;
92+#if !STREAM
8593 this.DicDir = settings.DicDir;
8694 this.UserDic = this.SplitStringArray(settings.UserDic, ',');
95+#endif
8796 this.OutputFormatType = settings.OutputFormatType;
8897 }
8998
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
90117 public void LoadDicRC()
91118 {
92119 string rc = Path.Combine(this.DicDir, this.RcFile);
93120 this.Load(rc);
94121 }
122+#endif
95123
96124 public void Load(string path)
97125 {