Commit MetaInfo
Log Message
DepEditで単語クリックにより表示されるLexemeSelectionGrid(単語アサイン変更ダイアログ)にMWE Annotationを統合.
Change Summary
Incremental Difference
| | @@ -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)
|
| | @@ -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")]
|
Show on old repository browser
|