Parse String to Syntax Tree (Penn Treebank) in Python

The Penn Treebank is a massive dataset of annotated & human-corrected words maintained by the University of Pennsylvania, designed to make the process of breaking down and tagging natural language sentences easy & accessible. It’s useful to have a sentence broken down in this way, especially if you’re incorporating other elements of NLP into your application. The /nlp-v2/parse/tree iteration of the Cloudmersive NLP API v2 will empower your application to quickly perform this task. Let’s walk through how to use this in Python.

You can copy in this first snippet to install the Python SDK:

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

After that, you’ll need to authorize your API key in the below snippet:

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

Finally, you can add in the rest of the callback function below:

# create an instance of the API class
api_instance = cloudmersive_nlp_api_client.ParseApi(cloudmersive_nlp_api_client.ApiClient(configuration))
input = cloudmersive_nlp_api_client.ParseRequest() # ParseRequest | Input string
# Parse string to syntax tree
api_response = api_instance.parse_parse_string(input)
except ApiException as e:
print("Exception when calling ParseApi->parse_parse_string: %s\n" % e)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store