DepEditで単語クリックにより表示されるLexemeSelectionGrid(単語アサイン変更ダイアログ)にMWE Annotationを統合.
@@ -52,8 +52,9 @@ | ||
52 | 52 | m_LexSelector.BeginSelection(orglex.Surface, orglex); |
53 | 53 | if (m_LexSelector.ShowDialog() == DialogResult.OK) |
54 | 54 | { |
55 | - Lexeme lex = m_LexSelector.Selection; | |
56 | - if (lex != null) | |
55 | + var lex = m_LexSelector.Selection?.Lexeme; | |
56 | + var mwe_match = m_LexSelector.Selection?.Match; | |
57 | + if (lex != null && mwe_match == null) | |
57 | 58 | { |
58 | 59 | var props = lex.ToPropertyArray(); |
59 | 60 | var customprop = lex.CustomProperty; |
@@ -12,6 +12,7 @@ | ||
12 | 12 | public List<int> DepList { get; set; } |
13 | 13 | public MWE MWE { get; set; } |
14 | 14 | public List<CharRange> CharRangeList { get; set; } |
15 | + public Uri Url { get; set; } // 外部辞書でマッチした場合はそのサーバーのURL(Word IDは含まない) | |
15 | 16 | |
16 | 17 | public MatchingResult() |
17 | 18 | { |
@@ -27,5 +28,33 @@ | ||
27 | 28 | select new CharRange(words[r.Start].StartChar - startChar, words[r.End - 1].EndChar - startChar)) |
28 | 29 | .ToList(); |
29 | 30 | } |
31 | + | |
32 | + public static string MWEToString(MWE mwe, IList<Word> words, MatchingResult match) | |
33 | + { | |
34 | + if (words == null) return string.Empty; | |
35 | + | |
36 | + var tokens = new List<string>(); | |
37 | + for (var i = 0; i < mwe.Items.Count; i++) | |
38 | + { | |
39 | + switch (mwe.Items[i].NodeType) | |
40 | + { | |
41 | + case MWENodeType.Word: | |
42 | + tokens.Add(mwe.Items[i].Label); | |
43 | + break; | |
44 | + case MWENodeType.Placeholder: | |
45 | + var w = new List<string>(); | |
46 | + for (var j = match.RangeList[i].Start; j < match.RangeList[i].End; j++) | |
47 | + { | |
48 | + w.Add(words[j].Lex.Surface); | |
49 | + } | |
50 | + tokens.Add($"({string.Join(" ", w)})"); | |
51 | + break; | |
52 | + default: | |
53 | + tokens.Add("*"); | |
54 | + break; | |
55 | + } | |
56 | + } | |
57 | + return string.Join(" ", tokens); | |
58 | + } | |
30 | 59 | } |
31 | 60 | } |
@@ -580,7 +580,8 @@ | ||
580 | 580 | |
581 | 581 | // z-orderレベルの計算 |
582 | 582 | new TopologicalSort<SegmentBox>(m_SegmentBoxes, |
583 | - (x, y) => { | |
583 | + (x, y) => | |
584 | + { | |
584 | 585 | if (x.Range.IsSameStartEnd(y.Range)) |
585 | 586 | { |
586 | 587 | return ((x.Model as Segment).ID > (y.Model as Segment).ID); |
@@ -2276,11 +2277,13 @@ | ||
2276 | 2277 | |
2277 | 2278 | try |
2278 | 2279 | { |
2279 | - m_LexSelector.BeginSelection(wb.Model.Lex.Surface, wb.Model.Lex); | |
2280 | + var words = this.Model.GetWords(this.TargetProjectId); | |
2281 | + m_LexSelector.BeginSelection(wb.Model.Lex.Surface, wb.Model.Lex, words); | |
2280 | 2282 | if (m_LexSelector.ShowDialog() == DialogResult.OK) |
2281 | 2283 | { |
2282 | - Lexeme lex = m_LexSelector.Selection; | |
2283 | - if (lex != null) | |
2284 | + var lex = m_LexSelector.Selection?.Lexeme; | |
2285 | + var mwe_match = m_LexSelector.Selection?.Match; | |
2286 | + if (lex != null && mwe_match == null) | |
2284 | 2287 | { |
2285 | 2288 | try |
2286 | 2289 | { |
@@ -2294,6 +2297,28 @@ | ||
2294 | 2297 | m_Service.ResetTransaction(); |
2295 | 2298 | } |
2296 | 2299 | } |
2300 | + else if (mwe_match != null) | |
2301 | + { | |
2302 | + try | |
2303 | + { | |
2304 | + mwe_match.CalcCharRangeList(words, this.Model.StartChar); | |
2305 | + var op = m_Service.CreateMWEAnnotation(mwe_match, true); | |
2306 | + if (op == null) | |
2307 | + { | |
2308 | + MessageBox.Show("Duplicate segment is prohibited!"); | |
2309 | + } | |
2310 | + else | |
2311 | + { | |
2312 | + UpdateContents(); | |
2313 | + } | |
2314 | + } | |
2315 | + catch (Exception ex) | |
2316 | + { | |
2317 | + ErrorReportDialog dlg = new ErrorReportDialog("Cannot Execute operation", ex); | |
2318 | + dlg.ShowDialog(); | |
2319 | + m_Service.ResetTransaction(); | |
2320 | + } | |
2321 | + } | |
2297 | 2322 | } |
2298 | 2323 | } |
2299 | 2324 | catch (Exception ex) |
@@ -10,6 +10,8 @@ | ||
10 | 10 | using ChaKi.Service.DependencyEdit; |
11 | 11 | using PopupControl; |
12 | 12 | using ChaKi.Service.Lexicons; |
13 | +using System.Linq; | |
14 | +using ChaKi.Common.SequenceMatcher; | |
13 | 15 | |
14 | 16 | namespace DependencyEditSLA.Widgets |
15 | 17 | { |
@@ -16,7 +18,7 @@ | ||
16 | 18 | public partial class LexemeSelectionGrid : Form |
17 | 19 | { |
18 | 20 | private Corpus m_Corpus; |
19 | - private IList<Lexeme> m_LexList; | |
21 | + private IList<LexemeCandidate> m_Candidates; | |
20 | 22 | private ILexiconService m_Service; |
21 | 23 | private List<LP> m_PropertyColumns; |
22 | 24 | private DataGridViewCell m_CurrentCell; |
@@ -37,7 +39,7 @@ | ||
37 | 39 | /// <summary> |
38 | 40 | /// 選択された結果のLexeme |
39 | 41 | /// </summary> |
40 | - public Lexeme Selection { get; set; } | |
42 | + public LexemeCandidate Selection { get; set; } | |
41 | 43 | |
42 | 44 | public event EventHandler LexemeSelected; |
43 | 45 |
@@ -59,9 +61,14 @@ | ||
59 | 61 | |
60 | 62 | // カラム作成 |
61 | 63 | DataGridViewColumn col; |
62 | - col = new DataGridViewTextBoxColumn() | |
63 | - { Name = "ID", ReadOnly = true, | |
64 | - DefaultCellStyle = new DataGridViewCellStyle() { Alignment = DataGridViewContentAlignment.MiddleRight } }; | |
64 | + col = new DataGridViewLinkColumn() | |
65 | + { | |
66 | + Name = "ID", | |
67 | + ReadOnly = true, | |
68 | + DefaultCellStyle = new DataGridViewCellStyle() { Alignment = DataGridViewContentAlignment.MiddleRight }, | |
69 | + LinkColor = Color.Blue, | |
70 | + VisitedLinkColor = Color.DarkBlue | |
71 | + }; | |
65 | 72 | dg.Columns.Add(col); |
66 | 73 | col = new DataGridViewTextBoxColumn() { Name = "Dictioanry", ReadOnly = true }; |
67 | 74 | dg.Columns.Add(col); |
@@ -100,8 +107,11 @@ | ||
100 | 107 | c++; |
101 | 108 | } |
102 | 109 | col = new DataGridViewTextBoxColumn() |
103 | - { Name = "Frequency", ReadOnly = true, | |
104 | - DefaultCellStyle = new DataGridViewCellStyle() { Alignment = DataGridViewContentAlignment.MiddleRight } }; | |
110 | + { | |
111 | + Name = "Frequency", | |
112 | + ReadOnly = true, | |
113 | + DefaultCellStyle = new DataGridViewCellStyle() { Alignment = DataGridViewContentAlignment.MiddleRight } | |
114 | + }; | |
105 | 115 | dg.Columns.Add(col); |
106 | 116 | |
107 | 117 | // 初期値設定を反映 |
@@ -116,7 +126,7 @@ | ||
116 | 126 | this.Location = new Point( |
117 | 127 | Math.Min(maxRect.Width, Math.Max(Settings.InitialLocation.Location.X, 0)), |
118 | 128 | Math.Min(maxRect.Height, Math.Max(Settings.InitialLocation.Location.Y, 0))); |
119 | - | |
129 | + | |
120 | 130 | this.Size = new Size( |
121 | 131 | Math.Min(maxRect.Width, Math.Max(Settings.InitialLocation.Size.Width, 100)), |
122 | 132 | Math.Min(maxRect.Height, Math.Max(Settings.InitialLocation.Size.Height, 100))); |
@@ -130,13 +140,13 @@ | ||
130 | 140 | m_CurrentCell = null; |
131 | 141 | } |
132 | 142 | |
133 | - public void BeginSelection(string surface, Lexeme currentLexeme) | |
143 | + public void BeginSelection(string surface, Lexeme currentLexeme, IList<Word> words = null) | |
134 | 144 | { |
135 | 145 | DataGridView dg = this.dataGridView1; |
136 | 146 | dg.Rows.Clear(); |
137 | 147 | try |
138 | 148 | { |
139 | - m_LexList = m_Service.FindAllLexemeCandidates(surface); | |
149 | + m_Candidates = m_Service.FindAllLexemeCandidates(surface); | |
140 | 150 | } |
141 | 151 | catch (Exception ex) |
142 | 152 | { |
@@ -145,14 +155,16 @@ | ||
145 | 155 | return; |
146 | 156 | } |
147 | 157 | |
148 | - this.Selection = currentLexeme; | |
158 | + this.Selection = (from c in this.m_Candidates where c.Lexeme == currentLexeme select c).FirstOrDefault(); | |
149 | 159 | |
150 | - foreach (Lexeme lex in m_LexList) | |
160 | + foreach (var cand in m_Candidates) | |
151 | 161 | { |
152 | 162 | int r = dg.Rows.Add(); |
153 | 163 | |
154 | 164 | DataGridViewRow row = dg.Rows[r]; |
155 | 165 | |
166 | + var lex = cand.Lexeme; | |
167 | + var mwe_match = cand.Match; | |
156 | 168 | string idstr; |
157 | 169 | if (lex.ID < 0) |
158 | 170 | { |
@@ -181,11 +193,20 @@ | ||
181 | 193 | row.Cells[col++].Value = lex.GetStringProperty(m_PropertyColumns[i]); |
182 | 194 | } |
183 | 195 | row.Cells[col++].Value = lex.Frequency; |
196 | + if (mwe_match != null) | |
197 | + { | |
198 | + row.Cells[2].Value = MatchingResult.MWEToString(mwe_match.MWE, words, mwe_match); | |
199 | + } | |
200 | + | |
184 | 201 | if (!lex.CanEdit) |
185 | 202 | { |
186 | 203 | row.ReadOnly = true; |
187 | - if (lex.Dictionary != null) | |
204 | + if (mwe_match != null) | |
188 | 205 | { |
206 | + row.DefaultCellStyle.BackColor = Color.LightYellow; | |
207 | + } | |
208 | + else if (lex.Dictionary != null) | |
209 | + { | |
189 | 210 | row.DefaultCellStyle.BackColor = Color.LightBlue; |
190 | 211 | } |
191 | 212 | else |
@@ -198,7 +219,8 @@ | ||
198 | 219 | row.DefaultCellStyle.BackColor = Color.White; |
199 | 220 | } |
200 | 221 | } |
201 | - this.dataGridView1.MouseClick +=new MouseEventHandler(dataGridView1_MouseClick); | |
222 | + this.dataGridView1.MouseClick += new MouseEventHandler(dataGridView1_MouseClick); | |
223 | + this.dataGridView1.CellContentClick += dataGridView1_CellContentClick; | |
202 | 224 | |
203 | 225 | // 参照用辞書を含め、全ての使用可能なPOS, CType, CFormタグのリストを得て、PropTreeにセットする. |
204 | 226 | Dictionary<string, IList<PartOfSpeech>> pos; // stringはDictionary名(カレントコーパスは"Default") |
@@ -223,7 +245,7 @@ | ||
223 | 245 | base.WndProc(ref m); |
224 | 246 | } |
225 | 247 | |
226 | - protected override bool ProcessCmdKey( ref Message msg, Keys keyData ) | |
248 | + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) | |
227 | 249 | { |
228 | 250 | //if (keyData == Keys.Enter) |
229 | 251 | //{ |
@@ -243,21 +265,21 @@ | ||
243 | 265 | if (OkCancel) |
244 | 266 | { |
245 | 267 | int index = (this.dataGridView1.SelectedCells.Count > 0) ? this.dataGridView1.SelectedCells[0].RowIndex : -1; |
246 | - if (index >= 0 && index < m_LexList.Count) | |
268 | + if (index >= 0 && index < m_Candidates.Count) | |
247 | 269 | { |
248 | 270 | try |
249 | 271 | { |
250 | - string[] props = ToLexemePropertyArray(index, m_LexList[index]); | |
251 | - string customprop = m_LexList[index].CustomProperty; | |
252 | - Lexeme lex = m_LexList[index]; | |
272 | + var lex = m_Candidates[index].Lexeme; | |
273 | + var props = ToLexemePropertyArray(index, lex); | |
274 | + var customprop = lex.CustomProperty; | |
253 | 275 | if (lex.Dictionary != null) |
254 | 276 | { |
255 | 277 | lex = null; |
256 | 278 | } |
257 | 279 | m_Service.CreateOrUpdateLexeme(ref lex, props, customprop); |
258 | - m_LexList[index] = lex; | |
280 | + m_Candidates[index].Lexeme = lex; | |
259 | 281 | |
260 | - this.Selection = m_LexList[index]; | |
282 | + this.Selection = m_Candidates[index]; | |
261 | 283 | if (LexemeSelected != null) |
262 | 284 | { |
263 | 285 | LexemeSelected(this, null); |
@@ -300,7 +322,7 @@ | ||
300 | 322 | |
301 | 323 | private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) |
302 | 324 | { |
303 | - if (e.RowIndex >= 0 && e.RowIndex < m_LexList.Count) | |
325 | + if (e.RowIndex >= 0 && e.RowIndex < m_Candidates.Count) | |
304 | 326 | { |
305 | 327 | foreach (DataGridViewCell cell in this.dataGridView1.SelectedCells) |
306 | 328 | { |
@@ -322,13 +344,13 @@ | ||
322 | 344 | { |
323 | 345 | cell.Selected = false; |
324 | 346 | } |
325 | - if (m_LexList == null) | |
347 | + if (m_Candidates == null) | |
326 | 348 | { |
327 | 349 | return; |
328 | 350 | } |
329 | - for (int i = 0; i < m_LexList.Count; i++) | |
351 | + for (int i = 0; i < m_Candidates.Count; i++) | |
330 | 352 | { |
331 | - if (m_LexList[i] == this.Selection) | |
353 | + if (m_Candidates[i] == this.Selection) | |
332 | 354 | { |
333 | 355 | this.dataGridView1.Rows[i].Cells[0].Selected = true; |
334 | 356 | this.dataGridView1.CurrentCell = this.dataGridView1[0, i]; |
@@ -337,6 +359,30 @@ | ||
337 | 359 | } |
338 | 360 | } |
339 | 361 | |
362 | + | |
363 | + private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) | |
364 | + { | |
365 | + var dgv = (DataGridView)sender; | |
366 | + if (dgv.Columns[e.ColumnIndex].Name == "ID") | |
367 | + { | |
368 | + int index = (this.dataGridView1.SelectedCells.Count > 0) ? this.dataGridView1.SelectedCells[0].RowIndex : -1; | |
369 | + if (index >= 0 && index < m_Candidates.Count) | |
370 | + { | |
371 | + var cand = m_Candidates[index]; | |
372 | + if (cand != null && cand.Url != null) | |
373 | + { | |
374 | + // Cradleの単語画面をブラウザで表示 | |
375 | + var url = $"{cand.Url}word?id={cand.Lexeme.SID}"; | |
376 | + System.Diagnostics.Process.Start(url); | |
377 | + | |
378 | + // set "visited" | |
379 | + var cell = (DataGridViewLinkCell)dgv[e.ColumnIndex, e.RowIndex]; | |
380 | + cell.LinkVisited = true; | |
381 | + } | |
382 | + } | |
383 | + } | |
384 | + } | |
385 | + | |
340 | 386 | // マウス右クリック→Tree Menu表示 |
341 | 387 | void dataGridView1_MouseClick(object sender, MouseEventArgs e) |
342 | 388 | { |
@@ -389,7 +435,7 @@ | ||
389 | 435 | // 初期値設定をセーブ |
390 | 436 | int cols = this.dataGridView1.Columns.Count; |
391 | 437 | Settings.ColumnWidths = new int[cols]; |
392 | - for (int i= 0; i < cols; i++) | |
438 | + for (int i = 0; i < cols; i++) | |
393 | 439 | { |
394 | 440 | Settings.ColumnWidths[i] = this.dataGridView1.Columns[i].Width; |
395 | 441 | } |
@@ -127,36 +127,11 @@ | ||
127 | 127 | BeginInvoke(new Action(() => { |
128 | 128 | this.Table.Rows.Add( |
129 | 129 | false, |
130 | - MWEToString(mwe, this.Words, match), | |
130 | + MatchingResult.MWEToString(mwe, this.Words, match), | |
131 | 131 | string.Join(",", from r in match.RangeList where (r.Start >= 0 && r.End >= 0) select r.ToString())); |
132 | 132 | this.Results.Add(new Tuple<MWE, MatchingResult>(mwe, match)); |
133 | 133 | })); |
134 | 134 | } |
135 | 135 | |
136 | - private static string MWEToString(MWE mwe, IList<Word> words, MatchingResult match) | |
137 | - { | |
138 | - var tokens = new List<string>(); | |
139 | - for (var i = 0; i < mwe.Items.Count; i++) | |
140 | - { | |
141 | - switch (mwe.Items[i].NodeType) | |
142 | - { | |
143 | - case MWENodeType.Word: | |
144 | - tokens.Add(mwe.Items[i].Label); | |
145 | - break; | |
146 | - case MWENodeType.Placeholder: | |
147 | - var w = new List<string>(); | |
148 | - for (var j = match.RangeList[i].Start; j < match.RangeList[i].End; j++) | |
149 | - { | |
150 | - w.Add(words[j].Lex.Surface); | |
151 | - } | |
152 | - tokens.Add($"({string.Join(" ", w)})"); | |
153 | - break; | |
154 | - default: | |
155 | - tokens.Add("*"); | |
156 | - break; | |
157 | - } | |
158 | - } | |
159 | - return string.Join(" ", tokens); | |
160 | - } | |
161 | 136 | } |
162 | 137 | } |
@@ -14,6 +14,7 @@ | ||
14 | 14 | |
15 | 15 | public Lexeme Lex { get; set; } |
16 | 16 | public List<MWENode> Items { get; set; } |
17 | + public string Dictionary { get; set; } | |
17 | 18 | |
18 | 19 | public override string ToString() |
19 | 20 | { |
@@ -12,5 +12,5 @@ | ||
12 | 12 | [assembly: AssemblyCulture("")] |
13 | 13 | [assembly: ComVisible(false)] |
14 | 14 | [assembly: Guid("6a95808a-d1e3-47de-bb62-7ed7a281ac0b")] |
15 | -[assembly: AssemblyVersion("3.11.613.0")] | |
16 | -[assembly: AssemblyFileVersion("3.11.613.0")] | |
15 | +[assembly: AssemblyVersion("3.11.616.0")] | |
16 | +[assembly: AssemblyFileVersion("3.11.616.0")] |
@@ -954,7 +954,7 @@ | ||
954 | 954 | /// (先に見つけられたものが優先される。コーパス内にあるものは最優先。) |
955 | 955 | /// </summary> |
956 | 956 | /// <param name="str"></param> |
957 | - public IList<Lexeme> FindAllLexemeCandidates(string str) | |
957 | + public IList<LexemeCandidate> FindAllLexemeCandidates(string str) | |
958 | 958 | { |
959 | 959 | return FindAllLexemeCandidates(m_Context.Session, m_Dictionaries, str); |
960 | 960 | } |
@@ -965,20 +965,20 @@ | ||
965 | 965 | /// (先に見つけられたものが優先される。コーパス内にあるものは最優先。) |
966 | 966 | /// </summary> |
967 | 967 | /// <param name="str"></param> |
968 | - public static IList<Lexeme> FindAllLexemeCandidates(ISession session, List<DictionaryAccessor> refdics, string str) | |
968 | + public IList<LexemeCandidate> FindAllLexemeCandidates(ISession session, List<DictionaryAccessor> refdics, string str) | |
969 | 969 | { |
970 | - SortedList<string, Lexeme> list = new SortedList<string, Lexeme>(); | |
970 | + var list = new SortedList<string, LexemeCandidate>(); | |
971 | 971 | |
972 | 972 | // コーパス本体のLexicon |
973 | - IQuery query = session.CreateQuery(string.Format("from Lexeme l where l.Surface='{0}'", str)); | |
974 | - IList<Lexeme> result = query.List<Lexeme>(); | |
973 | + var query = session.CreateQuery(string.Format("from Lexeme l where l.Surface='{0}'", str)); | |
974 | + var result = query.List<Lexeme>(); | |
975 | 975 | bool needsNewLexeme = true; // 新語登録に使えるLexeme (Freq=0) が見つからなければtrue. |
976 | - foreach (Lexeme lex in result) | |
976 | + foreach (var lex in result) | |
977 | 977 | { |
978 | 978 | string key = lex.ToString3(); // POSを優先してSortさせる |
979 | 979 | if (!list.ContainsKey(key)) |
980 | 980 | { |
981 | - list.Add(key, lex); | |
981 | + list.Add(key, new LexemeCandidate(lex)); | |
982 | 982 | } |
983 | 983 | if (lex.PartOfSpeech == PartOfSpeech.Default) |
984 | 984 | { |
@@ -999,7 +999,9 @@ | ||
999 | 999 | string key = lex.ToString3(); |
1000 | 1000 | if (!list.ContainsKey(key)) |
1001 | 1001 | { |
1002 | - list.Add(key, lex); | |
1002 | + var cand = new LexemeCandidate(lex); | |
1003 | + cand.Url = refdic.Url; | |
1004 | + list.Add(key, cand); | |
1003 | 1005 | } |
1004 | 1006 | if (lex.Dictionary != null) |
1005 | 1007 | { |
@@ -1012,13 +1014,45 @@ | ||
1012 | 1014 | lex.CanEdit = false; |
1013 | 1015 | } |
1014 | 1016 | } |
1015 | - IList<Lexeme> ret = new List<Lexeme>(list.Values); | |
1017 | + // MWEも検索 | |
1018 | + var words = m_Context.Sen.GetWords(m_Context.Proj.ID); | |
1019 | + var matches = this.FindMWECandidates2(str, words); | |
1020 | + foreach (var match in matches) | |
1021 | + { | |
1022 | + var mwe = match.MWE; | |
1023 | + var lex = mwe.Lex; | |
1024 | + if (lex == null) continue; | |
1025 | + var matchranges = string.Join(",", from r in match.RangeList where (r.Start >= 0 && r.End >= 0) select r.ToString()); | |
1026 | + var key = $"{lex.ToString3()}@{matchranges}"; | |
1027 | + if (!list.ContainsKey(key)) | |
1028 | + { | |
1029 | + var cand = new LexemeCandidate(match); | |
1030 | + cand.Url = match.Url; | |
1031 | + list.Add(key, cand); | |
1032 | + } | |
1033 | + if (lex.Dictionary != null && lex.Dictionary.Contains("[")) | |
1034 | + { | |
1035 | + // 同じLexに対して2回以上通る可能性があるので、簡易的にチェックする. | |
1036 | + // do nothing | |
1037 | + } | |
1038 | + else if (lex.Dictionary != null) | |
1039 | + { | |
1040 | + lex.Dictionary = $"{mwe.Dictionary}[{lex.Dictionary}]"; | |
1041 | + } | |
1042 | + else | |
1043 | + { | |
1044 | + lex.Dictionary = mwe.Dictionary; | |
1045 | + } | |
1046 | + lex.CanEdit = false; | |
1047 | + } | |
1048 | + | |
1049 | + var ret = new List<LexemeCandidate>(list.Values); | |
1016 | 1050 | // 新語登録のための種となるLexemeをリストに追加する. |
1017 | 1051 | if (needsNewLexeme) |
1018 | 1052 | { |
1019 | - Lexeme lex = Lexeme.CreateDefaultUnknownLexeme(str); | |
1053 | + var lex = Lexeme.CreateDefaultUnknownLexeme(str); | |
1020 | 1054 | lex.CanEdit = true; |
1021 | - ret.Add(lex); | |
1055 | + ret.Add(new LexemeCandidate(lex)); | |
1022 | 1056 | } |
1023 | 1057 | |
1024 | 1058 | return ret; |
@@ -1081,7 +1115,7 @@ | ||
1081 | 1115 | } |
1082 | 1116 | |
1083 | 1117 | /// <summary> |
1084 | - /// strで開始されるMWEを複合語辞書(Cradle)から検索する. | |
1118 | + /// word listのそれぞれの語で開始されるMWEを複合語辞書(Cradle)から検索する. | |
1085 | 1119 | /// </summary> |
1086 | 1120 | /// <param name="str"></param> |
1087 | 1121 | public List<MWE> FindMWECandidates(IList<Word> words, Action<string> showMessageCallback = null, Action<MWE, MatchingResult> foundMWECallback = null) |
@@ -1127,6 +1161,39 @@ | ||
1127 | 1161 | } |
1128 | 1162 | |
1129 | 1163 | /// <summary> |
1164 | + /// surfaceを含み、word list(本文)の一部になりうるMWEをすべて辞書から検索し、 | |
1165 | + /// word listとのマッチング結果を返す. | |
1166 | + /// </summary> | |
1167 | + /// <param name="surface"></param> | |
1168 | + /// <returns></returns> | |
1169 | + public List<MatchingResult> FindMWECandidates2(string surface, IList<Word> words) | |
1170 | + { | |
1171 | + var result = new List<MatchingResult>(); | |
1172 | + | |
1173 | + int wpos = 0; | |
1174 | + foreach (var dict in m_Dictionaries) | |
1175 | + { | |
1176 | + if (!dict.CanSearchCompoundWord) | |
1177 | + { | |
1178 | + continue; | |
1179 | + } | |
1180 | + var list = dict.FindMWEBySurface2(surface); | |
1181 | + foreach (var mwe in list) | |
1182 | + { | |
1183 | + mwe.Dictionary = dict.Name; | |
1184 | + // 見つかったMWEがWord Listと合致するかチェックする. | |
1185 | + var matches = MWEMatcher.Match(words, wpos, mwe); | |
1186 | + foreach (var match in matches) | |
1187 | + { | |
1188 | + result.Add(match); | |
1189 | + match.Url = dict.Url; | |
1190 | + } | |
1191 | + } | |
1192 | + } | |
1193 | + return result; | |
1194 | + } | |
1195 | + | |
1196 | + /// <summary> | |
1130 | 1197 | /// 現在のSentenceの持つ "MWE"Group annotationおよびその範囲に付与された係り受けをすべて取得し、 |
1131 | 1198 | /// MWEオブジェクトに変換して返す. |
1132 | 1199 | /// </summary> |
@@ -11,6 +11,8 @@ | ||
11 | 11 | { |
12 | 12 | public abstract string Name { get; } |
13 | 13 | |
14 | + public Uri Url { get; private set; } | |
15 | + | |
14 | 16 | public bool CanSearchCompoundWord { get; private set; } |
15 | 17 | |
16 | 18 | public bool CanUpdateCompoundWord { get; private set; } |
@@ -32,11 +34,13 @@ | ||
32 | 34 | |
33 | 35 | if (dict is Dictionary_DB) |
34 | 36 | { |
35 | - ctx = new DictionaryAccessor_DB(((Dictionary_DB)dict)); | |
37 | + ctx = new DictionaryAccessor_DB((Dictionary_DB)dict); | |
36 | 38 | } |
37 | 39 | else if (dict is Dictionary_Cradle) |
38 | 40 | { |
39 | - ctx = new DictionaryAccessor_Cradle(((Dictionary_Cradle)dict)); | |
41 | + var cradle = (Dictionary_Cradle)dict; | |
42 | + ctx = new DictionaryAccessor_Cradle(cradle); | |
43 | + ctx.Url = cradle.Url; | |
40 | 44 | } |
41 | 45 | ctx.CanSearchCompoundWord = dict.CanSearchCompoundWord; |
42 | 46 | ctx.CanUpdateCompoundWord = dict.CanUpdateCompoundWord; |
@@ -48,6 +52,8 @@ | ||
48 | 52 | |
49 | 53 | public abstract IList<MWE> FindMWEBySurface(string surface); |
50 | 54 | |
55 | + public abstract IList<MWE> FindMWEBySurface2(string surface); | |
56 | + | |
51 | 57 | public abstract void RegisterMWE(MWE mwe); |
52 | 58 | } |
53 | 59 | } |
@@ -84,12 +84,22 @@ | ||
84 | 84 | |
85 | 85 | public override IList<MWE> FindMWEBySurface(string surface) |
86 | 86 | { |
87 | + return FindMWEBySurface_Impl(surface, "find_mwe"); | |
88 | + } | |
89 | + | |
90 | + public override IList<MWE> FindMWEBySurface2(string surface) | |
91 | + { | |
92 | + return FindMWEBySurface_Impl(surface, "find_mwe2"); | |
93 | + } | |
94 | + | |
95 | + private IList<MWE> FindMWEBySurface_Impl(string surface, string apiname) | |
96 | + { | |
87 | 97 | var result = new List<MWE>(); |
88 | 98 | |
89 | 99 | var client = new WebClient(); |
90 | 100 | client.Encoding = new UTF8Encoding(); |
91 | 101 | var json = client.DownloadString( |
92 | - new Uri(string.Format("{0}find_mwe?surface={1}", m_Dict.Url, surface))); | |
102 | + new Uri($"{m_Dict.Url}{apiname}?surface={surface}")); | |
93 | 103 | var jarray = JArray.Parse(json); |
94 | 104 | foreach (var item in jarray) |
95 | 105 | { |
@@ -63,6 +63,11 @@ | ||
63 | 63 | return new List<MWE>(); // This Dictionary does not support MWE(Compound Word) |
64 | 64 | } |
65 | 65 | |
66 | + public override IList<MWE> FindMWEBySurface2(string surface) | |
67 | + { | |
68 | + return new List<MWE>(); // This Dictionary does not support MWE(Compound Word) | |
69 | + } | |
70 | + | |
66 | 71 | public override void RegisterMWE(MWE mwe) |
67 | 72 | { |
68 | 73 | // This Dictionary does not support MWE(Compound Word) |
@@ -124,7 +124,7 @@ | ||
124 | 124 | // |
125 | 125 | // 以下は今のところ使用していない。DepEditServiceで実装されている。 |
126 | 126 | // |
127 | - public IList<Lexeme> FindAllLexemeCandidates(string str) | |
127 | + public IList<LexemeCandidate> FindAllLexemeCandidates(string str) | |
128 | 128 | { |
129 | 129 | throw new NotImplementedException(); |
130 | 130 | } |
@@ -144,5 +144,9 @@ | ||
144 | 144 | throw new NotImplementedException(); |
145 | 145 | } |
146 | 146 | |
147 | + public List<MatchingResult> FindMWECandidates2(string surface, IList<Word> words) | |
148 | + { | |
149 | + throw new NotImplementedException(); | |
150 | + } | |
147 | 151 | } |
148 | 152 | } |
@@ -91,9 +91,9 @@ | ||
91 | 91 | Operation.CreateOrUpdateLexeme(m_Context, ref lex, props, customprop); |
92 | 92 | } |
93 | 93 | |
94 | - public IList<Lexeme> FindAllLexemeCandidates(string str) | |
94 | + public IList<LexemeCandidate> FindAllLexemeCandidates(string str) | |
95 | 95 | { |
96 | - return DepEditService.FindAllLexemeCandidates(m_Context.Session, m_RefDics, str); | |
96 | + throw new NotImplementedException(); | |
97 | 97 | } |
98 | 98 | |
99 | 99 | public void GetLexiconTags(out Dictionary<string, IList<PartOfSpeech>> pos, out Dictionary<string, IList<CType>> ctypes, out Dictionary<string, IList<CForm>> cforms) |
@@ -103,7 +103,12 @@ | ||
103 | 103 | |
104 | 104 | public List<MWE> FindMWECandidates(IList<Word> words, Action<string> showMessageCallback, Action<MWE, MatchingResult> foundMWECallback) |
105 | 105 | { |
106 | - return DepEditService.FindMWECandidates(m_RefDics, words, showMessageCallback, foundMWECallback); | |
106 | + throw new NotImplementedException(); | |
107 | 107 | } |
108 | + | |
109 | + public List<MatchingResult> FindMWECandidates2(string surface, IList<Word> words) | |
110 | + { | |
111 | + throw new NotImplementedException(); | |
112 | + } | |
108 | 113 | } |
109 | 114 | } |
@@ -11,7 +11,7 @@ | ||
11 | 11 | /// Surfaceがstrに一致するLexemeをすべて得る。 |
12 | 12 | /// </summary> |
13 | 13 | /// <param name="str"></param> |
14 | - IList<Lexeme> FindAllLexemeCandidates(string str); | |
14 | + IList<LexemeCandidate> FindAllLexemeCandidates(string str); | |
15 | 15 | |
16 | 16 | /// <summary> |
17 | 17 | /// propsで与えられた内容を元に既存のLexemeを更新または新たに生成してDBに登録する. |
@@ -37,5 +37,13 @@ | ||
37 | 37 | /// </summary> |
38 | 38 | /// <param name="str"></param> |
39 | 39 | List<MWE> FindMWECandidates(IList<Word> words, Action<string> showMessageCallback = null, Action<MWE, MatchingResult> foundMWECallback = null); |
40 | + | |
41 | + /// <summary> | |
42 | + /// surfaceを含み、word list(本文)の一部になりうるMWEをすべて辞書から検索し、 | |
43 | + /// word listとのマッチング結果を返す. | |
44 | + /// </summary> | |
45 | + /// <param name="surface"></param> | |
46 | + /// <returns></returns> | |
47 | + List<MatchingResult> FindMWECandidates2(string surface, IList<Word> words); | |
40 | 48 | } |
41 | 49 | } |
@@ -12,5 +12,5 @@ | ||
12 | 12 | [assembly: AssemblyCulture("")] |
13 | 13 | [assembly: ComVisible(false)] |
14 | 14 | [assembly: Guid("a8cf8403-eb88-418f-bf54-56aeaef39268")] |
15 | -[assembly: AssemblyVersion("3.11.613.0")] | |
16 | -[assembly: AssemblyFileVersion("3.11.613.0")] | |
15 | +[assembly: AssemblyVersion("3.11.616.0")] | |
16 | +[assembly: AssemblyFileVersion("3.11.616.0")] |
@@ -12,5 +12,5 @@ | ||
12 | 12 | [assembly: AssemblyCulture("")] |
13 | 13 | [assembly: ComVisible(false)] |
14 | 14 | [assembly: Guid("ff6652ed-b932-466b-944b-ce88d698979b")] |
15 | -[assembly: AssemblyVersion("3.11.613.0")] | |
16 | -[assembly: AssemblyFileVersion("3.11.613.0")] | |
15 | +[assembly: AssemblyVersion("3.11.616.0")] | |
16 | +[assembly: AssemblyFileVersion("3.11.616.0")] |