Easily Perform Powerful Text Analysis With Google Machine Learning
Google Cloud offers a Natural Language API which allows a developer to take unstructured text as an input and utilize Google’s machine learning capabilities to derive insight from it. They have a number of different operations that can be performed on a piece of text including syntax analysis, entity analysis, custom entity extraction, sentiment analysis, custom sentiment analysis, content classification, custom content classification, custom models, and spatial structure understanding. The Google Natural Language APIs feature multi-language support, large dataset support, and give you access to Google’s AutoML models. RAD Studio and Delphi gives you easy access to all of this Natural Language processing capability via Google’s REST API. RAD Studio includes a tool called the REST Debugger where you can configure all of your REST API settings and then export them as components into your Delphi application. This includes wiring up the incoming data automatically to an in memory database table (TFDMemTable). It literally takes only a few minutes to get up and running with Google Cloud’s powerful Natural Language API from within Delphi and RAD Studio. Additionally, the application built and the source code available at the end of this blog post uses Delphi’s cross-platform/multi-platform FireMonkey framework which supports Windows, Linux, macOS, Android, and iOS with a single codebase and single responsive UI. Let’s dive into the Google Cloud Natural Language API and how to build a desktop and mobile application utilizing it’s REST API. What can I do with the Google Cloud Natural Language API? On Google’s website the full REST reference for the Natural Language API is available. Here are the different endpoints available in the API: analyzeEntities POST /v1beta2/documents:analyzeEntities analyzeEntitySentiment POST /v1beta2/documents:analyzeEntitySentiment analyzeSentiment POST /v1beta2/documents:analyzeSentiment analyzeSyntax POST /v1beta2/documents:analyzeSyntax annotateText POST /v1beta2/documents:annotateText classifyText POST /v1beta2/documents:classifyText How can I set up the Natural Language API credentials? An API key is needed in order to use the above REST APIs. You will need to visit the following URL which will walk you through creating a project and enabled the Natural Language API on your Google Cloud account. https://cloud.google.com/natural-language/docs/quickstart-client-libraries Once you have the Natural Language API enabled on your account you can visit the Credentials page to create an API Key. https://console.cloud.google.com/apis/credentials How do I connect to the Google Cloud Natural Language API REST end point with Delphi? I built a sample application in Delphi using the REST Debugger which utilizes the analyzeEntities end point. There is also a video tutorial for using the RAD Studio REST Debugger available to automatically create the REST components and paste them into your app. The analyzeEntiries endpoint breaks down the content of the text into entities that are contained within Google’s machine learning database. Entities have their own id (called mid), a type classification (like ‘ORGANIZATION’), and contain additional meta data like a Wikipedia URL and the like to provide context to that entity. Here are the three components in Delphi that make the API call. They are the TRESTClient, TRESTRequest, and TRESTResponse. You will notice that the API URL is set on the BaseURL of TRESTClient. On the TRESTRequest component you will see that the request type is set to rmPOST, the ContentType is set to ctAPPLICATION_JSON, and that it contains one request body for the POST which is set to: You will also notice that on the TRESTResponse component the RootElement […]
