How to Part-Of-Speech Tag a Text String and Filter the Verbs in Python with NLP
2 min readJun 6, 2020
Verb filtering through POS tagging is about to become as easy as pie, just you wait.
First step: install the client we will be using:
pip install git+https://github.com/Cloudmersive/Cloudmersive.APIClient.Python.NLP.git
Secondly, paste in this chunk of example code 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.PosTaggerApi(cloudmersive_nlp_api_client.ApiClient(configuration))request = cloudmersive_nlp_api_client.PosRequest() # PosRequest | Input stringtry:# Part-of-speech tag a string, filter to verbsapi_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)
Alright, that’s it for the setup. Now you need only enter your string as part of the PosRequest object and let the API take care of it for you. If you have other POS tagging needs, or have a desired for a wide range of other NLP-related functions, this same library is full of them. Give it a look and find out how much more time you can save.