• R/O
  • SSH
  • HTTPS

chaki: Commit


Commit MetaInfo

Revision616 (tree)
Time2018-07-22 23:03:17
Authortomorita

Log Message

CreateMWEAnnotationで、二重Segmentの事前チェック処理を追加.

Change Summary

Incremental Difference

--- trunk/ChaKi.NET/src/Service/DependencyEdit/OperationCreateMWEAnnotation.cs (revision 615)
+++ trunk/ChaKi.NET/src/Service/DependencyEdit/OperationCreateMWEAnnotation.cs (revision 616)
@@ -34,6 +34,20 @@
3434 {
3535 throw new Exception($"#Ranges={n} != #MWEItems={m_Match.MWE.Items.Count}");
3636 }
37+ //重複MWE Segmentのチェック
38+ for (var i = 0; i < m_Match.CharRangeList.Count; i++)
39+ {
40+ var range = m_Match.CharRangeList[i];
41+ var docid = ctx.Sen.ParentDoc.ID;
42+ var start = range.Start.Value + ctx.Sen.StartChar;
43+ var end = range.End.Value + ctx.Sen.StartChar;
44+ // 既にMWE Segmentが同じ個所にないかをチェック
45+ if (FindSegmentBetween(ctx, docid, start, end, MWETag) != null)
46+ {
47+ throw new DuplicatedAnnotationException();
48+ }
49+ }
50+
3751 // m_CharRangeにそれぞれMWE Segmnetを作成し、全体をGroupとする
3852 var bunsetsulist = new List<Segment>();
3953 var stag = ctx.Proj.FindTag(Tag.SEGMENT, MWETag);
@@ -77,6 +91,7 @@
7791 var docid = ctx.Sen.ParentDoc.ID;
7892 var start = range.Start.Value + ctx.Sen.StartChar;
7993 var end = range.End.Value + ctx.Sen.StartChar;
94+
8095 var seg = new Segment();
8196 seg.Sentence = ctx.Sen;
8297 seg.Tag = stag;
--- trunk/ChaKi.NET/src/Service/DependencyEdit/DepEditService.cs (revision 615)
+++ trunk/ChaKi.NET/src/Service/DependencyEdit/DepEditService.cs (revision 616)
@@ -632,7 +632,15 @@
632632 public IOperation CreateMWEAnnotation(MatchingResult match, bool recordHistory = true)
633633 {
634634 var op = new OperationCreateMWEAnnotation(match);
635- op.Execute(m_Context);
635+ try
636+ {
637+ op.Execute(m_Context);
638+ }
639+ catch (DuplicatedAnnotationException)
640+ {
641+ // 同じMWE Segmentを付けようとしたときはDBを変更せずnullを返す.
642+ return null;
643+ }
636644 if (recordHistory)
637645 {
638646 m_History.Record(op);
--- trunk/ChaKi.NET/src/DepEditSLA/Widgets/MWEDownloadGrid.cs (revision 615)
+++ trunk/ChaKi.NET/src/DepEditSLA/Widgets/MWEDownloadGrid.cs (revision 616)
@@ -30,7 +30,7 @@
3030 public DataTable Table { get; set; }
3131 public List<Tuple<MWE, MatchingResult>> Results { get; set; }
3232
33- public event Action<MatchingResult[], bool[]> OnApplyMweMatches;
33+ public event Func<MatchingResult[], bool[], bool[]> OnApplyMweMatches;
3434
3535 public MWEDownloadGrid(Corpus cps, ILexiconService lexsvc, IDepEditService depsvc)
3636 {
@@ -74,7 +74,11 @@
7474 // checkedリストを生成
7575 var checks = from r in this.Table.Rows.Cast<DataRow>() select (bool)r[0];
7676
77- this.OnApplyMweMatches(mwes.ToArray(), checks.ToArray());
77+ var checks_update = this.OnApplyMweMatches(mwes.ToArray(), checks.ToArray());
78+ for (var i = 0; i < checks_update.Length; i++)
79+ {
80+ this.Table.Rows[i][0] = checks_update[i];
81+ }
7882 }
7983 }
8084
--- trunk/ChaKi.NET/src/DepEditSLA/SentenceStructure.cs (revision 615)
+++ trunk/ChaKi.NET/src/DepEditSLA/SentenceStructure.cs (revision 616)
@@ -2715,7 +2715,6 @@
27152715 try
27162716 {
27172717 m_MweOps.Clear();
2718-
27192718 var words = this.Model.GetWords(this.TargetProjectId);
27202719 m_MWEDownloadSelector.Words = words;
27212720 m_MWEDownloadSelector.OnApplyMweMatches += OnApplyMWEMatches;
@@ -2743,11 +2742,13 @@
27432742 }
27442743
27452744 // MWEアノテーションを一旦元に戻し、onされたMWEを順に生成しなおす.
2746- private void OnApplyMWEMatches(MatchingResult[] matches, bool[] onoffs)
2745+ // 処理結果に一致したcheck状態を返す.
2746+ private bool[] OnApplyMWEMatches(MatchingResult[] matches, bool[] onoffs)
27472747 {
27482748 var words = m_MWEDownloadSelector.Words;
27492749 var oldCur = Cursor.Current;
27502750 Cursor.Current = Cursors.WaitCursor;
2751+ var checkStates = new bool[matches.Length]; // すべてデフォルトではunchecked状態
27512752 try
27522753 {
27532754 // チェックが変更されるたびにRollbackする
@@ -2762,7 +2763,15 @@
27622763 // Word番号リストから文字位置範囲リストへ変換
27632764 match.CalcCharRangeList(words, this.Model.StartChar);
27642765 var op = m_Service.CreateMWEAnnotation(match, false);
2765- m_MweOps.Add(op);
2766+ if (op != null)
2767+ {
2768+ m_MweOps.Add(op);
2769+ checkStates[i] = true; // Executeが成功したので、Check状態とする.
2770+ }
2771+ else
2772+ {
2773+ MessageBox.Show("Duplicate segment is prohibited!");
2774+ }
27662775 }
27672776 }
27682777 }
@@ -2785,6 +2794,7 @@
27852794 }
27862795 Cursor.Current = oldCur;
27872796 }
2797+ return checkStates;
27882798 }
27892799
27902800 public event EventHandler CreateLinkModeChanged;
Show on old repository browser