Part 1. Getting started and making requests
By Rodrigo Alarcón, Computational Linguist
In this series of posts we want to showcase different examples on how to call our NLP API to analyze your own texts.
To use Codeq NLP API you need to sign up to generate a USER_ID and USER_KEY. Registration is free and we provide a developer plan with enough calls to start exploring our NLP tools.
Once you have signed up, next step would be to install our Python SDK:
Import the client SDK and define a pipeline
The SDK can be used to create an instance of a client using your API credentials and analyze your own documents. By default, when you call the API you will retrieve a text fully analyzed by our complete set of NLP Annotators. Or you can specify a custom pipeline depending on your needs, for example a pipeline to analyze the speech acts, sentiments and emotions of a text:
Analyze a text
Now you can pass a text and the pipeline you declared as input to the API client, which will return a Document object. The Document contains a list of Sentence objects with the analyzed information of the text:
In the last two lines, we iterate over the sentences extracted from the document and print all analyzed attributes for a quick look:
You can also iterate over the results and access the specific attributes of each NLP annotator. A complete list of attributes can be found in our documentation; here is an example:
Analyze a list of texts (or sentences)
The client can also be used to analyze list of texts or sentences without applying any further segmentation. This will keep the original structure of your texts, which can be helpful, for example, if you’re analyzing conversations. Let’s consider the following example:
In this case, you just need to call the method client.analyze_sentences():
The output will keep the original segmentation:
On this post we have shown how easy it is to send requests to our NLP API using our Python SDK and analyze your own texts. The following code snippet resumes the workflow explained above. Don’t forget to replace USER_ID and USER_KEY with your own API credentials.
Take a look at our documentation to learn more about the NLP tools we provide.
Do you need inspiration? Go to our use case demos and see how you can integrate different tools.
In our NLP demos section you can also try our tools and find examples of the output of each module.