From 4c947f5d8867a06a84c83584249a82dad34bdfff Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 11 Aug 2021 13:53:19 +0900 Subject: [PATCH] [NLP] Fix crash issue Signed-off-by: Jihoon Kim --- src/Tizen.Nlp/Tizen.Nlp/NaturalLanguageProcess.cs | 73 +++++++++++++---------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/src/Tizen.Nlp/Tizen.Nlp/NaturalLanguageProcess.cs b/src/Tizen.Nlp/Tizen.Nlp/NaturalLanguageProcess.cs index 4cc0b88..bff123d 100755 --- a/src/Tizen.Nlp/Tizen.Nlp/NaturalLanguageProcess.cs +++ b/src/Tizen.Nlp/Tizen.Nlp/NaturalLanguageProcess.cs @@ -116,46 +116,55 @@ namespace Tizen.Nlp { Log.Debug(LogTag, "OnReceived "); MessageReceivedEventArgs e = new MessageReceivedEventArgs(); - int requestid; + int requestid = 0; Dictionary result = new Dictionary(); - result.Add("token", (string[])msg.GetItem("return_token")); - e.RequestId = requestid = int.Parse((string)msg.GetItem("request_id")); - if (msg.GetItem("command").Equals("word_tokenize")) + if (msg.Contains("return_token")) + result.Add("token", (string[])msg.GetItem("return_token")); + + if (msg.Contains("request_id")) + e.RequestId = requestid = int.Parse((string)msg.GetItem("request_id")); + else + return; + + if (msg.Contains("command")) { - e.Message = result; - if (_mapsWordTokenize.ContainsKey(requestid)) + if (msg.GetItem("command").Equals("word_tokenize")) { - _mapsWordTokenize[requestid]?.Invoke(e); - _mapsWordTokenize.Remove(requestid); + e.Message = result; + if (_mapsWordTokenize.ContainsKey(requestid)) + { + _mapsWordTokenize[requestid]?.Invoke(e); + _mapsWordTokenize.Remove(requestid); + } } - } - else if (msg.GetItem("command").Equals("pos_tag")) - { - result.Add("tag", (string[])msg.GetItem("return_tag")); - e.Message = result; - if (_mapsPosTag.ContainsKey(requestid)) + else if (msg.GetItem("command").Equals("pos_tag")) { - _mapsPosTag[requestid]?.Invoke(e); - _mapsPosTag.Remove(requestid); + result.Add("tag", (string[])msg.GetItem("return_tag")); + e.Message = result; + if (_mapsPosTag.ContainsKey(requestid)) + { + _mapsPosTag[requestid]?.Invoke(e); + _mapsPosTag.Remove(requestid); + } } - } - else if (msg.GetItem("command").Equals("ne_chunk")) - { - result.Add("tag", (string[])msg.GetItem("return_tag")); - e.Message = result; - if (_mapsNamedEntity.ContainsKey(requestid)) + else if (msg.GetItem("command").Equals("ne_chunk")) { - _mapsNamedEntity[requestid]?.Invoke(e); - _mapsNamedEntity.Remove(requestid); + result.Add("tag", (string[])msg.GetItem("return_tag")); + e.Message = result; + if (_mapsNamedEntity.ContainsKey(requestid)) + { + _mapsNamedEntity[requestid]?.Invoke(e); + _mapsNamedEntity.Remove(requestid); + } } - } - else if (msg.GetItem("command").Equals("langdetect")) - { - e.Message = result; - if (_mapsLangDetect.ContainsKey(requestid)) + else if (msg.GetItem("command").Equals("langdetect")) { - _mapsLangDetect[requestid]?.Invoke(e); - _mapsLangDetect.Remove(requestid); + e.Message = result; + if (_mapsLangDetect.ContainsKey(requestid)) + { + _mapsLangDetect[requestid]?.Invoke(e); + _mapsLangDetect.Remove(requestid); + } } } } @@ -343,4 +352,4 @@ namespace Tizen.Nlp return task.Task; } } -} \ No newline at end of file +} -- 2.7.4