Text Metrics Vector

Turbo 360 Vectors are a great way of accelerating the development process so you can roll features out more quickly than has ever been possible. With Vectors, there is no need to configure a server or backend, all you need to do is hit the API endpoint, and voila! It just works. You can create your own Vectors for applications you’ve built, and also share them with teammates or sell them in the Vector Marketplace at a price of your choosing to actually earn income.

The Text Metrics Vector was built to provide the ability to analyze text on your website. It is useful for learning more about comments, reviews, blog posts, etc. It provides data such as sentiment, processed versions of the given text, and word frequencies. The following is a simple example that demonstrates how to use this vector.

Documentation

The base endpoint for this vector, which will need a query parameter, is:

https://production.turbo360-vector.com/text-metrics-nlugpj/metrics

Using the Vector

Step 1

Enter the language into the following endpoint as the ‘lang’ query parameter:

https://production.turbo360-vector.com/text-metrics-nlugpj/metrics?lang=en&text=Hello, how are you doing today?

The language parameter is used for proper removal of stopwords. These are words such as ‘a’, ‘the’, and ‘what’, which have no effect on the meaning of the text. If this parameter is omitted, it will default to English. The available languages are:

Step 2

Find text that you would like to be processed, or use the same example we just tried “Hello, how are you doing today?”

Enter the text into the following endpoint as the ‘text’ query parameter:

https://production.turbo360-vector.com/text-metrics-nlugpj/metrics?lang=en&text=Hello, how are you doing today? 

JSON Payload

The JSON payload returned by this vector will contain the following information:

Use Case Example

In the following example, we will see how to use the Text Metrics to analyze reviews and save the data in the Turbo 360 Datastore.

Getting Started

First, make sure you have Node version 6 or higher installed:

$ node -v

Then, run the following commands:

$ sudo npm i -g gulp
$ sudo npm i -g webpack
$ sudo npm i -g turbo-cli

Create a new Turbo 360 project and install the required Node modules:

$ turbo new text-metrics-demo
$ cd text-metrics-demo
$ npm install

Head to Turbo 360 and create an account if you don’t already have one. Create a new app and give it a name such as “text-metrics-demo”. Copy the APP ID from the right side of the window, then connect your local source code to this Turbo 360 project by running:

$ turbo app PASTE_APP_ID_HERE
$ turbo deploy

index.mustache

We are going to be using the Story theme provided by Turbo 360 for this demo, so run the following command:

$ turbo theme story

We want to be able to submit reviews for this example, so we need to create an HTML form that will be used to send in the reviews. Modify your index.mustache file in the views directory so it looks like this:

If you run the devserver:

$ turbo devserver

and navigate to localhost:3000 in your browser, you should see a web page that looks like this:

At this point, submitting a review won’t do anything, so we need to create a new route to handle this.

metrics.js

Create a file called metrics.js in the routes directory:

$ cd routes
$ touch metrics.js

This file will be responsible for sending an HTTP request to the Text Metrics vector and adding the returned data to the Turbo 360 Datastore. We’re going to need the Superagent module for this, so install it like so:

$ npm install -S superagent

Open the file app.js and connect the new route:

metrics.js will be used to receive the reviews submitted via our HTML form, then call the Text Metrics Vector, and finally add the returned data to the Turbo 360 Datastore:

Finishing Up

If you run the devserver command and navigate back to localhost:3000 and submit a review, you will see the JSON data returned from the Text Metrics vector. You can also check your Turbo 360 Datastore and you will see that this data has been added under the name “Metrics”. You can test this on the live website by running the command:

$ turbo deploy

and using your browser to navigate to the URL provided in the terminal.


For questions or comments regarding this article, please contact matthew@turbo360.co.