Get Words in Input String in Python

Cloudmersive
2 min readJan 26, 2022

--

In our last article, we walked through an iteration of the Cloudmersive NLP API v2 which can break text down into individual sentences. In this article, we’ll go through a companion iteration to this which will go a step further and break down your text string into all its individual component words. You can take advantage of this powerful NLP capability in no time following the below steps & copying documented, ready-to-run code (directly from the Cloudmersive API Console).

First, we need to copy & run the following command to install the Python SDK:

pip install cloudmersive-nlp-api-clientfrom __future__ import print_function
import time
import cloudmersive_nlp_api_client
from cloudmersive_nlp_api_client.rest import ApiException
from pprint import pprint

Once that’s done, we can move onto our API key authorization step (you can acquire an API key by creating a free account on the Cloudmersive website):

# Configure API key authorization: Apikey
configuration = cloudmersive_nlp_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'

Now we’re at the finish line — just copy & paste the below code to complete the function, and you’re all set:

# create an instance of the API class api_instance = cloudmersive_nlp_api_client.SegmentationApi(cloudmersive_nlp_api_client.ApiClient(configuration)) input = cloudmersive_nlp_api_client.GetWordsRequest() # GetWordsRequest | String to process  try:     # Get words in input string     api_response = api_instance.segmentation_get_words(input)     pprint(api_response) except ApiException as e:     print("Exception when calling SegmentationApi->segmentation_get_words: %s\n" % e)

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet