Part-of-Speech Tag a String, Filter to Adjectives in Python
We all know the basics: an adjective is a word that describes a noun. Cloudmersive’s NLP API v2 knows that too. Specifically, the /nlp-v2/pos/tag/adjectives iteration of this API uses NLP to quickly filter a body of text for adjectives and show the results as in JSON format. In this article we’ll walk through how you can connect with this API in Python.
At the outset you’ll need to run the command for Python SDK installation:
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
Right after that you’ll need to copy the below code snippet to capture your API key & authorize API access:
# Configure API key authorization: Apikey
configuration = cloudmersive_nlp_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
Now we’re almost finished — all that’s left is copying in the rest of the callback function:
# 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 adjectives
api_response = api_instance.pos_tagger_tag_adjectives(request)
pprint(api_response)
except ApiException as e:
print("Exception when calling PosTaggerApi->pos_tagger_tag_adjectives: %s\n" % e)