How to get Nouns from a Sentence in Python
Today we are going to do things a little differently. Instead of showing a lengthy process for manually setting up an NLP system for filtering nouns, we will be cutting some corners to get set up almost instantly. Let’s take a look.
Our key ingredient for simplicity today is Cloudmersive’s NLP API, the client for which we shall install as our first step.
pip install git+https://github.com/Cloudmersive/Cloudmersive.APIClient.Python.NLP.git
And next we are going to set up our function call, which will look like this code snippet here:
from __future__ import print_functionimport timeimport cloudmersive_nlp_api_clientfrom cloudmersive_nlp_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_nlp_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_nlp_api_client.WordsApi(cloudmersive_nlp_api_client.ApiClient(configuration))input = 'input_example' # str | Input stringtry:# Get nouns in stringapi_response = api_instance.words_nouns(input)pprint(api_response)except ApiException as e:print("Exception when calling WordsApi->words_nouns: %s\n" % e)
Now get ready to have your mind blown: That’s it! That’s the entire process! Seriously, how easy was that?