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 cloudmersive_nlp_api_client.rest 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
try:
# Parse string to syntax tree
api_response = api_instance.parse_parse_string(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling ParseApi->parse_parse_string: %s\n" % e)

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to install OSRM backend on Ubuntu Ubuntu 20.04.1 LTS

Hacking with Swift — Learning Project 11

NEAR Blockchain Developer Bootcamp.

The long road to the very beginning! (For artists/musicians going into tech)

Creating A Function In R

Using monads with go 1.18 generics (Part 1 — Maybe)

From 0 to 60 with Elastic Security

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
Cloudmersive

Cloudmersive

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

More from Medium

Part-of-Speech Tag a String, Filter to Nouns in Python

[In-Depth Tutorial] Tesseract OCR in Python with Pytesseract & OpenCV

Part-of-Speech Tag a String, Filter to Adjectives in Python

Part-of-Speech (POS) Tag a String in Python