+++ /dev/null
-/*
-* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the License);
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an AS IS BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Tizen.Nlp
-{
- /// <summary>
- /// This class contains result of lemmatized.
- /// </summary>
- /// <since_tizen> 5 </since_tizen>
- public class LemmatizeResult
- {
- /// <summary>
- /// The whole sentence.
- /// </summary>
- /// <since_tizen> 5 </since_tizen>
- public string ActualWord { get; set; }
- }
-}
private int _requestIdLang = 0;
private int _requestIdNeChunk = 0;
private int _requestIdWordTokenize = 0;
- private int _requestIdLemmatize = 0;
private Task _connectionTask;
private ConnectedState _connectionState = ConnectedState.Disconnected;
private readonly Dictionary<int, NamedEntityRecognitionCallback> _mapsNamedEntity =
new Dictionary<int, NamedEntityRecognitionCallback>();
- private readonly Dictionary<int, LemmatizeCallback> _mapsLemmatize = new Dictionary<int, LemmatizeCallback>();
-
/// <summary>
/// An construct method to init local env of NLP .
/// </summary>
private delegate bool NamedEntityRecognitionCallback(MessageReceivedEventArgs e);
- private delegate bool LemmatizeCallback(MessageReceivedEventArgs e);
-
/// <summary>
/// A connection status change event
/// </summary>
_mapsNamedEntity.Remove(requestid);
}
}
- else if (msg.GetItem("command").Equals("lemmatize"))
- {
- e.Message = result;
- if (_mapsLemmatize.ContainsKey(requestid))
- {
- _mapsLemmatize[requestid]?.Invoke(e);
- _mapsLemmatize.Remove(requestid);
- }
- }
else if (msg.GetItem("command").Equals("langdetect"))
{
e.Message = result;
/// An async method to connect remote service.
/// </summary>
/// <since_tizen> 5 </since_tizen>
+ /// <returns>A task representing the asynchronous connect operation.</returns>
/// <exception cref="InvalidOperationException">Thrown when the connect is rejected.</exception>
public Task Connect()
{
{
Log.Debug(LogTag, "start to register");
_msg.CoRegister(Application.Current.ApplicationInfo.ApplicationId, _noti);
- tcs.SetResult(true);
_connectionState = ConnectedState.Connected;
+ tcs.SetResult(true);
};
_msg.Rejected += (sender, e) =>
{
_mapsWordTokenize.Clear();
_mapsPosTag.Clear();
_mapsNamedEntity.Clear();
- _mapsLemmatize.Clear();
_mapsLangDetect.Clear();
}
}
/// <summary>
- /// Send Lemmatize request to remote tidl service with one parameters.
- /// </summary>
- /// <param name="sentence">A sentence need to be processed.</param>
- /// <returns>ProcessResult</returns>
- /// <since_tizen> 5 </since_tizen>
- public Task<LemmatizeResult> LemmatizeaAsync(string sentence)
- {
- int id = _requestIdLemmatize++;
- MakeRequest("lemmatize", sentence, id);
- var task = new TaskCompletionSource<LemmatizeResult>();
- _mapsLemmatize[id] = (e) =>
- {
- LemmatizeResult mr = new LemmatizeResult();
- e.Message.TryGetValue("token", out string[] tokens);
- if (tokens != null) mr.ActualWord = tokens[0];
- task.SetResult(mr);
- return true;
- };
- return task.Task;
- }
-
- /// <summary>
/// Send word tokenize request to remote tidl service with one parameters.
/// </summary>
/// <param name="sentence">A sentence need to be processed.</param>