Part-of-speech Tag a String, Filter to Verbs in Python
--
NLP gives our applications the ability to quickly perform useful tasks by analyzing Natural Language text inputs. One category of such tasks includes breaking down sentences for a specific POS (part-of-speech), which is a pain to do manually, regardless of your level of grammatical prowess. In this article we’ll walk through the ease of using Cloudmersive’s /nlp-v2/pos/tag/verbs iteration of the NLP API v2 to find verbs in a text string & return a JSON result.
To begin with, you’ll need to run the below command found on the Cloudmersive API console page 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
After this, the next step is to copy the below API Key Authorization code snippet & ensure your API key is properly entered:
# Configure API key authorization: Apikey
configuration = cloudmersive_nlp_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
And now for the final step, you can copy in the rest of the function to call the API:
# create an instance of the API class
api_instance = cloudmersive_nlp_api_client.PosTaggerApi(cloudmersive_nlp_api_client.ApiClient(configuration))
request = cloudmersive_nlp_api_client.PosRequest() # PosRequest | Input stringtry:
# Part-of-speech tag a string, filter to verbs
api_response = api_instance.pos_tagger_tag_verbs(request)
pprint(api_response)
except ApiException as e:
print("Exception when calling PosTaggerApi->pos_tagger_tag_verbs: %s\n" % e)