Build a simple demo application Watson Films

Source: Internet
Author: User
Keywords Ibm watson films demo application

This article builds a simple demo application by using Watson Question and Answer (q&a) technology and the Q&a APIs exposed by Watson. Watson Films. Cognition exists in almost any activity that human beings do, such as language comprehension, sensation, judgment, athletic skills, learning, spatial processing and social behavior. We are increasingly expected to use machines that exhibit the same cognitive behavior. IBM Watson represents the first step towards a cognitive system, a new era of computing. In addition to using programming calculations, Watson has 3 big features that make it truly unique:

Natural language Processing

Assumption Generation and evaluation

Dynamic Learning

IBM Watson's combination of these 3 powerful features through unprecedented and unique ways has fundamentally changed the way companies focus on solving problems quickly. IBM Watson is a natural language quiz system that does not use prepared answers, but rather based on the knowledge it acquires to determine the answer and the associated confidence level.

Watson has inspired many developers to envision new innovative application concepts, using cognitive elements to provide users with a better, more personalized experience. Applications supported by Watson can do more than simply data processing, and can find associations, build hypotheses, and learn from the results. This article builds a simple demo application by using Watson Question and Answer technology and the Question and Answer APIs (QAAPI) exposed by Watson. Watson Films.

Note: To fully run the "Watson Films" application in this article, you must have access to an instance of IBM Watson. To access an instance of IBM Watson, please refer to Watson Developer Cloud Enterprise (PDF file) and/or apply to join the Watson Ecosystem program. To help you understand Watson's input and output, we have provided the Watson QAAPI request and Response JSON sample under the Watson_films_dw/samples folder in the DevOps Services project. Thank you for your understanding!

The application will be hosted and managed on IBM bluemix™, Bluemix is a Cloud Foundry PaaS for building, managing, and running various types of applications (WEB, mobile, large data, and smart devices). The code for the application will be managed by.

Characteristics of the cognitive system

Cognitive system:

manipulating the complexities of human language and understanding acquiring and processing massive structured and unstructured (large) data generation and evaluating myriad possibilities based solely on relevant evidence to weigh and evaluate responses to provide scenario-specific recommendations, insights and guidance to continuously improve knowledge and learning support in each iteration and interaction making decisions at impact points Can scale

with tasks

These systems use similar human characteristics to communicate and process ideas. Combined with the intrinsic advantages of digital computing, they can solve problems on a larger scale with higher accuracy and flexibility. Watson is an example of a cognitive system. It can comb the human language and infer between text messages, with similar accuracy to humans, but with a much greater speed and range than anyone else. Rule-based methods require an almost unlimited number of rules to capture every situation we might encounter in a language.

Figure 1. Key features of the cognitive system

Prepare to build Watson Films

Watson Films application is a simple demonstration of how to build an application to interact with Watson using Watson Qaapi. The app allows users to ask questions about the movie, especially the American Film Association's 100 big American films, and the general film production issues.

Figure 2. Watson Films Interface

Before answering the user question, IBM Watson must have a knowledge base containing information so that the correct answer can be inferred from it. For this application, we use Wikipedia's content on the list of the 100 Greatest American films ever selected by the American Film Association. The content from Wikipedia is in HTML format. We also use the content from Kodak's essential Reference Guide for filmmakers, which is also in PDF format.

Get Watson Films Code

can try it first! Check out Watson Films demo. To get or view the Watson Films code, you can either click the previous Get or view "code" button or use the IBM DevOps Services and Web IDE in combination. Because this project contains JavaScript, HTML, and CSS code, only the Web IDE may be the only one that needs to be viewed or edited after the project branch is created. To download and set up this project to your local native Eclipse IDE (the Nodeclipse plug-in installed), follow these instructions. You can also create a branch of the Watson Films project to create your own DevOps Services project based on the content of this project.

About Watson Films Code

Watson Films Demo app uses Express to build on Node.js. We also use Bootstrap and slick carousel to construct the user interface and set its style.

The following brief outlines the techniques used:

IBM Watson Watson qaapi–watson a RESTful interface that enables users to ask questions and receive answers from Watson. Node.js-a lightweight platform built on Chrome's JavaScript runtime to easily build fast, scalable server-side network applications Express.js-a Node-oriented Web application framework bootstrap.js– A simple and responsive front-end WEB development framework JQuery-a fast, small, feature-rich JavaScript library ladda– a responsive button toolkit slick carousel– a JavaScript carousel. Bootstrap also has a carousel, but we'd like to try Slick!

About Watson Films Architecture

Watson Films Architecture consists of the following layers and associated components:

View: A responsive front-end user interface built primarily with HTML5, CSS3, Bootstrap, JQuery, and other JavaScript client plug-ins. The view component in this layer allows the user to ask Watson questions through an input point. Controller: A middleware and controller layer based on node.js and Express, exposing RESTful business APIs to view components. This REST API interacts with Watson by invoking Watson Qaapi and processing the response. It can be extended to perform other business operations, including integration with other cognitive services and third-party services. Cognitive backend: IBM Watson digests the content of film and film production. Watson provides a RESTful interface Qaapi. This API allows developers to ask Watson questions about film and film production and receive answers. The answer includes various kinds of information, such as the answer text, Watson's reliability and the evidence to support the answer. Platform and Devops:watson Films applications will be deployed on IBM Bluemix. It also uses DevOps Services to manage code. DevOps Services is responsible for managing Watson Films source code and its deployment to Bluemix. Bluemix hosts responsive front-end user interfaces and Node.js intermediaries, while IBM Watson and its QAAPI are hosted in the IBM Watson developer Cloud.

Figure 3. Watson Films Architecture

Mapping between code and schema

When you review the Watsonfilms code, you see a small number of files and directories in the WATSON_FILMS_DW project root directory. These files and folders are directly related to the schema component.

public/– This directory contains all Watson Films client HTML, CSS, and JavaScript. It is supported by Node.js. watson/– This directory contains the logic used by our REST API. It interacts directly with Watson using Watson Qaapi. app.js– This file launches the WEB server, which hosts our REST API and all client content.

Use Watson experience Manager to ingest relevant content into Watson

IBM Watson provides a web-based toolset called Watson Experience Manager. With these tools, you can:

Upload and manage document creation and management Knowledge Base create training data to teach Watson your domain knowledge use an out-of-the-box UI, submit a question and view the returned answer or reply to test Watson monitor and view usage reports

Figure 4. Watson Experience Manager

Watson can ingest content in a variety of formats, including DOCX, DOC, PDF, HTML, and text. These formats represent most of the unstructured content that exists. For the Watson Films application, we will get the HTML content from Wikipedia for the 100 Best American films selected by the American Film Association. We will also get a PDF document from the essential Reference Guide for filmmakers. We will use Watson experience Manager to upload and retrieve these documents.

Figure 5. Watson Experience Manager-corpus Management

Build and run Watson Films

Requires an IBM DevOps Services account to build and run the Watson Films demo locally. If you do not have an IBM DevOps Services account, you can create an account.

Watson Films demo can be built using eclipse or not using Eclipse. The two methods are described below.

After you download the project and set it locally, you need to access an instance of Watson to run it end-to-end. You also need to change the URL and credentials in the Watson.js file to reflect your own instance of Watson. We have provided many examples of Watson QAAPI request and Response JSON, which can be found under the Watson_films_dw/samples folder.

Building and running with Eclipse/nodeclipse

the 1th step. Install Eclipse to download and install Eclipse (v4.3.2 or later). Install nodeclipse– Drag the Install button to the Eclipse toolbar. 2nd step. Get Code

Watson Films code is contained in a Git repository hosted on IBM DevOps Services. To get the code:

Open Git Perspective: Window->open perspective->git. Clone the repository: The source code is located on the Origin/master branch.

Figure 6. Cloning a repository

Enter the following Git repository Url:https://hub.jazz.net/project/dimascio/watsonfilmsdw. Enter your jazz hub credentials and complete the wizard. 3rd step. Import Watsonfilm project into Eclipse

From the Git perspective, open the Sharable Directory folder and select Import Projects.

Figure 7. Import Project

4th step. Install dependencies

Select Package.json and run NPM install to install dependencies, such as Express. The installation of dependencies is optional. All dependencies are contained in the repository.

Figure 8. Installing dependencies

the 5th step. Run Code

From the Node perspective, select App.js and Run As->node creator.

Figure 9. Run code

Watson Films is now running on port 3001. Point the browser to http://localhost:3001 to use the demo application.

Build and run without using Eclipse/nodeclipse

Git clone Https://username:password@hub.jazz.net/git/dimascio/watsonfilmsdw, where username and password refer to your IBM DevOps Services account. Install Node.js. Run NPM install Express. Run NPM install request. Navigate to the Repository and Watsonfilmsdw/watson_films_dw folder that you cloned. Run node app.js.

Watson Films is now running on port 3001. Point the browser to http://localhost:3001 to use the demo application.

Create a REST API using Node.js

To build our Watson Films REST API using Node.js, we will use the following two modules: Express.js and Request. We have previously described how to install these two modules using NPM install.

the 1th step. Exposing the REST API

Our REST API is simple. It contains only one resource/question. When a POST request is made to/question, the business logic invokes Watson through QAAPI.

With a few lines of simple Node code, the following code snippet from App.js defines our problem resources, creating and starting a Web server.

Listing 1. Defining Problem Resources

//Get access to our Watson Modulevar Watson = require ('./watson/watson ');/the Set up RESTful resources//POST requests to/ Question are handled by ' watson.question ' app.post ('/question ', watson.question);//Start the HTTP Serverhttp.createserver (APP). Listen (App.get (' Port '), function () {console.log (' Express server listening on port ' + App.get (' Port ')); 2nd step. Call Watson Qaapi

In the previous section, we set up a handler function for all POST requests sent to/question. This processing function is defined in a simple Node module named Watson. File Watson/watson.js is responsible for invoking Watson through QAAPI.

Listing 2. Call Watson through QAAPI

Describe The Watson endpoint//specify the information and credentials pertinent to your Watson Instancevar = {  //Enter Watson host name; For example: ' http://www.myhost.com '   host: ',  //Enter Watson instance name; For example: '/deepqa/v1/question '   instance: ',  //enter AUTH info; For example: ' Basic c29tzxvzzxjpzdpzb21lcgfzc3dvcmq= '   auth: '};//Handler for/question POST requests//submits Question to Watson via the IBM Watson qaapi//and returns the Qaapi response.exports.question = function (req, res) { if! Endpoint.host) {  res.send (404, ' Watson host information not supplied. ');  } var uri = endpoint.host + Endpoint.instance; var request = require ("request");  //Form A Proper Watson qaapi Request var questionentity = {  "question": {  "Evidencerequest": {//Ask Watson to return evidence  "Items": 5//asked for Hep answers with evidence },  "qUestiontext ": req.body.question//The question } };  console.log (' Ask Watson: ' + req.body.question + ' @ ' + URI); //Invoke the IBM Watson qaapi synchronously //POST the questionentity and handle the Qaapi response  Request ({  ' URI ': uri,  ' method ': ' POST ',  ' headers ': {  ' content-type ': ' Application/json;charset =utf-8 ',  ' x-synctimeout ': 30,  ' Authorization ': endpoint.auth },  ' json ': questionentity,  The function (error, response, body) { //Return the QAAPI response in the entity body  Res.json (body); });

So what's the use of this code? First, it exports the question function (our handler function) so that the function can be accessed from app.js. The question function accepts two parameters: request req and respond to Res.

The request req should be a string containing the problem text. The question string is then used to create an appropriate Watson QAAPI problem request that conforms to the QAAPI JSON request and Response model.

Finally, the question function uses the request module to synchronize calls to Watson Qaapi, returning the response "as is".

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.