{"id":19403167,"url":"https://github.com/watson-developer-cloud/natural-language-understanding-code-pattern","last_synced_at":"2025-04-24T07:32:42.319Z","repository":{"id":55074704,"uuid":"234402979","full_name":"watson-developer-cloud/natural-language-understanding-code-pattern","owner":"watson-developer-cloud","description":"Natural Language Understanding Code Pattern","archived":false,"fork":false,"pushed_at":"2021-10-15T15:47:47.000Z","size":1391,"stargazers_count":2,"open_issues_count":0,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-03T01:33:55.021Z","etag":null,"topics":["ibm","ibm-watson","nlp","watson-natural-language"],"latest_commit_sha":null,"homepage":"https://natural-language-understanding-code-pattern.ng.bluemix.net/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/watson-developer-cloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-16T20:11:51.000Z","updated_at":"2022-01-20T00:30:46.000Z","dependencies_parsed_at":"2022-08-14T11:10:49.028Z","dependency_job_id":null,"html_url":"https://github.com/watson-developer-cloud/natural-language-understanding-code-pattern","commit_stats":null,"previous_names":[],"tags_count":4,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fnatural-language-understanding-code-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fnatural-language-understanding-code-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fnatural-language-understanding-code-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fnatural-language-understanding-code-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/watson-developer-cloud","download_url":"https://codeload.github.com/watson-developer-cloud/natural-language-understanding-code-pattern/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250583071,"owners_count":21453956,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ibm","ibm-watson","nlp","watson-natural-language"],"created_at":"2024-11-10T11:27:29.366Z","updated_at":"2025-04-24T07:32:41.720Z","avatar_url":"https://github.com/watson-developer-cloud.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 style=\"font-weight: bold;\"\u003e# DEPRECATED\u003c/h1\u003e\n\u003ch2\u003e\n  This code pattern is no longer supported. You can find the newly supported Natural Language Understanding Pattern\n  \u003ca href=\"https://github.com/IBM/natural-language-understanding-code-pattern\"\u003e\n    here.\n  \u003c/a\u003e\n\u003c/h2\u003e\n\u003ch1 align=\"center\" style=\"border-bottom: none;\"\u003e🔎 Natural Language Understanding Code Pattern \u003c/h1\u003e\n\u003ch3 align=\"center\"\u003eNatural Language Understanding is a collection of APIs that offer text analysis through natural language processing. This set of APIs can analyze text to help you understand its concepts, entities, keywords, sentiment, and more. Additionally, you can create a custom model for some APIs to get specific results that are tailored to your domain.\u003c/h3\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://travis-ci.org/watson-developer-cloud/natural-language-understanding-code-pattern\"\u003e\n    \u003cimg alt=\"Travis\" src=\"https://travis-ci.org/watson-developer-cloud/natural-language-understanding-code-pattern.svg?branch=master\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"#badge\"\u003e\n    \u003cimg alt=\"semantic-release\" src=\"https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\u003c/p\u003e\n\nDemo: https://natural-language-understanding-code-pattern.ng.bluemix.net/\n\n### Flow\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"architecture\" width=\"600\" src=\"./public/architecture.png\"\u003e\n\u003c/p\u003e\n\n1. User sends messages to the application (running locally, in the IBM Cloud or in IBM Cloud Pak for Data).\n1. The application sends the user message to IBM Watson Natural Language Understanding service.\n1. Watson Natural Language Understanding processes the text or url and extract features such us keywords, concepts, categories. The service can be provisioned on either IBM Cloud or IBM Cloud Pak for Data.\n\n## Prerequisites\n\n### Public Cloud\n\n1. Sign up for an [IBM Cloud account](https://console.bluemix.net/registration/).\n1. Download the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview).\n1. Create an instance of the Natural Language Understanding service and get your credentials:\n   - Go to the [Natural Language Understanding](https://console.bluemix.net/catalog/services/natural-language-understanding) page in the IBM Cloud Catalog.\n   - Log in to your IBM Cloud account.\n   - Click **Create**.\n   - Click **Show** to view the service credentials.\n   - Copy the `apikey` value.\n   - Copy the `url` value.\n\n### Cloud Pak for Data\n\nTo use this code pattern with a Natural Language Classifier instance provisioned on Cloud Pak for Data, you can use your CPD `username` and `password` credentials or an `access_token` to authenticate your requests. You also need the service `url` as described [here](https://cloud.ibm.com/apidocs/natural-language-understanding/natural-language-understanding-data#authentication).\n\n## Configuring the application\n\nDepending on where your service instance is you may have different ways to download the credentials file.\n\n\u003e Need more information? See the [authentication wiki](https://github.com/IBM/node-sdk-core/blob/master/AUTHENTICATION.md).\n\n### Automatically\n\nCopy the credential file to the application folder.\n\n**Cloud Pak for Data**\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"CPD\"  width=\"600\" src=\"https://watson-developer-cloud.github.io/images/credentials-cpd.png\"\u003e\n\u003c/p\u003e\n\n**Public Cloud**\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"public\"  width=\"600\" src=\"https://watson-developer-cloud.github.io/images/credentials-public.png\"\u003e\n\u003c/p\u003e\n\n### Manual deployment\n\nThe recommended approach is to download the credentials file and place it in the directory where you code is. Follow the following steps only if you want to manually configure your authentication mechanism.\n\n\u003cdetails\u003e\n\u003csummary\u003eConfigure the authentication manually\u003c/summary\u003e\n\n1.  In the application folder, copy the _.env.example_ file and create a file called _.env_\n\n    ```\n    cp .env.example .env\n    ```\n\n2.  Open the _.env_ file and add the service credentials depending on your environment.\n\n    Example _.env_ file that configures the `apikey` and `url` for a Natural Language Understanding service instance hosted in the US East region:\n\n    ```\n    NATURAL_LANGUAGE_UNDERSTANDING_IAM_APIKEY=X4rbi8vwZmKpXfowaS3GAsA7vdy17Qh7km5D6EzKLHL2\n    NATURAL_LANGUAGE_UNDERSTANDING_URL=https://api.us-east.natural-language-understanding.watson.cloud.ibm.com/\n    ```\n\n    - **CPD using username and password:** If your service instance is running in Cloud Pak for Data and you want to use `username` and `password` credentials, add the `NATURAL_LANGUAGE_UNDERSTANDING_USERNAME` and `NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD` variables to the _.env_ file.\n\n      Example _.env_ file that configures the `username`, `password`, and `url` for a Natural Language Understanding service instance:\n\n      ```\n      NATURAL_LANGUAGE_UNDERSTANDING_USERNAME=admin\n      NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD=password\n      NATURAL_LANGUAGE_UNDERSTANDING_URL=https://{cpd-url}:{cpd-port}/natural-language-understanding/api\n\n      NATURAL_LANGUAGE_UNDERSTANDING_AUTH_TYPE=cp4d\n      NATURAL_LANGUAGE_UNDERSTANDING_AUTH_URL=https://{cpd-url}:{cpd-port}/v1/preauth/validateAuth\n\n      # Only needed if using a self-signed certificate\n      NATURAL_LANGUAGE_UNDERSTANDING_AUTH_DISABLE_SSL=true\n      NATURAL_LANGUAGE_UNDERSTANDING_DISABLE_SSL=true\n      ```\n\n    - **CPD using access token:** If your service instance is running in Cloud Pak for Data and you want to use the `access_token` from the service instance detail page.\n\n      ```\n      NATURAL_LANGUAGE_UNDERSTANDING_BEARER_TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.ey...\n      NATURAL_LANGUAGE_UNDERSTANDING_URL=https://{cpd-url}:{cpd-port}/natural-language-understanding/api\n      NATURAL_LANGUAGE_UNDERSTANDING_AUTH_TYPE=bearerToken\n      ```\n\n\u003c/details\u003e\n\n## Running locally\n\n1. Install the dependencies\n\n   ```\n   npm install\n   ```\n\n1. Build the application\n\n   ```\n   npm run build\n   ```\n\n1. Run the application\n\n   ```\n   npm run dev\n   ```\n\n1. View the application in a browser at `localhost:3000`\n\n## Deploying to IBM Cloud as a Cloud Foundry Application\n\nClick on the button below to deploy this demo to the IBM Cloud.\n\n[![Deploy to IBM Cloud](https://cloud.ibm.com/devops/setup/deploy/button.png)](https://cloud.ibm.com/devops/setup/deploy?repository=https://github.com/watson-developer-cloud/natural-language-understanding-code-pattern)\n\n### Manually\n\n1. Build the application\n\n   ```\n   npm run build\n   ```\n\n1. Login to IBM Cloud with the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview)\n\n   ```\n   ibmcloud login\n   ```\n\n1. Target a Cloud Foundry organization and space.\n\n   ```\n   ibmcloud target --cf\n   ```\n\n1. Edit the _manifest.yml_ file. Change the **name** field to something unique. For example, `- name: my-app-name`.\n1. Deploy the application\n\n   ```\n   ibmcloud app push\n   ```\n\n1. View the application online at the app URL, for example: https://my-app-name.mybluemix.net\n\n## Deploying to OpenShift\n\nThis code pattern can be deployed to any OpenShift cluster or [Minishift](https://www.okd.io/minishift) running 3.2 or above.\n\n### Creating a project\n\nAfter logging in with `oc login`, ensure that you have a project set up. If not, create one as follows:\n\n```\noc new-project nlu-project --display-name=\"NLU Code Pattern\"\n```\n\nEnsure that your current project is set.\n\n```bash\noc project nlu-project\n```\n\n### Automatic deployment\n\nRun the deploy.sh script:\n\n```\nsh openshift/deploy.sh\n```\n\nThe script will run until the app is deployed and available.\n\n### Manual deployment\n\n\u003cdetails\u003e\n\u003csummary\u003eManually deploy to openshift\u003c/summary\u003e\n\n#### Prepare the required parameters\n\nThe template for this example is located at [template.yaml](openshift/template.yaml).\n\nFirst, list the available parameters:\n\n```bash\noc process --parameters -f openshift/template.yaml\n```\n\nThe output will look like:\n\n```\nNAME                                          DESCRIPTION                                                                                               GENERATOR           VALUE\nAPP_NAME                                      The name assigned to all of the frontend objects defined in this template.                                                    nlu-code-pattern\nNATURAL_LANGUAGE_UNDERSTANDING_AUTH_TYPE      How to authenticate with the NLU service, possible values are: iam, cp4d, bearerToken                                         bearerToken\nNATURAL_LANGUAGE_UNDERSTANDING_BEARER_URL     The service URL.\nNATURAL_LANGUAGE_UNDERSTANDING_BEARER_TOKEN   Cloud Pak for Data bearer token.\nNATURAL_LANGUAGE_UNDERSTANDING_APIKEY         IBM Cloud IAM apikey from the service instance page.\nNATURAL_LANGUAGE_UNDERSTANDING_USERNAME       Cloud Pak for Data username of user with access to the service instance.\nNATURAL_LANGUAGE_UNDERSTANDING_PASSWORD       Cloud Pak for Data password of user with access to the service instance.\nNAMESPACE                                     The OpenShift Namespace where the ImageStream resides.                                                                        openshift\nAPPLICATION_DOMAIN                            The exposed hostname that will route to the Node.js service, if left blank a value will be defaulted.                         nlu-code-pattern\nSOURCE_REPOSITORY_URL                         The URL of the repository with your application source code.                                                                  https://github.com/watson-developer-cloud/natural-language-understanding-code-pattern\nSOURCE_REPOSITORY_REF                         Set this to a branch name, tag or other ref of your repository if you are not using the default branch.\n```\n\nDepending on where your service instance is running you may have to provide different parameters to this application. Follow the [instructions](#manual-deployment) on how to run the application locally and create the `.env` file with the service credentials. The same values will be used when deploying to OpenShift.\n\nCreate the template with the values from the previous step.\n\n```\noc new-app -f openshift/template.yaml --ignore-unknown-parameters=true --param-file ./env\n```\n\n#### Check the status\n\nTo check the status of the application run:\n\n```bash\noc status\n```\n\nWhich should return something like:\n\n```\nIn project NLU Code Pattern Project (nlu-project) on server https://10.2.2.2:8443\n\n  svc/nlu-code-pattern - 172.30.108.183:8080\n  dc/nlu-code-pattern deploys istag/nlu-code-pattern:latest \u003c-\n    bc/nlu-code-pattern source builds https://... on openshift/nodejs:12\n      build #1 running for 7 seconds\n    deployment #1 waiting on image or update\n```\n\n#### Custom Routing\n\nAn OpenShift route exposes a service at a host name, like www.example.com, so that external clients can reach it by name.\n\nDNS resolution for a host name is handled separately from routing; you may wish to configure a cloud domain that will always correctly resolve to the OpenShift router, or if using an unrelated host name you may need to modify its DNS records independently to resolve to the router.\n\nThat aside, let's explore our new web app. `oc new-app` created a new route. To view your new route:\n\n```\noc get route\n```\n\nIn the result you can find all routes in your project and for each route you can find its hostname.\nFind the `nlu-code-pattern` route and use the hostname to navigate to the newly created Node.js web app.\nNotice that you can use the `APPLICATION_DOMAIN` template parameter to define a hostname for your app.\n\n#### Optional diagnostics\n\nIf the build is not yet started (you can check by running `oc get builds`), start one and stream the logs with:\n\n```\noc start-build nlu-code-pattern --follow\n```\n\nDeployment happens automatically once the new application image is available. To monitor its status either watch the web console or execute `oc get pods` to see when the pod is up. Another helpful command is\n\n```\noc get svc\n```\n\nThis will help indicate what IP address the service is running, the default port for it to deploy at is 8080. Output should look like:\n\n```\nNAME              CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE\nnlu-code-pattern  172.30.249.251   \u003cnone\u003e        8080/TCP   7m\n```\n\n\u003c/details\u003e\n\n## Tests\n\n#### Unit tests\n\nRun unit tests with:\n\n```\nnpm run test:components\n```\n\nSee the output for more info.\n\n#### Integration tests\n\nFirst you have to make sure your code is built:\n\n```\nnpm run build\n```\n\nThen run integration tests with:\n\n```\nnpm run test:integration\n```\n\n## Directory structure\n\n```none\n.\n├── app.js                      // express routes\n├── config                      // express configuration\n│   ├── error-handler.js\n│   ├── express.js\n│   └── security.js\n├── package.json\n├── openshift                   // openshift template\n├── public                      // static resources\n├── server.js                   // entry point\n├── test                        // integration tests\n└── src                         // react client\n    ├── __test__                // unit tests\n    └── index.js                // app entry point\n```\n\n## License\n\nThis sample code is licensed under the [MIT License](https://opensource.org/licenses/MIT).\n\n## Open Source @ IBM\n\nFind more open source projects on the [IBM Github Page](http://ibm.github.io/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatson-developer-cloud%2Fnatural-language-understanding-code-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwatson-developer-cloud%2Fnatural-language-understanding-code-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatson-developer-cloud%2Fnatural-language-understanding-code-pattern/lists"}