Natural Language Processing (NLP)
NLP is a subset of Natural Language Toolkit that specifies an interface and a protocol for basic natural language processing. Tizen enables you to use Natural Language Process (NLP) functionalities, such as language detection, parts of speech, word tokenization, and named entity detection. For more information, see the NLTK Forum.
NoteNLP API is deprecated since Tizen 8.0 and will be removed after two releases without any alternatives.
The main features of the Tizen.Nlp namespace include the following:
-
Word tokenize support
You can get tokens from a sentence, the type of return is WordTokenizeResult. This method breaks up the sentence into words and punctuation.
-
Part-of-speech support
You can get tokens and tags from a sentence, the type of return is PosTagResult. This method breaks up the sentence into words and punctuation with tag attributes.
-
Named entity recognizer support
You can get tokens and tags from a sentence, the type of return is NamedEntityRecognitionResult. This method breaks up the sentence into words and punctuation with tag attributes.
-
Language detect support
You can get language from a sentence, the type of return is LanguageDetectedResult. This method is used to detect the language of a sentence.
Prerequisites
To enable your application to use the NLP functionality, follow the steps below:
-
To use the Tizen.Nlp namespace, the application has to request permission by adding the following privileges to the
tizen-manifest.xml
file:XMLCopy<privileges> <privilege>http://tizen.org/privilege/appmanager.launch</privilege> <privilege>http://tizen.org/privilege/datasharing</privilege> </privileges>
-
To use the methods and properties of the
Tizen.Nlp
namespace, include it in your application:C#Copyusing Tizen.Nlp;
Receive WordTokenize tokens
To receive the tokens from sentence, follow the steps below:
-
Construct NaturalLanguageProcess on OnCreate(), and connect the NLP service on init of app:
C#Copyprotected override void OnCreate { .. nlp = new NaturalLanguageProcess(); Task task = nlp.Connect(); .. }
-
Call the WordTokenizeAsync(string msg) in a async task method:
C#Copypublic async Task OnTokenButtonPressedAsync(string msg) { .. var ret = nlp.WordTokenizeAsync(msg); WordTokenizeResult wr = await ret; .. }
-
When NLP object is no longer needed, call Dispose() to release the resource of NLP:
C#Copyprotected override void OnTerminate() { .. nlp.Dispose(); .. }
Receive PosTag tokens and tags
To receive the tokens and tags from sentence, follow the steps below:
-
Construct NaturalLanguageProcess on OnCreate(), and connect the NLP service on init of app:
C#Copyprotected override void OnCreate { .. nlp = new NaturalLanguageProcess(); Task task = nlp.Connect(); .. }
-
Call the PosTagAsync(string msg) in a async task method:
C#Copypublic async Task OnPosButtonPressedAsync(string msg) { .. var ret = nlp.PosTagAsync(msg); PosTagResult pr = await ret; .. }
-
When NLP object is no longer needed, call Dispose() to release the resource of NLP:
C#Copyprotected override void OnTerminate() { .. nlp.Dispose(); .. }
Receive named entity tokens and tags
To receive the tokens and tags information from sentence, follow the steps below:
-
Construct NaturalLanguageProcess on OnCreate(), and connect the NLP service on init of app:
C#Copyprotected override void OnCreate { .. nlp = new NaturalLanguageProcess(); Task task = nlp.Connect(); .. }
-
Call the NamedEntityRecognitionAsync(string msg) in a async task method:
C#Copypublic async Task OnTokenButtonPressedAsync(string msg) { .. var ret = nlp.NamedEntityRecognitionAsync(msg); NamedEntityRecognitionResult nr = await ret; .. }
-
When NLP object is no longer needed, call Dispose() to release the resource of NLP:
C#Copyprotected override void OnTerminate() { .. nlp.Dispose(); .. }
Detect language
To detect the language from sentence, follow the steps below:
-
Construct NaturalLanguageProcess on OnCreate(), and connect the NLP service on init of app:
C#Copyprotected override void OnCreate { .. nlp = new NaturalLanguageProcess(); Task task = nlp.Connect(); .. }
-
Call the LanguageDetectAsync(string msg) in a async task method:
C#Copypublic async Task OnLangButtonPressedAsync(string msg) { .. var ret = nlp.LanguageDetectAsync(msg); LanguageDetectedResult lr = await ret; .. }
-
When NLP object is no longer needed, call Dispose() to release the resource of NLP:
C#Copyprotected override void OnTerminate() { .. a.Dispose(); .. }
Related information
- Dependencies
- Tizen 5.0 and Higher