Languages Magazine

The MindMeld API: Getting Started With the JavaScript SDK

By Expectlabs @ExpectLabs

Are you ready to add voice-driven content discovery features into your JavaScript apps? The tutorial above gives an in-depth look at how to get the ball rolling with the MindMeld JavaScript SDK.

When you’re done, don’t forget to check out our screencasts on the iOS and Android SDKs. Thanks for watching!

TRANSCRIPT:

This screencast will describe how you can use the MindMeld JavaScript SDK to get started building applications that run in browsers. To get started, we’ll first create an account on developer.expectlabs.com. This is the developer console page displaying information about each of my applications and links to the developer tools. The first thing we’re going to need to do is crawl some data. Let’s crawl this Wikia about Seinfeld called WikiSein. So let’s head over to our Crawl Manager, and start a crawl. To do that, we have to add the Wikia domain and exclude any pages linking to images. Click “add domain,” enter http://seinfeld.wikia.com/wiki, and add .png & .jpg to the blacklist.

The Wiki contains about a 1000 pages, and the crawler examines approximately 1 page / second so it should take around 20 minutes for the crawl to finish. For the rest of the screencast, I will use another application, where I have already finished crawling the Seinfeld wiki.

Now, the easiest way to get started with the SDK is to download the minified version of mindmeld-2.0.js from here. You can also check-out the public mindmeld-js-sdk repository here. Lastly, you can install the SDK as a bower component like this: bower install mindmeld-js-sdk.

mindmeld.js currently depends on jQuery, so you’ll need to include both files in your app’s HTML file. For the sake of simplicity, however, I’ll be doing the rest of this screencast in JSFiddle, an online sandbox for JavaScript and HTML. In the fiddle, I have already included jQuery as a dependency, and loaded mindmeld-2.0.min.js as an external dependency. In the fiddle, I have also included 2 logging sections so we can log messages and pretty-print JSON data via the functions log and logJSON, respectively. Now that we have our environment set up, it’s time to get started actually using the SDK!

The first thing we need to do to start using the SDK is call MM.init with a config object specifying your app id and an onInit callback. Get your app id from the developer console and add it as a parameter in your config. In our onMMInit function, let’s log a message and display the SDK version.

To start making calls to our API, we need a user token. The API supports two mechanisms for obtaining a token with user privileges: simple user authentication. We’ll be obtaining a token via simple user authentication here, which requires the app secret. Simple user authentication allows you to obtain a user token by submitting valid administrator credentials along with a set of credentials that uniquely identify the users of your application.

Let’s create our credentials object so we can get a new user token. Obtain your appsecret from the developer console page. All entity extraction and document ranking happens inside of a MindMeld session. Now, let’s create a new, private session, named ‘seinfeld session.’ Using this SDK, you create you own session to which you can later add text entries and fetch relevant documents.

In addition to the push events that indicate that API objects have changed, you can also create custom push events. In the following example, I’ll show you how to subscribe to a custom push event on the user channel, and then publish a custom push event with a on that same channel. I’ll also show you how to do the same on the session channel. And that concludes our screencast on the MindMeld JavaScript SDK. Thanks for watching!

TRANSCRIPT:

This screencast will describe how you can use the MindMeld JavaScript SDK to get started building applications that run in browsers. To get started, we’ll first create an account on developer.expectlabs.com. This is the developer console page displaying information about each of my applications and links to the developer tools. The first thing we’re going to need to do is crawl some data. Let’s crawl this Wikia about Seinfeld called WikiSein. So let’s head over to our Crawl Manager, and start a crawl. To do that, we have to add the Wikia domain and exclude any pages linking to images. Click “add domain,” enter http://seinfeld.wikia.com/wiki, and add .png & .jpg to the blacklist.
The Wiki contains about a 1000 pages, and the crawler examines approximately 1 page / second so it should take around 20 minutes for the crawl to finish. For the rest of the screencast, I will use another application, where I have already finished crawling the Seinfeld wiki.
Now, the easiest way to get started with the SDK is to download the minified version of mindmeld-2.0.js from here. You can also check-out the public mindmeld-js-sdk repository here. Lastly, you can install the SDK as a bower component like this: bower install mindmeld-js-sdk.
mindmeld.js currently depends on jQuery, so you’ll need to include both files in your app’s HTML file. For the sake of simplicity, however, I’ll be doing the rest of this screencast in JSFiddle, an online sandbox for JavaScript and HTML. In the fiddle, I have already included jQuery as a dependency, and loaded mindmeld-2.0.min.js as an external dependency. In the fiddle, I have also included 2 logging sections so we can log messages and pretty-print JSON data via the functions log and logJSON, respectively. Now that we have our environment set up, it’s time to get started actually using the SDK!
The first thing we need to do to start using the SDK is call MM.init with a config object specifying your app id and an onInit callback. Get your app id from the developer console and add it as a parameter in your config. In our onMMInit function, let’s log a message and display the SDK version.
To start making calls to our API, we need a user token. The API supports two mechanisms for obtaining a token with user privileges: simple user authentication. We’ll be obtaining a token via simple user authentication here, which requires the app secret. Simple user authentication allows you to obtain a user token by submitting valid administrator credentials along with a set of credentials that uniquely identify the users of your application.
Let’s create our credentials object so we can get a new user token. Obtain your <appsecret> from the developer console page. All entity extraction and document ranking happens inside of a MindMeld session. Now, let’s create a new, private session, named ‘seinfeld session.’ Using this SDK, you create you own session to which you can later add text entries and fetch relevant documents.
In addition to the push events that indicate that API objects have changed, you can also create custom push events. In the following example, I’ll show you how to subscribe to a custom push event on the user channel, and then publish a custom push event with a on that same channel. I’ll also show you how to do the same on the session channel. And that concludes our screencast on the MindMeld JavaScript SDK. 


Back to Featured Articles on Logo Paperblog

Paperblog Hot Topics

Magazines