Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.

Commit 38753fd

Browse files
🔥 Update dependencies
1 parent d78e89b commit 38753fd

File tree

7 files changed

+1056
-2962
lines changed

7 files changed

+1056
-2962
lines changed

.travis.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: node_js
2-
dist: trusty
32
sudo: required
4-
node_js: 8
3+
node_js: 12
54
script:
65
- npm run test
76

@@ -18,13 +17,10 @@ before_deploy: npm install -g bx-blue-green
1817
deploy:
1918
- provider: script
2019
skip_cleanup: true
21-
script:
22-
- bx-blue-green-travis
20+
script: bx-blue-green-travis
2321
on:
2422
branch: master
2523
repo: watson-developer-cloud/natural-language-classifier-nodejs
2624
- provider: script
2725
skip_cleanup: true
2826
script: npx semantic-release
29-
on:
30-
node: 8

README.md

+4-15
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,21 @@ You can view a [demo](https://natural-language-classifier-demo.ng.bluemix.net/)
2626
- Log in to your IBM Cloud account.
2727
- Click **Create**.
2828
- Click **Show** to view the service credentials.
29-
- Copy the `apikey` value, or copy the `username` and `password` values if your service instance doesn't provide an `apikey`.
29+
- Copy the `apikey` value.
3030
- Copy the `url` value.
3131

3232
## Configuring the application
3333

3434
1. The Natural Language Classifier service must be trained before you can successfully use this application. The training data is provided in the file `training/weather_data_train.csv`.
3535
If you have `username` and `password` credentials, train a classifier by using the following command:
3636

37-
```none
38-
curl -i -u "<username>":"<password>" \
37+
```sh
38+
curl -i -u "apikey":"<apikey>" \
3939
-F training_data=@training/weather_data_train.csv \
4040
-F training_metadata="{\"language\":\"en\",\"name\":\"TutorialClassifier\"}" \
4141
"<url>/v1/classifiers"
4242
```
43-
Make sure to replace `<username>`, `<password>` and `<url>`.
44-
If you have `apikey` credentials, use the word "apikey" as your username and your `apikey` as the password.
43+
Make sure to replace `<apikey>` and `<url>`.
4544
After running the command, copy the value for `classifier_id`.
4645

4746
2. In the application folder, copy the *.env.example* file and create a file called *.env*
@@ -59,16 +58,6 @@ You can view a [demo](https://natural-language-classifier-demo.ng.bluemix.net/)
5958
NATURAL_LANGUAGE_CLASSIFIER_URL=https://gateway.watsonplatform.net/natural-language-classifier/api
6059
```
6160
62-
- If your service instance uses `username` and `password` credentials, add the `NATURAL_LANGUAGE_CLASSIFIER_USERNAME` and `NATURAL_LANGUAGE_CLASSIFIER_PASSWORD` variables to the *.env* file.
63-
64-
Example *.env* file that configures the `username`, `password`, and `url` for a Natural Language Classifier service instance hosted in the Sydney region:
65-
66-
```
67-
NATURAL_LANGUAGE_CLASSIFIER_USERNAME=522be-7b41-ab44-dec3-g1eab2ha73c6
68-
NATURAL_LANGUAGE_CLASSIFIER_PASSWORD=A4Z5BdGENrwu8
69-
NATURAL_LANGUAGE_CLASSIFIER_URL=https://gateway-syd.watsonplatform.net/natural-language-classifier/api
70-
```
71-
7261
8. Add the `CLASSIFIER_ID` to the previous properties
7362
7463
```

app.js

+10-17
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,20 @@ const express = require('express');
1818

1919
const app = express();
2020
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1');
21+
const { IamAuthenticator } = require('ibm-watson/auth');
2122

2223
// Bootstrap application settings
2324
require('./config/express')(app);
2425

2526
// Create the service wrapper
2627

27-
let classifier;
28-
29-
if (process.env.NATURAL_LANGUAGE_CLASSIFIER_IAM_APIKEY && process.env.NATURAL_LANGUAGE_CLASSIFIER_IAM_APIKEY !== '') {
30-
classifier = new NaturalLanguageClassifierV1({
31-
url: process.env.NATURAL_LANGUAGE_CLASSIFIER_URL || '<service-url>',
32-
iam_apikey: process.env.NATURAL_LANGUAGE_CLASSIFIER_IAM_APIKEY || '<iam_apikey>',
33-
iam_url: process.env.ASSISTANT_IAM_URL || 'https://iam.bluemix.net/identity/token',
34-
});
35-
} else {
36-
classifier = new NaturalLanguageClassifierV1({
37-
url: process.env.NATURAL_LANGUAGE_CLASSIFIER_URL || '<service-url>',
38-
username: process.env.NATURAL_LANGUAGE_CLASSIFIER_USERNAME || '<username>',
39-
password: process.env.NATURAL_LANGUAGE_CLASSIFIER_PASSWORD || '<password>',
40-
});
41-
}
28+
const classifier = new NaturalLanguageClassifierV1({
29+
version: '2018-04-05',
30+
authenticator: new IamAuthenticator({
31+
apikey: process.env.NATURAL_LANGUAGE_CLASSIFIER_IAM_APIKEY || '<api-key>',
32+
}),
33+
url: process.env.NATURAL_LANGUAGE_CLASSIFIER_URL,
34+
});
4235

4336
app.get('/', (req, res) => {
4437
res.render('index', {
@@ -52,12 +45,12 @@ app.get('/', (req, res) => {
5245
app.post('/api/classify', (req, res, next) => {
5346
classifier.classify({
5447
text: req.body.text,
55-
classifier_id: process.env.CLASSIFIER_ID || '<classifier-id>',
48+
classifierId: process.env.CLASSIFIER_ID || '<classifier-id>',
5649
}, (err, data) => {
5750
if (err) {
5851
return next(err);
5952
}
60-
return res.json(data);
53+
return res.json(data.result);
6154
});
6255
});
6356

manifest.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
declared-services:
2-
my-nlc-service:
3-
label: natural_language_classifier
4-
plan: standard
51
applications:
6-
- services:
7-
- my-nlc-service
8-
name: natural-language-classifier-demo
2+
- name: natural-language-classifier-demo
93
command: npm start
104
path: .
115
memory: 512M

0 commit comments

Comments
 (0)