├── .bluemix
└── pipeline.yml
├── .cfignore
├── .env.example
├── .eslintignore
├── .eslintrc.yml
├── .gitignore
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── app.js
├── casper-runner.js
├── config
├── error-handler.js
├── express.js
└── security.js
├── demo.gif
├── manifest.yml
├── package-lock.json
├── package.json
├── payload.json
├── public
├── css
│ └── style.css
├── images
│ └── favicon.ico
└── scripts
│ ├── analytics.js
│ ├── bundle.jsx
│ └── polyfills.js
├── server.js
├── test
├── integration
│ └── test.mainpage.js
├── unit
│ └── test.express.js
└── utils
│ └── handleError.js
└── views
├── Bar.jsx
├── Demo.jsx
├── ErrorMessage.jsx
├── FloatingCta.jsx
├── Input.jsx
├── JsonLink.jsx
├── Layout.jsx
├── Output
├── Categories.jsx
├── Concept.jsx
├── Emotion.jsx
├── Entities.jsx
├── Keywords.jsx
├── MoreInput.jsx
├── Output.jsx
├── OutputTemplate.jsx
├── Relations.jsx
├── SemanticRoles.jsx
├── Sentiment.jsx
└── Syntax.jsx
├── Table.jsx
├── index.jsx
└── utils
├── breakpoints.js
├── colors.js
├── request.js
├── typography.js
├── variables.js
└── zIndices.js
/.bluemix/pipeline.yml:
--------------------------------------------------------------------------------
1 | ---
2 | stages:
3 | - name: Build Stage
4 | inputs:
5 | - type: git
6 | branch: master
7 | service: ${REPO}
8 | jobs:
9 | - name: Build
10 | type: builder
11 | artifact_dir: ''
12 | - name: Deploy Stage
13 | inputs:
14 | - type: job
15 | stage: Build Stage
16 | job: Build
17 | triggers:
18 | - type: stage
19 | jobs:
20 | - name: Deploy
21 | type: deployer
22 | target:
23 | region_id: ${CF_REGION_ID}
24 | organization: ${CF_ORGANIZATION}
25 | space: ${CF_SPACE}
26 | application: ${CF_APP}
27 | script: |-
28 | #!/bin/bash
29 | cf create-service natural-language-understanding free my-nlu-service
30 | # Push app
31 | export CF_APP_NAME="$CF_APP"
32 | cf push "${CF_APP_NAME}"
33 |
--------------------------------------------------------------------------------
/.cfignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | coverage
3 | uploads
4 | logs
5 | npm-debug.log
6 | .idea
7 | .vscode
8 |
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 |
2 | NATURAL_LANGUAGE_UNDERSTANDING_IAM_APIKEY=
3 | NATURAL_LANGUAGE_UNDERSTANDING_URL=https://gateway.watsonplatform.net/natural-language-understanding/api
4 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | # this file is compiled
2 | public/js/index.js
3 | public/scripts/analytics.js
4 | coverage
5 | logs
6 |
--------------------------------------------------------------------------------
/.eslintrc.yml:
--------------------------------------------------------------------------------
1 | env:
2 | browser: true
3 | es6: true
4 | node: true
5 | mocha: true
6 | extends: 'eslint:recommended'
7 | globals:
8 | Atomics: readonly
9 | SharedArrayBuffer: readonly
10 | parserOptions:
11 | ecmaFeatures:
12 | jsx: true
13 | ecmaVersion: 2018
14 | sourceType: module
15 | plugins:
16 | - react
17 | rules: {}
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | coverage
3 | uploads/
4 | .DS_Store
5 | logs/
6 | .env
7 | *.log
8 | coverage/
9 | .idea
10 | .vscode
11 | Bluemix_CLI*
12 | IBM_Cloud_CLI_*
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | sudo: required
3 | node_js: 12
4 | script:
5 | - npm run test
6 | cache:
7 | directories:
8 | - node_modules
9 | env:
10 | global:
11 | - BX_APP=natural-language-understanding-demo
12 | - BX_API=https://api.ng.bluemix.net
13 | - BX_ORGANIZATION=WatsonPlatformServices
14 | - BX_SPACE=demos
15 | before_deploy: npm install -g bx-blue-green
16 | deploy:
17 | - provider: script
18 | skip_cleanup: true
19 | script: bx-blue-green-travis
20 | on:
21 | branch: master
22 | repo: watson-developer-cloud/natural-language-understanding-nodejs
23 | - provider: script
24 | skip_cleanup: true
25 | script: npx semantic-release
26 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Questions
2 |
3 | If you are having problems using the APIs or have a question about the IBM
4 | Watson Services, please ask a question on
5 | [dW Answers](https://developer.ibm.com/answers/questions/ask/?topics=watson)
6 | or [Stack Overflow](http://stackoverflow.com/questions/ask?tags=ibm-watson).
7 |
8 | # Code
9 |
10 | - Our style guide is based on [Google's](https://google.github.io/styleguide/jsguide.html), most of it is automaticaly enforced (and can be automatically applied with `npm run autofix`)
11 | - Commits should follow the [Angular commit message guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines). This is because our release tool uses this format for determining release versions and generating changelogs. To make this easier, we recommend using the [Commitizen CLI](https://github.com/commitizen/cz-cli) with the `cz-conventional-changelog` adapter.
12 |
13 | # Issues
14 |
15 | If you encounter an issue with the Node.js library, you are welcome to submit
16 | a [bug report](https://github.com/watson-developer-cloud/natural-language-understanding-nodejs/issues).
17 | Before that, please search for similar issues. It's possible somebody has
18 | already encountered this issue.
19 |
20 | # Pull Requests
21 |
22 | If you want to contribute to the repository, follow these steps:
23 |
24 | 1. Fork the repo.
25 | 2. Develop and test your code changes: `npm install -d && npm test`.
26 | 3. Travis-CI will run the tests for all services once your changes are merged.
27 | 4. Add a test for your changes. Only refactoring and documentation changes require no new tests.
28 | 5. Make the test pass.
29 | 6. Commit your changes.
30 | 7. Push to your fork and submit a pull request.
31 |
32 | # Developer's Certificate of Origin 1.1
33 |
34 | By making a contribution to this project, I certify that:
35 |
36 | (a) The contribution was created in whole or in part by me and I
37 | have the right to submit it under the open source license
38 | indicated in the file; or
39 |
40 | (b) The contribution is based upon previous work that, to the best
41 | of my knowledge, is covered under an appropriate open source
42 | license and I have the right under that license to submit that
43 | work with modifications, whether created in whole or in part
44 | by me, under the same open source license (unless I am
45 | permitted to submit under a different license), as indicated
46 | in the file; or
47 |
48 | (c) The contribution was provided directly to me by some other
49 | person who certified (a), (b) or (c) and I have not modified
50 | it.
51 |
52 | (d) I understand and agree that this project and the contribution
53 | are public and that a record of the contribution (including all
54 | personal information I submit with it, including my sign-off) is
55 | maintained indefinitely and may be redistributed consistent with
56 | this project or the open source license(s) involved.
57 |
58 | ## Tests
59 |
60 | Ideally, we'd like to see both unit and innervation tests on each method.
61 | (Unit tests do not actually connect to the Watson service, integration tests do.)
62 |
63 | Out of the box, `npm test` runs linting and unit tests, but skips the integration tests,
64 | because they require credentials.
65 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
🚀 Natural Language Understanding Sample Application
2 |
This Node.js app demonstrates some of the Natural Language Understanding service features.
11 |
12 |
13 | Natural 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.
14 |
15 | [](https://natural-language-understanding-demo.ng.bluemix.net)
16 |
17 | ## Prerequisites
18 |
19 | 1. Sign up for an [IBM Cloud account](https://cloud.ibm.com/registration).
20 | 1. Download the [IBM Cloud CLI](https://cloud.ibm.com/docs/cli?topic=cli-getting-started#overview).
21 | 1. Create an instance of the Natural Language Understanding service and get your credentials:
22 | - Go to the [Natural Language Understanding](https://cloud.ibm.com/catalog/services/natural-language-understanding) page in the IBM Cloud Catalog.
23 | - Log in to your IBM Cloud account.
24 | - Click **Create**.
25 | - Click **Show** to view the service credentials.
26 | - Copy the `apikey` value.
27 | - Copy the `url` value.
28 |
29 | ## Configuring the application
30 |
31 | 1. In the application folder, copy the _.env.example_ file and create a file called _.env_
32 |
33 | ```
34 | cp .env.example .env
35 | ```
36 |
37 | 2. Open the _.env_ file and add the service credentials that you obtained in the previous step.
38 |
39 | Example _.env_ file that configures the `apikey` and `url` for a Natural Language Understanding service instance hosted in the US East region:
40 |
41 | ```
42 | NATURAL_LANGUAGE_UNDERSTANDING_IAM_APIKEY=X4rbi8vwZmKpXfowaS3GAsA7vdy17Qh7km5D6EzKLHL2
43 | NATURAL_LANGUAGE_UNDERSTANDING_URL=https://gateway-wdc.watsonplatform.net/natural-language-understanding/api
44 | ```
45 |
46 | ## Running locally
47 |
48 | 1. Install the dependencies
49 |
50 | ```
51 | npm install
52 | ```
53 |
54 | 1. Run the application
55 |
56 | ```
57 | npm start
58 | ```
59 |
60 | 1. View the application in a browser at `localhost:3000`
61 |
62 | ## Deploying to IBM Cloud as a Cloud Foundry Application
63 |
64 | 1. Login to IBM Cloud with the [IBM Cloud CLI](https://cloud.ibm.com/docs/cli?topic=cli-getting-started#overview)
65 |
66 | ```
67 | ibmcloud login
68 | ```
69 |
70 | 1. Target a Cloud Foundry organization and space.
71 |
72 | ```
73 | ibmcloud target --cf
74 | ```
75 |
76 | 1. Edit the _manifest.yml_ file. Change the **name** field to something unique.
77 | For example, `- name: my-app-name`.
78 | 1. Deploy the application
79 |
80 | ```
81 | ibmcloud app push
82 | ```
83 |
84 | 1. View the application online at the app URL.
85 | For example: https://my-app-name.mybluemix.net
86 |
87 | ## Directory structure
88 |
89 | ```none
90 | .
91 | ├── app.js // express routes
92 | ├── config // express configuration
93 | │ ├── express.js
94 | │ └── security.js
95 | ├── manifest.yml
96 | ├── package.json
97 | ├── public // static resources
98 | ├── server.js // entry point
99 | ├── test // tests
100 | └── views // react components
101 | ```
102 |
103 | ## License
104 |
105 | This sample code is licensed under Apache 2.0.
106 | Full license text is available in [LICENSE](LICENSE).
107 |
108 | ## Contributing
109 |
110 | See [CONTRIBUTING](CONTRIBUTING.md).
111 |
112 | ## Open Source @ IBM
113 |
114 | Find more open source projects on the
115 | [IBM Github Page](http://ibm.github.io/).
116 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 IBM Corp. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | const express = require('express');
18 | const NaturalLanguageUnderstandingV1 = require('ibm-watson/natural-language-understanding/v1.js');
19 | const { IamAuthenticator } = require('ibm-watson/auth');
20 |
21 | const app = express();
22 | // Create the service wrapper
23 | const nlu = new NaturalLanguageUnderstandingV1({
24 | version: '2021-10-15',
25 | authenticator: new IamAuthenticator({
26 | apikey: process.env.NATURAL_LANGUAGE_UNDERSTANDING_IAM_APIKEY || 'type-key-here',
27 | }),
28 | url: process.env.NATURAL_LANGUAGE_UNDERSTANDING_URL,
29 | });
30 |
31 | // setup body-parser
32 | const bodyParser = require('body-parser');
33 |
34 | app.use(bodyParser.json());
35 |
36 | // Bootstrap application settings
37 | require('./config/express')(app);
38 |
39 | app.get('/', (req, res) => {
40 | res.render('index');
41 | });
42 |
43 | app.post('/api/analyze', (req, res, next) => {
44 | if (process.env.SHOW_DUMMY_DATA) {
45 | res.json(require('./payload.json'));
46 | } else {
47 | nlu.analyze(req.body, (err, results) => {
48 | if (err) {
49 | return next(err);
50 | }
51 | return res.json({ query: req.body.query, results: results.result });
52 | });
53 | }
54 | });
55 |
56 | // error-handler settings
57 | require('./config/error-handler')(app);
58 |
59 | module.exports = app;
60 |
--------------------------------------------------------------------------------
/casper-runner.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 IBM Corp. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | require('dotenv').config({ silent: true });
17 |
18 | if (!process.env.NATURAL_LANGUAGE_UNDERSTANDING_IAM_APIKEY) {
19 | console.log(
20 | 'Skipping integration tests because NATURAL_LANGUAGE_UNDERSTANDING_IAM_APIKEY is null',
21 | ); // eslint-disable-line
22 | process.exit(0);
23 | }
24 |
25 | const { spawn } = require('child_process');
26 |
27 | const app = require('./app');
28 |
29 | const port = 3000;
30 |
31 | const server = app.listen(port, () => {
32 | console.log('Server running on port: %d', port); // eslint-disable-line
33 |
34 | function kill(code) {
35 | server.close(() => {
36 | process.exit(code);
37 | });
38 | }
39 |
40 | function runTests() {
41 | const casper = spawn('npm', ['run', 'test-integration']);
42 | casper.stdout.pipe(process.stdout);
43 |
44 | casper.on('error', (error) => {
45 | console.log(`ERROR: ${error}`); // eslint-disable-line
46 | server.close(() => {
47 | process.exit(1);
48 | });
49 | });
50 |
51 | casper.on('close', kill);
52 | }
53 |
54 | runTests();
55 | });
56 |
--------------------------------------------------------------------------------
/config/error-handler.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 IBM Corp. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /* eslint no-unused-vars: "off" */
17 |
18 |
19 | module.exports = (app) => {
20 | // catch 404 and forward to error handler
21 | app.use((req, res, next) => {
22 | const err = new Error('Not Found');
23 | err.code = 404;
24 | err.message = 'Not Found';
25 | next(err);
26 | });
27 |
28 | // error handler
29 | app.use((err, req, res, next) => {
30 | const error = {
31 | code: err.code || 500,
32 | error: err.error || err.message,
33 | };
34 | console.log(error); // eslint-disable-line
35 | res.status(error.code).json(error);
36 | });
37 | };
38 |
--------------------------------------------------------------------------------
/config/express.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 IBM Corp. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | // Module dependencies
18 | const express = require('express');
19 | const expressBrowserify = require('express-browserify');
20 | const path = require('path');
21 |
22 |
23 | module.exports = (app) => {
24 | app.enable('trust proxy');
25 | app.set('view engine', 'jsx');
26 | app.engine('jsx', require('express-react-views').createEngine());
27 |
28 |
29 | // Only loaded when running in Bluemix
30 | if (process.env.VCAP_APPLICATION) {
31 | require('./security')(app);
32 | }
33 |
34 | // automatically bundle the front-end js on the fly
35 | // note: this should come before the express.static since bundle.js is in the public folder
36 | const isDev = (app.get('env') === 'development');
37 | const browserifyier = expressBrowserify('./public/scripts/bundle.jsx', {
38 | watch: isDev,
39 | debug: isDev,
40 | extension: ['jsx'],
41 | transform: ['babelify'],
42 | });
43 | if (!isDev) {
44 | browserifyier.browserify.transform('uglifyify', { global: true });
45 | }
46 | app.get('/scripts/bundle.js', browserifyier);
47 |
48 | // Configure Express
49 | app.use(express.static(path.join(__dirname, '..', 'public')));
50 | app.use(express.static(path.join(__dirname, '..', 'node_modules/watson-react-components/dist/')));
51 | };
52 |
--------------------------------------------------------------------------------
/config/security.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 IBM Corp. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | // security.js
18 | const secure = require('express-secure-only');
19 | const rateLimit = require('express-rate-limit');
20 | const helmet = require('helmet');
21 |
22 | module.exports = (app) => {
23 | app.enable('trust proxy');
24 |
25 | // 1. redirects http to https
26 | app.use(secure());
27 |
28 | // 2. helmet with defaults
29 | app.use(helmet());
30 |
31 | // 5. rate limiting.
32 | app.use('/api/', rateLimit({
33 | windowMs: 30 * 1000, // 30 seconds
34 | delayMs: 0,
35 | max: 3,
36 | message: JSON.stringify({
37 | error: 'Too many requests, please try again in 30 seconds.',
38 | code: 429,
39 | }),
40 | }));
41 | };
42 |
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/natural-language-understanding-nodejs/b63b0e8eba99fb116a630fa1c6e0fbd32a6d6bd3/demo.gif
--------------------------------------------------------------------------------
/manifest.yml:
--------------------------------------------------------------------------------
1 | applications:
2 | - name: natural-language-understanding-demo
3 | path: .
4 | buildpacks:
5 | - nodejs_buildpack
6 | command: npm start
7 | memory: 512M
8 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ibm-watson/natural-language-understanding-nodejs",
3 | "version": "0.0.2",
4 | "description": "A sample Node.js app for IBM Cloud that use the IBM Watson Natural Language Understanding service",
5 | "repository": {
6 | "type": "git",
7 | "url": "https://github.com/watson-developer-cloud/natural-language-understanding-nodejs.git"
8 | },
9 | "engines": {
10 | "node": ">=12"
11 | },
12 | "author": "IBM Corp.",
13 | "babel": {
14 | "presets": [
15 | [
16 | "@babel/preset-env",
17 | {
18 | "useBuiltIns": "entry",
19 | "corejs": "3.0"
20 | }
21 | ],
22 | "@babel/preset-react"
23 | ]
24 | },
25 | "license": "Apache-2.0",
26 | "bugs": {
27 | "url": "https://github.com/watson-developer-cloud/natural-language-understanding-nodejs/issues"
28 | },
29 | "scripts": {
30 | "start": "node server.js",
31 | "test-integration": "casperjs test ./test/integration/test.*.js",
32 | "test-integration-runner": "NODE_ENV=test node casper-runner.js",
33 | "test": "npm run lint && npm run test-unit && npm run test-integration-runner",
34 | "test-unit": "mocha test/unit --exit",
35 | "lint": "npx eslint .",
36 | "autofix": "npx eslint --fix .",
37 | "codecov": "npm run test && (codecov || true)"
38 | },
39 | "dependencies": {
40 | "@babel/core": "^7.7.0",
41 | "@babel/preset-env": "^7.7.1",
42 | "@babel/preset-react": "^7.7.0",
43 | "@babel/register": "^7.7.0",
44 | "aphrodite": "^1.2.5",
45 | "babel-eslint": "^10.0.3",
46 | "babelify": "^10.0.0",
47 | "body-parser": "^1.19.0",
48 | "core-js": "^3.4.0",
49 | "css-math": "^0.4.0",
50 | "deep-assign": "^2.0.0",
51 | "dotenv": "^8.2.0",
52 | "es6-promise": "^4.2.8",
53 | "express": "^4.17.1",
54 | "express-browserify": "^1.0.3",
55 | "express-rate-limit": "^5.0.0",
56 | "express-react-views": "^0.11.0",
57 | "express-secure-only": "^0.2.1",
58 | "helmet": "^3.21.2",
59 | "html-to-react": "^1.4.2",
60 | "ibm-watson": "^5.1.0",
61 | "isomorphic-fetch": "^2.2.1",
62 | "language-list": "0.0.3",
63 | "map-range": "^0.1.2",
64 | "numeral": "^2.0.6",
65 | "prop-types": "^15.7.2",
66 | "raf": "^3.4.1",
67 | "react": "^15.6.2",
68 | "react-dom": "^15.6.2",
69 | "react-waypoint": "^8.1.0",
70 | "scroll-to-element": "^2.0.3",
71 | "tween": "^0.9.0",
72 | "uglifyify": "^5.0.2",
73 | "valid-url": "^1.0.9",
74 | "watson-react-components": "^0.6.19",
75 | "watson-ui-components": "^0.6.2",
76 | "whatwg-fetch": "^2.0.4"
77 | },
78 | "devDependencies": {
79 | "casperjs": "^1.1.4",
80 | "codecov": "^3.6.1",
81 | "eslint": "^6.6.0",
82 | "eslint-config-airbnb": "^18.0.1",
83 | "eslint-plugin-import": "^2.18.2",
84 | "eslint-plugin-jsx-a11y": "^6.2.3",
85 | "eslint-plugin-react": "^7.16.0",
86 | "jest": "^24.9.0",
87 | "mocha": "^6.2.2",
88 | "nock": "^11.7.0",
89 | "phantomjs-prebuilt": "^2.1.16",
90 | "supertest": "^4.0.2"
91 | },
92 | "publishConfig": {
93 | "registry": "https://registry.npmjs.org/",
94 | "access": "public"
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/payload.json:
--------------------------------------------------------------------------------
1 | {
2 | "query": {
3 | "text": "In the rugged Colorado Desert of California, there lies buried a treasure ship sailed there hundreds of years ago by either Viking or Spanish explorers. Some say this is legend; others insist it is fact. A few have even claimed to have seen the ship, its wooden remains poking through the sand like the skeleton of a prehistoric beast. Among those who say they’ve come close to the ship is small-town librarian Myrtle Botts. In 1933, she was hiking with her husband in the Anza-Borrego Desert, not far from the border with Mexico. It was early March, so the desert would have been in bloom, its washed-out yellows and grays beaten back by the riotous invasion of wildflowers. Those wildflowers were what brought the Bottses to the desert, and they ended up near a tiny settlement called Agua Caliente. Surrounding place names reflected the strangeness and severity of the land: Moonlight Canyon, Hellhole Canyon, Indian Gorge. To enter the desert is to succumb to the unknowable. One morning, a prospector appeared in the couple’s camp with news far more astonishing than a new species of desert flora: He’d found a ship lodged in the rocky face of Canebrake Canyon. The vessel was made of wood, and there was a serpentine figure carved into its prow. There were also impressions on its flanks where shields had been attached—all the hallmarks of a Viking craft. Recounting the episode later, Botts said she and her husband saw the ship but couldn’t reach it, so they vowed to return the following day, better prepared for a rugged hike. That wasn’t to be, because, several hours later, there was a 6.4 magnitude earthquake in the waters off Huntington Beach, in Southern California. Botts claimed it dislodged rocks that buried her Viking ship, which she never saw again.There are reasons to doubt her story, yet it is only one of many about sightings of the desert ship. By the time Myrtle and her husband had set out to explore, amid the blooming poppies and evening primrose, the story of the lost desert ship was already about 60 years old. By the time I heard it, while working on a story about desert conservation, it had been nearly a century and a half since explorer Albert S. Evans had published the first account. Traveling to San Bernardino, Evans came into a valley that was “the grim and silent ghost of a dead sea,” presumably Lake Cahuilla. “The moon threw a track of shimmering light,” he wrote, directly upon “the wreck of a gallant ship, which may have gone down there centuries ago.” The route Evans took came nowhere near Canebrake Canyon, and the ship Evans claimed to see was Spanish, not Norse. Others have also seen this vessel, but much farther south, in Baja California, Mexico. Like all great legends, the desert ship is immune to its contradictions: It is fake news for the romantic soul, offering passage into some ancient American dreamtime when blood and gold were the main currencies of civic life. The legend does seem, prima facie, bonkers: a craft loaded with untold riches, sailed by early-European explorers into a vast lake that once stretched over much of inland Southern California, then run aground, abandoned by its crew and covered over by centuries of sand and rock and creosote bush as that lake dried out…and now it lies a few feet below the surface, in sight of the chicken-wire fence at the back of the Desert Dunes motel, $58 a night and HBO in most rooms. Totally insane, right? Let us slink back to our cubicles and never speak of the desert ship again. Let us only believe that which is shared with us on Facebook. Let us banish forever all traces of wonder from our lives. Yet there are believers who insist that, using recent advances in archaeology, the ship can be found. They point, for example, to a wooden sloop from the 1770s unearthed during excavations at the World Trade Center site in lower Manhattan, or the more than 40 ships, dating back perhaps 800 years, discovered in the Black Sea earlier this year.",
4 | "features": {
5 | "sentiment": {},
6 | "keywords": {},
7 | "categories": {},
8 | "emotion": {},
9 | "entities": {},
10 | "concepts": {},
11 | "semantic_roles": {}
12 | }
13 | },
14 | "results": {
15 | "usage": {
16 | "text_units": 1,
17 | "text_characters": 3972,
18 | "features": 7
19 | },
20 | "sentiment": {
21 | "document": {
22 | "score": -0.544138,
23 | "label": "negative"
24 | }
25 | },
26 | "semantic_roles": [
27 | {
28 | "subject": {
29 | "text": "a treasure ship sailed there hundreds of years ago by either Viking or Spanish explorers"
30 | },
31 | "sentence": "In the rugged Colorado Desert of California, there lies buried a treasure ship sailed there hundreds of years ago by either Viking or Spanish explorers.",
32 | "object": {
33 | "text": "buried"
34 | },
35 | "action": {
36 | "verb": {
37 | "text": "lie",
38 | "tense": "present"
39 | },
40 | "text": "lies",
41 | "normalized": "lie"
42 | }
43 | },
44 | {
45 | "subject": {
46 | "text": "a treasure ship"
47 | },
48 | "sentence": "In the rugged Colorado Desert of California, there lies buried a treasure ship sailed there hundreds of years ago by either Viking or Spanish explorers.",
49 | "action": {
50 | "verb": {
51 | "text": "sail",
52 | "tense": "past"
53 | },
54 | "text": "sailed",
55 | "normalized": "sail"
56 | }
57 | },
58 | {
59 | "subject": {
60 | "text": "Some"
61 | },
62 | "sentence": " Some say this is legend; others insist it is fact.",
63 | "object": {
64 | "text": "this is legend"
65 | },
66 | "action": {
67 | "verb": {
68 | "text": "say",
69 | "tense": "present"
70 | },
71 | "text": "say",
72 | "normalized": "say"
73 | }
74 | },
75 | {
76 | "subject": {
77 | "text": "others"
78 | },
79 | "sentence": " Some say this is legend; others insist it is fact.",
80 | "object": {
81 | "text": "it is fact"
82 | },
83 | "action": {
84 | "verb": {
85 | "text": "insist",
86 | "tense": "present"
87 | },
88 | "text": "insist",
89 | "normalized": "insist"
90 | }
91 | },
92 | {
93 | "subject": {
94 | "text": "A few"
95 | },
96 | "sentence": " A few have even claimed to have seen the ship, its wooden remains poking through the sand like the skeleton of a prehistoric beast.",
97 | "object": {
98 | "text": "to have seen the ship, its wooden remains poking through the sand like the skeleton of a prehistoric beast"
99 | },
100 | "action": {
101 | "verb": {
102 | "text": "claim",
103 | "tense": "past"
104 | },
105 | "text": "claimed",
106 | "normalized": "claim"
107 | }
108 | },
109 | {
110 | "subject": {
111 | "text": "A few"
112 | },
113 | "sentence": " A few have even claimed to have seen the ship, its wooden remains poking through the sand like the skeleton of a prehistoric beast.",
114 | "object": {
115 | "text": "the ship"
116 | },
117 | "action": {
118 | "verb": {
119 | "text": "see",
120 | "tense": "past"
121 | },
122 | "text": "have even claimed to have seen",
123 | "normalized": "have even claim to have see"
124 | }
125 | },
126 | {
127 | "subject": {
128 | "text": "those"
129 | },
130 | "sentence": " Among those who say they’ve come close to the ship is small-town librarian Myrtle Botts.",
131 | "object": {
132 | "text": "they’ve come close to the ship"
133 | },
134 | "action": {
135 | "verb": {
136 | "text": "say",
137 | "tense": "present"
138 | },
139 | "text": "say",
140 | "normalized": "say"
141 | }
142 | },
143 | {
144 | "subject": {
145 | "text": "they’ve come close to the ship"
146 | },
147 | "sentence": " Among those who say they’ve come close to the ship is small-town librarian Myrtle Botts.",
148 | "object": {
149 | "text": "small-town librarian Myrtle Botts"
150 | },
151 | "action": {
152 | "verb": {
153 | "text": "be",
154 | "tense": "present"
155 | },
156 | "text": "is",
157 | "normalized": "be"
158 | }
159 | },
160 | {
161 | "subject": {
162 | "text": "she"
163 | },
164 | "sentence": " In 1933, she was hiking with her husband in the Anza-Borrego Desert, not far from the border with Mexico.",
165 | "object": {
166 | "text": "hiking with her husband in the Anza-Borrego Desert, not far from the border with Mexico"
167 | },
168 | "action": {
169 | "verb": {
170 | "text": "be",
171 | "tense": "past"
172 | },
173 | "text": "was",
174 | "normalized": "be"
175 | }
176 | },
177 | {
178 | "subject": {
179 | "text": "she"
180 | },
181 | "sentence": " In 1933, she was hiking with her husband in the Anza-Borrego Desert, not far from the border with Mexico.",
182 | "action": {
183 | "verb": {
184 | "text": "hike",
185 | "tense": "past"
186 | },
187 | "text": "was hiking",
188 | "normalized": "be hike"
189 | }
190 | },
191 | {
192 | "subject": {
193 | "text": "It"
194 | },
195 | "sentence": " It was early March, so the desert would have been in bloom, its washed-out yellows and grays beaten back by the riotous invasion of wildflowers.",
196 | "action": {
197 | "verb": {
198 | "text": "be",
199 | "tense": "past"
200 | },
201 | "text": "was",
202 | "normalized": "be"
203 | }
204 | },
205 | {
206 | "subject": {
207 | "text": "the desert"
208 | },
209 | "sentence": " It was early March, so the desert would have been in bloom, its washed-out yellows and grays beaten back by the riotous invasion of wildflowers.",
210 | "action": {
211 | "verb": {
212 | "text": "be",
213 | "tense": "future"
214 | },
215 | "text": "would have been",
216 | "normalized": "would have be"
217 | }
218 | },
219 | {
220 | "subject": {
221 | "text": "its washed-out yellows and grays"
222 | },
223 | "sentence": " It was early March, so the desert would have been in bloom, its washed-out yellows and grays beaten back by the riotous invasion of wildflowers.",
224 | "object": {
225 | "text": "by the riotous invasion of wildflowers"
226 | },
227 | "action": {
228 | "verb": {
229 | "text": "beat",
230 | "tense": "past"
231 | },
232 | "text": "beaten",
233 | "normalized": "beat"
234 | }
235 | },
236 | {
237 | "subject": {
238 | "text": "Those wildflowers"
239 | },
240 | "sentence": " Those wildflowers were what brought the Bottses to the desert, and they ended up near a tiny settlement called Agua Caliente.",
241 | "object": {
242 | "text": "the Bottses"
243 | },
244 | "action": {
245 | "verb": {
246 | "text": "bring",
247 | "tense": "past"
248 | },
249 | "text": "brought",
250 | "normalized": "bring"
251 | }
252 | },
253 | {
254 | "subject": {
255 | "text": "they"
256 | },
257 | "sentence": " Those wildflowers were what brought the Bottses to the desert, and they ended up near a tiny settlement called Agua Caliente.",
258 | "action": {
259 | "verb": {
260 | "text": "end",
261 | "tense": "past"
262 | },
263 | "text": "ended",
264 | "normalized": "end"
265 | }
266 | },
267 | {
268 | "subject": {
269 | "text": "a tiny settlement"
270 | },
271 | "sentence": " Those wildflowers were what brought the Bottses to the desert, and they ended up near a tiny settlement called Agua Caliente.",
272 | "object": {
273 | "text": "Agua Caliente"
274 | },
275 | "action": {
276 | "verb": {
277 | "text": "call",
278 | "tense": "past"
279 | },
280 | "text": "called",
281 | "normalized": "call"
282 | }
283 | },
284 | {
285 | "subject": {
286 | "text": "the strangeness and severity of the land: Moonlight Canyon, Hellhole Canyon, Indian Gorge"
287 | },
288 | "sentence": " Surrounding place names reflected the strangeness and severity of the land: Moonlight Canyon, Hellhole Canyon, Indian Gorge.",
289 | "object": {
290 | "text": "Surrounding place names"
291 | },
292 | "action": {
293 | "verb": {
294 | "text": "reflect",
295 | "tense": "past"
296 | },
297 | "text": "reflected",
298 | "normalized": "reflect"
299 | }
300 | },
301 | {
302 | "subject": {
303 | "text": "a prospector"
304 | },
305 | "sentence": " One morning, a prospector appeared in the couple’s camp with news far more astonishing than a new species of desert flora: He’d found a ship lodged in the rocky face of Canebrake Canyon.",
306 | "action": {
307 | "verb": {
308 | "text": "appear",
309 | "tense": "past"
310 | },
311 | "text": "appeared",
312 | "normalized": "appear"
313 | }
314 | },
315 | {
316 | "subject": {
317 | "text": "He"
318 | },
319 | "sentence": " One morning, a prospector appeared in the couple’s camp with news far more astonishing than a new species of desert flora: He’d found a ship lodged in the rocky face of Canebrake Canyon.",
320 | "object": {
321 | "text": "found a ship lodged in the rocky face of Canebrake Canyon"
322 | },
323 | "action": {
324 | "verb": {
325 | "text": "’d",
326 | "tense": "past"
327 | },
328 | "text": "’d",
329 | "normalized": "’d"
330 | }
331 | },
332 | {
333 | "subject": {
334 | "text": "He"
335 | },
336 | "sentence": " One morning, a prospector appeared in the couple’s camp with news far more astonishing than a new species of desert flora: He’d found a ship lodged in the rocky face of Canebrake Canyon.",
337 | "object": {
338 | "text": "a ship lodged in the rocky face of Canebrake Canyon"
339 | },
340 | "action": {
341 | "verb": {
342 | "text": "find",
343 | "tense": "past"
344 | },
345 | "text": "d found",
346 | "normalized": "d find"
347 | }
348 | },
349 | {
350 | "subject": {
351 | "text": "The vessel"
352 | },
353 | "sentence": " The vessel was made of wood, and there was a serpentine figure carved into its prow.",
354 | "object": {
355 | "text": "made of wood"
356 | },
357 | "action": {
358 | "verb": {
359 | "text": "be",
360 | "tense": "past"
361 | },
362 | "text": "was",
363 | "normalized": "be"
364 | }
365 | },
366 | {
367 | "subject": {
368 | "text": "The vessel"
369 | },
370 | "sentence": " The vessel was made of wood, and there was a serpentine figure carved into its prow.",
371 | "object": {
372 | "text": "of wood"
373 | },
374 | "action": {
375 | "verb": {
376 | "text": "make",
377 | "tense": "past"
378 | },
379 | "text": "was made",
380 | "normalized": "be make"
381 | }
382 | },
383 | {
384 | "subject": {
385 | "text": "shields"
386 | },
387 | "sentence": " There were also impressions on its flanks where shields had been attached—all the hallmarks of a Viking craft.",
388 | "object": {
389 | "text": "been attached—all the hallmarks of a Viking craft"
390 | },
391 | "action": {
392 | "verb": {
393 | "text": "have",
394 | "tense": "past"
395 | },
396 | "text": "had",
397 | "normalized": "have"
398 | }
399 | },
400 | {
401 | "subject": {
402 | "text": "shields"
403 | },
404 | "sentence": " There were also impressions on its flanks where shields had been attached—all the hallmarks of a Viking craft.",
405 | "object": {
406 | "text": "attached—all the hallmarks of a Viking craft"
407 | },
408 | "action": {
409 | "verb": {
410 | "text": "be",
411 | "tense": "past"
412 | },
413 | "text": "had been",
414 | "normalized": "have be"
415 | }
416 | },
417 | {
418 | "subject": {
419 | "text": "Botts"
420 | },
421 | "sentence": " Recounting the episode later, Botts said she and her husband saw the ship but couldn’t reach it, so they vowed to return the following day, better prepared for a rugged hike.",
422 | "object": {
423 | "text": "she and her husband saw the ship but couldn’t reach it"
424 | },
425 | "action": {
426 | "verb": {
427 | "text": "say",
428 | "tense": "past"
429 | },
430 | "text": "said",
431 | "normalized": "say"
432 | }
433 | },
434 | {
435 | "subject": {
436 | "text": "they"
437 | },
438 | "sentence": " Recounting the episode later, Botts said she and her husband saw the ship but couldn’t reach it, so they vowed to return the following day, better prepared for a rugged hike.",
439 | "object": {
440 | "text": "to return the following day"
441 | },
442 | "action": {
443 | "verb": {
444 | "text": "vow",
445 | "tense": "past"
446 | },
447 | "text": "vowed",
448 | "normalized": "vow"
449 | }
450 | },
451 | {
452 | "subject": {
453 | "text": "they"
454 | },
455 | "sentence": " Recounting the episode later, Botts said she and her husband saw the ship but couldn’t reach it, so they vowed to return the following day, better prepared for a rugged hike.",
456 | "action": {
457 | "verb": {
458 | "text": "return",
459 | "tense": "future"
460 | },
461 | "text": "vowed to return",
462 | "normalized": "vow to return"
463 | }
464 | },
465 | {
466 | "subject": {
467 | "text": "That"
468 | },
469 | "sentence": " That wasn’t to be, because, several hours later, there was a 6.4 magnitude earthquake in the waters off Huntington Beach, in Southern California.",
470 | "object": {
471 | "text": "n’t"
472 | },
473 | "action": {
474 | "verb": {
475 | "text": "be",
476 | "tense": "past"
477 | },
478 | "text": "was",
479 | "normalized": "be"
480 | }
481 | },
482 | {
483 | "subject": {
484 | "text": "Botts"
485 | },
486 | "sentence": " Botts claimed it dislodged rocks that buried her Viking ship, which she never saw again.There are reasons to doubt her story, yet it is only one of many about sightings of the desert ship.",
487 | "object": {
488 | "text": "it dislodged rocks that buried her Viking ship, which she never saw again.There are reasons to doubt her story, yet it is only one of many about sightings of the desert ship"
489 | },
490 | "action": {
491 | "verb": {
492 | "text": "claim",
493 | "tense": "past"
494 | },
495 | "text": "claimed",
496 | "normalized": "claim"
497 | }
498 | },
499 | {
500 | "subject": {
501 | "text": "rocks"
502 | },
503 | "sentence": " Botts claimed it dislodged rocks that buried her Viking ship, which she never saw again.There are reasons to doubt her story, yet it is only one of many about sightings of the desert ship.",
504 | "object": {
505 | "text": "her Viking ship, which she never saw again.There"
506 | },
507 | "action": {
508 | "verb": {
509 | "text": "bury",
510 | "tense": "past"
511 | },
512 | "text": "buried",
513 | "normalized": "bury"
514 | }
515 | },
516 | {
517 | "subject": {
518 | "text": "she"
519 | },
520 | "sentence": " Botts claimed it dislodged rocks that buried her Viking ship, which she never saw again.There are reasons to doubt her story, yet it is only one of many about sightings of the desert ship.",
521 | "object": {
522 | "text": "again.There are reasons to doubt her story"
523 | },
524 | "action": {
525 | "verb": {
526 | "text": "see",
527 | "tense": "past"
528 | },
529 | "text": "saw",
530 | "normalized": "see"
531 | }
532 | },
533 | {
534 | "subject": {
535 | "text": "Myrtle and her husband"
536 | },
537 | "sentence": " By the time Myrtle and her husband had set out to explore, amid the blooming poppies and evening primrose, the story of the lost desert ship was already about 60 years old.",
538 | "object": {
539 | "text": "set out to explore"
540 | },
541 | "action": {
542 | "verb": {
543 | "text": "have",
544 | "tense": "past"
545 | },
546 | "text": "had",
547 | "normalized": "have"
548 | }
549 | },
550 | {
551 | "subject": {
552 | "text": "the story of the lost desert ship"
553 | },
554 | "sentence": " By the time Myrtle and her husband had set out to explore, amid the blooming poppies and evening primrose, the story of the lost desert ship was already about 60 years old.",
555 | "action": {
556 | "verb": {
557 | "text": "be",
558 | "tense": "past"
559 | },
560 | "text": "was",
561 | "normalized": "be"
562 | }
563 | },
564 | {
565 | "subject": {
566 | "text": "I"
567 | },
568 | "sentence": " By the time I heard it, while working on a story about desert conservation, it had been nearly a century and a half since explorer Albert S. Evans had published the first account.",
569 | "object": {
570 | "text": "it"
571 | },
572 | "action": {
573 | "verb": {
574 | "text": "hear",
575 | "tense": "past"
576 | },
577 | "text": "heard",
578 | "normalized": "hear"
579 | }
580 | },
581 | {
582 | "subject": {
583 | "text": "it"
584 | },
585 | "sentence": " By the time I heard it, while working on a story about desert conservation, it had been nearly a century and a half since explorer Albert S. Evans had published the first account.",
586 | "action": {
587 | "verb": {
588 | "text": "have",
589 | "tense": "past"
590 | },
591 | "text": "had been",
592 | "normalized": "have be"
593 | }
594 | },
595 | {
596 | "subject": {
597 | "text": "it"
598 | },
599 | "sentence": " By the time I heard it, while working on a story about desert conservation, it had been nearly a century and a half since explorer Albert S. Evans had published the first account.",
600 | "object": {
601 | "text": "nearly a century and a half"
602 | },
603 | "action": {
604 | "verb": {
605 | "text": "be",
606 | "tense": "past"
607 | },
608 | "text": "had been",
609 | "normalized": "have be"
610 | }
611 | },
612 | {
613 | "subject": {
614 | "text": "a half since explorer Albert S. Evans"
615 | },
616 | "sentence": " By the time I heard it, while working on a story about desert conservation, it had been nearly a century and a half since explorer Albert S. Evans had published the first account.",
617 | "object": {
618 | "text": "published the first account"
619 | },
620 | "action": {
621 | "verb": {
622 | "text": "have",
623 | "tense": "past"
624 | },
625 | "text": "had",
626 | "normalized": "have"
627 | }
628 | },
629 | {
630 | "subject": {
631 | "text": "a half since explorer Albert S. Evans"
632 | },
633 | "sentence": " By the time I heard it, while working on a story about desert conservation, it had been nearly a century and a half since explorer Albert S. Evans had published the first account.",
634 | "object": {
635 | "text": "the first account"
636 | },
637 | "action": {
638 | "verb": {
639 | "text": "publish",
640 | "tense": "past"
641 | },
642 | "text": "had published",
643 | "normalized": "have publish"
644 | }
645 | },
646 | {
647 | "subject": {
648 | "text": "Evans"
649 | },
650 | "sentence": " Traveling to San Bernardino, Evans came into a valley that was “the grim and silent ghost of a dead sea,” presumably Lake Cahuilla.",
651 | "object": {
652 | "text": "into a valley that was “the grim and silent ghost of a dead sea,” presumably Lake Cahuilla"
653 | },
654 | "action": {
655 | "verb": {
656 | "text": "come",
657 | "tense": "past"
658 | },
659 | "text": "came",
660 | "normalized": "come"
661 | }
662 | },
663 | {
664 | "subject": {
665 | "text": "a valley that"
666 | },
667 | "sentence": " Traveling to San Bernardino, Evans came into a valley that was “the grim and silent ghost of a dead sea,” presumably Lake Cahuilla.",
668 | "object": {
669 | "text": "the grim and silent ghost of a dead sea"
670 | },
671 | "action": {
672 | "verb": {
673 | "text": "be",
674 | "tense": "past"
675 | },
676 | "text": "was",
677 | "normalized": "be"
678 | }
679 | },
680 | {
681 | "subject": {
682 | "text": "The moon"
683 | },
684 | "sentence": " “The moon threw a track of shimmering light,” he wrote, directly upon “the wreck of a gallant ship, which may have gone down there centuries ago.” The route Evans took came nowhere near Canebrake Canyon, and the ship Evans claimed to see was Spanish, not Norse.",
685 | "object": {
686 | "text": "a track"
687 | },
688 | "action": {
689 | "verb": {
690 | "text": "throw",
691 | "tense": "past"
692 | },
693 | "text": "threw",
694 | "normalized": "throw"
695 | }
696 | },
697 | {
698 | "subject": {
699 | "text": "he"
700 | },
701 | "sentence": " “The moon threw a track of shimmering light,” he wrote, directly upon “the wreck of a gallant ship, which may have gone down there centuries ago.” The route Evans took came nowhere near Canebrake Canyon, and the ship Evans claimed to see was Spanish, not Norse.",
702 | "object": {
703 | "text": "The moon threw a track of shimmering light"
704 | },
705 | "action": {
706 | "verb": {
707 | "text": "write",
708 | "tense": "past"
709 | },
710 | "text": "wrote",
711 | "normalized": "write"
712 | }
713 | },
714 | {
715 | "subject": {
716 | "text": "a gallant ship"
717 | },
718 | "sentence": " “The moon threw a track of shimmering light,” he wrote, directly upon “the wreck of a gallant ship, which may have gone down there centuries ago.” The route Evans took came nowhere near Canebrake Canyon, and the ship Evans claimed to see was Spanish, not Norse.",
719 | "object": {
720 | "text": "gone down there centuries"
721 | },
722 | "action": {
723 | "verb": {
724 | "text": "have",
725 | "tense": "future"
726 | },
727 | "text": "have",
728 | "normalized": "have"
729 | }
730 | },
731 | {
732 | "subject": {
733 | "text": "Evans"
734 | },
735 | "sentence": " “The moon threw a track of shimmering light,” he wrote, directly upon “the wreck of a gallant ship, which may have gone down there centuries ago.” The route Evans took came nowhere near Canebrake Canyon, and the ship Evans claimed to see was Spanish, not Norse.",
736 | "object": {
737 | "text": "nowhere"
738 | },
739 | "action": {
740 | "verb": {
741 | "text": "come",
742 | "tense": "past"
743 | },
744 | "text": "came",
745 | "normalized": "come"
746 | }
747 | },
748 | {
749 | "subject": {
750 | "text": "the ship Evans"
751 | },
752 | "sentence": " “The moon threw a track of shimmering light,” he wrote, directly upon “the wreck of a gallant ship, which may have gone down there centuries ago.” The route Evans took came nowhere near Canebrake Canyon, and the ship Evans claimed to see was Spanish, not Norse.",
753 | "object": {
754 | "text": "to see was Spanish, not Norse"
755 | },
756 | "action": {
757 | "verb": {
758 | "text": "claim",
759 | "tense": "past"
760 | },
761 | "text": "claimed",
762 | "normalized": "claim"
763 | }
764 | },
765 | {
766 | "subject": {
767 | "text": "the ship Evans"
768 | },
769 | "sentence": " “The moon threw a track of shimmering light,” he wrote, directly upon “the wreck of a gallant ship, which may have gone down there centuries ago.” The route Evans took came nowhere near Canebrake Canyon, and the ship Evans claimed to see was Spanish, not Norse.",
770 | "object": {
771 | "text": "was Spanish, not Norse"
772 | },
773 | "action": {
774 | "verb": {
775 | "text": "see",
776 | "tense": "future"
777 | },
778 | "text": "claimed to see",
779 | "normalized": "claim to see"
780 | }
781 | },
782 | {
783 | "subject": {
784 | "text": "Others"
785 | },
786 | "sentence": " Others have also seen this vessel, but much farther south, in Baja California, Mexico.",
787 | "object": {
788 | "text": "this vessel"
789 | },
790 | "action": {
791 | "verb": {
792 | "text": "see",
793 | "tense": "past"
794 | },
795 | "text": "have also seen",
796 | "normalized": "have also see"
797 | }
798 | },
799 | {
800 | "subject": {
801 | "text": "the desert ship"
802 | },
803 | "sentence": " Like all great legends, the desert ship is immune to its contradictions: It is fake news for the romantic soul, offering passage into some ancient American dreamtime when blood and gold were the main currencies of civic life.",
804 | "object": {
805 | "text": "immune to its contradictions"
806 | },
807 | "action": {
808 | "verb": {
809 | "text": "be",
810 | "tense": "present"
811 | },
812 | "text": "is",
813 | "normalized": "be"
814 | }
815 | },
816 | {
817 | "subject": {
818 | "text": "blood and gold"
819 | },
820 | "sentence": " Like all great legends, the desert ship is immune to its contradictions: It is fake news for the romantic soul, offering passage into some ancient American dreamtime when blood and gold were the main currencies of civic life.",
821 | "object": {
822 | "text": "the main currencies of civic life"
823 | },
824 | "action": {
825 | "verb": {
826 | "text": "be",
827 | "tense": "past"
828 | },
829 | "text": "were",
830 | "normalized": "be"
831 | }
832 | },
833 | {
834 | "subject": {
835 | "text": "The legend"
836 | },
837 | "sentence": " The legend does seem, prima facie, bonkers: a craft loaded with untold riches, sailed by early-European explorers into a vast lake that once stretched over much of inland Southern California, then run aground, abandoned by its crew and covered over by centuries of sand and rock and creosote bush as that lake dried out…and now it lies a few feet below the surface, in sight of the chicken-wire fence at the back of the Desert Dunes motel, $58 a night and HBO in most rooms.",
838 | "object": {
839 | "text": "once stretched over much of inland Southern California, then run aground, abandoned by its crew and covered over by centuries of sand and rock and creosote bush as that lake dried out…and now it lies a few feet below the surface, in sight of the chicken-wire fence at the back of the Desert Dunes motel, $58 a night and HBO in most rooms"
840 | },
841 | "action": {
842 | "verb": {
843 | "text": "do",
844 | "tense": "present"
845 | },
846 | "text": "does seem",
847 | "normalized": "do seem"
848 | }
849 | }
850 | ],
851 | "language": "en",
852 | "keywords": [
853 | {
854 | "text": "treasure ship",
855 | "relevance": 0.678253,
856 | "count": 1
857 | },
858 | {
859 | "text": "rugged Colorado Desert of California",
860 | "relevance": 0.633605,
861 | "count": 1
862 | },
863 | {
864 | "text": "small-town librarian Myrtle Botts",
865 | "relevance": 0.602635,
866 | "count": 1
867 | },
868 | {
869 | "text": "Anza-Borrego Desert",
870 | "relevance": 0.574586,
871 | "count": 1
872 | },
873 | {
874 | "text": "great legends",
875 | "relevance": 0.563368,
876 | "count": 1
877 | },
878 | {
879 | "text": "explorer Albert S. Evans",
880 | "relevance": 0.559745,
881 | "count": 1
882 | },
883 | {
884 | "text": "time Myrtle",
885 | "relevance": 0.557398,
886 | "count": 1
887 | },
888 | {
889 | "text": "early March",
890 | "relevance": 0.554323,
891 | "count": 1
892 | },
893 | {
894 | "text": "San Bernardino",
895 | "relevance": 0.546636,
896 | "count": 1
897 | },
898 | {
899 | "text": "World Trade Center site",
900 | "relevance": 0.545634,
901 | "count": 1
902 | },
903 | {
904 | "text": "Spanish explorers",
905 | "relevance": 0.539944,
906 | "count": 1
907 | },
908 | {
909 | "text": "Southern California",
910 | "relevance": 0.538122,
911 | "count": 1
912 | },
913 | {
914 | "text": "fake news",
915 | "relevance": 0.535933,
916 | "count": 1
917 | },
918 | {
919 | "text": "Lake Cahuilla",
920 | "relevance": 0.531683,
921 | "count": 1
922 | },
923 | {
924 | "text": "magnitude earthquake",
925 | "relevance": 0.529386,
926 | "count": 1
927 | },
928 | {
929 | "text": "hallmarks of a Viking craft",
930 | "relevance": 0.529378,
931 | "count": 1
932 | },
933 | {
934 | "text": "riotous invasion of wildflowers",
935 | "relevance": 0.526639,
936 | "count": 1
937 | },
938 | {
939 | "text": "European explorers",
940 | "relevance": 0.526194,
941 | "count": 1
942 | },
943 | {
944 | "text": "wooden remains",
945 | "relevance": 0.5261,
946 | "count": 1
947 | },
948 | {
949 | "text": "lower Manhattan",
950 | "relevance": 0.525911,
951 | "count": 1
952 | },
953 | {
954 | "text": "Moonlight Canyon",
955 | "relevance": 0.524771,
956 | "count": 1
957 | },
958 | {
959 | "text": "recent advances",
960 | "relevance": 0.523816,
961 | "count": 1
962 | },
963 | {
964 | "text": "sight of the chicken-wire fence",
965 | "relevance": 0.523522,
966 | "count": 1
967 | },
968 | {
969 | "text": "legend",
970 | "relevance": 0.522402,
971 | "count": 2
972 | },
973 | {
974 | "text": "Huntington Beach",
975 | "relevance": 0.520237,
976 | "count": 1
977 | },
978 | {
979 | "text": "farther south",
980 | "relevance": 0.519995,
981 | "count": 1
982 | },
983 | {
984 | "text": "Baja California",
985 | "relevance": 0.51933,
986 | "count": 1
987 | },
988 | {
989 | "text": "new species of desert flora",
990 | "relevance": 0.518399,
991 | "count": 1
992 | },
993 | {
994 | "text": "route Evans",
995 | "relevance": 0.518141,
996 | "count": 1
997 | },
998 | {
999 | "text": "place names",
1000 | "relevance": 0.517965,
1001 | "count": 1
1002 | },
1003 | {
1004 | "text": "Viking ship",
1005 | "relevance": 0.517589,
1006 | "count": 1
1007 | },
1008 | {
1009 | "text": "vessel",
1010 | "relevance": 0.517503,
1011 | "count": 2
1012 | },
1013 | {
1014 | "text": "episode",
1015 | "relevance": 0.515696,
1016 | "count": 1
1017 | },
1018 | {
1019 | "text": "rocky face of Canebrake Canyon",
1020 | "relevance": 0.515254,
1021 | "count": 1
1022 | },
1023 | {
1024 | "text": "sightings of the desert ship",
1025 | "relevance": 0.514822,
1026 | "count": 1
1027 | },
1028 | {
1029 | "text": "out yellows",
1030 | "relevance": 0.514108,
1031 | "count": 1
1032 | },
1033 | {
1034 | "text": "wooden sloop",
1035 | "relevance": 0.513934,
1036 | "count": 1
1037 | },
1038 | {
1039 | "text": "romantic soul",
1040 | "relevance": 0.513202,
1041 | "count": 1
1042 | },
1043 | {
1044 | "text": "prima facie",
1045 | "relevance": 0.513119,
1046 | "count": 1
1047 | },
1048 | {
1049 | "text": "rugged hike",
1050 | "relevance": 0.513062,
1051 | "count": 1
1052 | },
1053 | {
1054 | "text": "couple’s camp",
1055 | "relevance": 0.512627,
1056 | "count": 1
1057 | },
1058 | {
1059 | "text": "vast lake",
1060 | "relevance": 0.511903,
1061 | "count": 1
1062 | },
1063 | {
1064 | "text": "moon",
1065 | "relevance": 0.511708,
1066 | "count": 1
1067 | },
1068 | {
1069 | "text": "Agua Caliente",
1070 | "relevance": 0.510988,
1071 | "count": 1
1072 | },
1073 | {
1074 | "text": "rocks",
1075 | "relevance": 0.510365,
1076 | "count": 1
1077 | },
1078 | {
1079 | "text": "back of the Desert Dunes motel",
1080 | "relevance": 0.510266,
1081 | "count": 1
1082 | },
1083 | {
1084 | "text": "wreck of a gallant ship",
1085 | "relevance": 0.510187,
1086 | "count": 1
1087 | },
1088 | {
1089 | "text": "Botts",
1090 | "relevance": 0.50997,
1091 | "count": 2
1092 | },
1093 | {
1094 | "text": "ancient American dreamtime",
1095 | "relevance": 0.509831,
1096 | "count": 1
1097 | },
1098 | {
1099 | "text": "bloom",
1100 | "relevance": 0.50971,
1101 | "count": 1
1102 | }
1103 | ],
1104 | "entities": [
1105 | {
1106 | "type": "GeographicFeature",
1107 | "text": "Anza-Borrego Desert",
1108 | "relevance": 0.854741,
1109 | "count": 4
1110 | },
1111 | {
1112 | "type": "Person",
1113 | "text": "Myrtle Botts",
1114 | "relevance": 0.830275,
1115 | "count": 7
1116 | },
1117 | {
1118 | "type": "GeographicFeature",
1119 | "text": "Colorado Desert",
1120 | "relevance": 0.576799,
1121 | "count": 1
1122 | },
1123 | {
1124 | "type": "Person",
1125 | "text": "Albert S. Evans",
1126 | "relevance": 0.510277,
1127 | "count": 4
1128 | },
1129 | {
1130 | "type": "GeographicFeature",
1131 | "text": "Canebrake Canyon",
1132 | "relevance": 0.464834,
1133 | "count": 2
1134 | },
1135 | {
1136 | "type": "GeographicFeature",
1137 | "text": "Desert Dunes",
1138 | "relevance": 0.442795,
1139 | "count": 1
1140 | },
1141 | {
1142 | "type": "Location",
1143 | "text": "Southern California",
1144 | "relevance": 0.40807,
1145 | "disambiguation": {
1146 | "subtype": [
1147 | "Region"
1148 | ]
1149 | },
1150 | "count": 2
1151 | },
1152 | {
1153 | "type": "Location",
1154 | "text": "Mexico",
1155 | "relevance": 0.398995,
1156 | "disambiguation": {
1157 | "subtype": [
1158 | "Country"
1159 | ]
1160 | },
1161 | "count": 2
1162 | },
1163 | {
1164 | "type": "GeographicFeature",
1165 | "text": "Moonlight Canyon",
1166 | "relevance": 0.379281,
1167 | "count": 1
1168 | },
1169 | {
1170 | "type": "Location",
1171 | "text": "California",
1172 | "relevance": 0.363336,
1173 | "disambiguation": {
1174 | "subtype": [
1175 | "StateOrCounty"
1176 | ]
1177 | },
1178 | "count": 1
1179 | },
1180 | {
1181 | "type": "Company",
1182 | "text": "Facebook",
1183 | "relevance": 0.353992,
1184 | "disambiguation": {
1185 | "subtype": [
1186 | "Website",
1187 | "VentureFundedCompany"
1188 | ],
1189 | "name": "Facebook",
1190 | "dbpedia_resource": "http://dbpedia.org/resource/Facebook"
1191 | },
1192 | "count": 1
1193 | },
1194 | {
1195 | "type": "GeographicFeature",
1196 | "text": "Agua Caliente",
1197 | "relevance": 0.328523,
1198 | "count": 1
1199 | },
1200 | {
1201 | "type": "Facility",
1202 | "text": "World Trade Center",
1203 | "relevance": 0.327814,
1204 | "disambiguation": {
1205 | "subtype": [
1206 | "Location",
1207 | "BuildingComplex",
1208 | "Skyscraper"
1209 | ],
1210 | "name": "World Trade Center",
1211 | "dbpedia_resource": "http://dbpedia.org/resource/World_Trade_Center"
1212 | },
1213 | "count": 1
1214 | },
1215 | {
1216 | "type": "Location",
1217 | "text": "San Bernardino",
1218 | "relevance": 0.319157,
1219 | "disambiguation": {
1220 | "subtype": [
1221 | "PlaceWithNeighborhoods",
1222 | "City"
1223 | ],
1224 | "name": "San Bernardino, California",
1225 | "dbpedia_resource": "http://dbpedia.org/resource/San_Bernardino,_California"
1226 | },
1227 | "count": 1
1228 | },
1229 | {
1230 | "type": "GeographicFeature",
1231 | "text": "Black Sea",
1232 | "relevance": 0.316259,
1233 | "disambiguation": {
1234 | "subtype": [
1235 | "Location",
1236 | "BodyOfWater",
1237 | "Lake"
1238 | ],
1239 | "name": "Black Sea",
1240 | "dbpedia_resource": "http://dbpedia.org/resource/Black_Sea"
1241 | },
1242 | "count": 1
1243 | },
1244 | {
1245 | "type": "Location",
1246 | "text": "Baja California",
1247 | "relevance": 0.313614,
1248 | "disambiguation": {
1249 | "subtype": [
1250 | "City"
1251 | ]
1252 | },
1253 | "count": 1
1254 | },
1255 | {
1256 | "type": "GeographicFeature",
1257 | "text": "Indian Gorge",
1258 | "relevance": 0.307322,
1259 | "count": 1
1260 | },
1261 | {
1262 | "type": "GeographicFeature",
1263 | "text": "Lake Cahuilla",
1264 | "relevance": 0.306655,
1265 | "count": 1
1266 | },
1267 | {
1268 | "type": "GeographicFeature",
1269 | "text": "Huntington Beach",
1270 | "relevance": 0.30613,
1271 | "count": 1
1272 | },
1273 | {
1274 | "type": "Location",
1275 | "text": "Manhattan",
1276 | "relevance": 0.304195,
1277 | "disambiguation": {
1278 | "subtype": [
1279 | "GeographicFeature",
1280 | "AdministrativeDivision",
1281 | "GovernmentalJurisdiction",
1282 | "Island",
1283 | "PlaceWithNeighborhoods",
1284 | "USCounty",
1285 | "City"
1286 | ],
1287 | "name": "Manhattan",
1288 | "dbpedia_resource": "http://dbpedia.org/resource/Manhattan"
1289 | },
1290 | "count": 1
1291 | },
1292 | {
1293 | "type": "Broadcaster",
1294 | "text": "HBO",
1295 | "relevance": 0.280288,
1296 | "disambiguation": {
1297 | "subtype": [
1298 | "TelevisionStation"
1299 | ]
1300 | },
1301 | "count": 1
1302 | },
1303 | {
1304 | "type": "Quantity",
1305 | "text": "800 years",
1306 | "relevance": 0.280288,
1307 | "count": 1
1308 | },
1309 | {
1310 | "type": "Quantity",
1311 | "text": "60 years",
1312 | "relevance": 0.280288,
1313 | "count": 1
1314 | },
1315 | {
1316 | "type": "Quantity",
1317 | "text": "$58",
1318 | "relevance": 0.280288,
1319 | "count": 1
1320 | }
1321 | ],
1322 | "emotion": {
1323 | "document": {
1324 | "emotion": {
1325 | "sadness": 0.510395,
1326 | "joy": 0.465514,
1327 | "fear": 0.087964,
1328 | "disgust": 0.129827,
1329 | "anger": 0.15183
1330 | }
1331 | }
1332 | },
1333 | "concepts": [
1334 | {
1335 | "text": "Colorado Desert",
1336 | "relevance": 0.949924,
1337 | "dbpedia_resource": "http://dbpedia.org/resource/Colorado_Desert"
1338 | },
1339 | {
1340 | "text": "Sonoran Desert",
1341 | "relevance": 0.841144,
1342 | "dbpedia_resource": "http://dbpedia.org/resource/Sonoran_Desert"
1343 | },
1344 | {
1345 | "text": "Desert",
1346 | "relevance": 0.7866,
1347 | "dbpedia_resource": "http://dbpedia.org/resource/Desert"
1348 | },
1349 | {
1350 | "text": "Mojave Desert",
1351 | "relevance": 0.69398,
1352 | "dbpedia_resource": "http://dbpedia.org/resource/Mojave_Desert"
1353 | },
1354 | {
1355 | "text": "Anza-Borrego Desert State Park",
1356 | "relevance": 0.671039,
1357 | "dbpedia_resource": "http://dbpedia.org/resource/Anza-Borrego_Desert_State_Park"
1358 | },
1359 | {
1360 | "text": "Imperial County, California",
1361 | "relevance": 0.652692,
1362 | "dbpedia_resource": "http://dbpedia.org/resource/Imperial_County,_California"
1363 | },
1364 | {
1365 | "text": "Salton Sea",
1366 | "relevance": 0.594352,
1367 | "dbpedia_resource": "http://dbpedia.org/resource/Salton_Sea"
1368 | },
1369 | {
1370 | "text": "Prima facie",
1371 | "relevance": 0.542887,
1372 | "dbpedia_resource": "http://dbpedia.org/resource/Prima_facie"
1373 | }
1374 | ],
1375 | "categories": [
1376 | {
1377 | "score": 0.965124,
1378 | "label": "/travel/transports/sea travel"
1379 | },
1380 | {
1381 | "score": 0.663114,
1382 | "label": "/society/unrest and war"
1383 | }
1384 | ]
1385 | }
1386 |
1387 | }
1388 |
--------------------------------------------------------------------------------
/public/css/style.css:
--------------------------------------------------------------------------------
1 | .base--p_small {
2 | font-size: 0.8rem;
3 | }
4 |
5 | h4 {
6 | font-weight: 400;
7 | color: #5b5b5b;
8 | }
9 |
10 | .base--color-input, .base--date-input, .base--datetime-local-input, .base--email-input, .base--file-input, .base--hidden-input, .base--input, .base--month-input, .base--number-input, .base--password-input, .base--range-input, .base--search-input, .base--select, .base--tel-input, .base--text-input, .base--time-input, .base--url-input, .base--week-input,
11 | input, input[type=range], input[type=search], input[type=tel], input[type=text], input[type=time], input[type=url], input[type=week], input[type=color], input[type=date], input[type=datetime-local], input[type=email], input[type=file], input[type=hidden], input[type=month],
12 | input[type=number], input[type=password], select {
13 | border-width: 1px;
14 | }
15 |
16 | ::-webkit-input-placeholder { /* Chrome/Opera/Safari */
17 | font-style: italic;
18 | }
19 | ::-moz-placeholder { /* Firefox 19+ */
20 | font-style: italic;
21 | }
22 | :-ms-input-placeholder { /* IE 10+ */
23 | font-style: italic;
24 | }
25 | :-moz-placeholder { /* Firefox 18- */
26 | font-style: italic;
27 | }
28 |
29 | .output-section .tab-panels {
30 | background-color: transparent;
31 | border: none;
32 | }
33 |
34 | .output-section .tab-panels--tab-content {
35 | padding-left: 0rem;
36 | padding-right: 0rem;
37 | }
38 |
39 | .output-section .tab-panels--tab.base--a {
40 | background-color: transparent;
41 | border-radius: 5px;
42 | border: 1px solid #969696;
43 | color: #5c5b5c;
44 | padding: 0.2rem 1rem;
45 | margin-right: 0.5rem;
46 | margin-bottom: 0.5rem;
47 | font-weight: 300;
48 | }
49 |
50 | .output-section .tab-panels--tab {
51 | border-bottom: none;
52 | }
53 |
54 | .output-section .tab-panels--tab.active,
55 | .output-section .tab-panels--tab:focus,
56 | .output-section .tab-panels--tab:hover {
57 | color: #fff;
58 | background-color: #9855d4;
59 | border-color: #9855d4;
60 | }
61 |
62 | .output-section .tab-panels--tab-list {
63 | border-bottom: none;
64 | }
65 |
66 | /*pre[class*="language"] {
67 | background-color: transparent;
68 | color: #f8fbfc;
69 | width: 100%;
70 | height: 100%;
71 | margin: 0rem;
72 | overflow: visible;
73 | }
74 | pre[class*="language"] code {
75 | overflow: visible;
76 | }
77 |
78 | .token.punctuation {
79 | color: #f8fbfc;
80 | }
81 | .token.operator {
82 | background: transparent;
83 | color: #f8fbfc;
84 | }
85 | .token.property {
86 | color: #70addc;
87 | }
88 | .token.string {
89 | color: #74c8bc;
90 | }*/
91 |
92 | .code-block--code {
93 | height: 100%;
94 | }
95 |
96 | .base--pre {
97 | height: 100%;
98 | overflow: initial;
99 | }
100 |
101 | .base--pre .prism {
102 | overflow: initial;
103 | }
104 |
105 | pre[class*="language"] {
106 | margin: 0rem;
107 | }
108 | .token.operator {
109 | background: transparent;
110 | }
111 |
112 | .error {
113 | padding: 0rem;
114 | margin-top: 0rem;
115 | }
116 | .error .alert {
117 | background-color: transparent !important;
118 | padding: 0rem;
119 | margin: 0rem;
120 | }
121 | .error .alert--content-container p {
122 | color: #e71d32;
123 | font-size: 0.9rem;
124 | }
125 |
126 | .sentence {
127 | font-size: x-large;
128 | line-height: 200%;
129 | padding-bottom: 1rem;
130 | border-bottom: 1px solid black;
131 | }
132 |
133 | .action {
134 | line-height: 100%;
135 | display: inline-block;
136 | position: relative;
137 | margin-top: 2rem;
138 | border-bottom: 1px solid #bd8bea;
139 | }
140 | .subject {
141 | line-height: 100%;
142 | display: inline-block;
143 | position: relative;
144 | margin-top: 2rem;
145 | border-bottom: 1px solid #bd8bea;
146 | }
147 | .object {
148 | line-height: 100%;
149 | display: inline-block;
150 | position: relative;
151 | margin-top: 2rem;
152 | border-bottom: 1px solid #bd8bea;
153 | }
154 |
155 | .label {
156 | font-size: 0.5rem;
157 | position: absolute;
158 | left: 0rem;
159 | width: 100%;
160 | text-align: center;
161 | color: #bd8bea;
162 | top: 100%;
163 | font-style: italic;
164 | font-weight: 500;
165 | text-transform: capitalize;
166 | margin-bottom: 2rem;
167 | margin-top: 0rem;
168 | }
169 |
170 | .base--button_bar .error {
171 | margin-top: 2rem;
172 | margin-bottom: 3rem;
173 | padding: 0px;
174 | }
175 |
176 | .footer-container--div {
177 | margin-top: 0;
178 | }
179 |
180 | .footer-container--div div {
181 | margin-top: 0;
182 | }
183 |
184 | .footer-gdpr--section {
185 | text-align: center;
186 | padding: 1rem 0 0 0;
187 | background-color: #323232;
188 | color: #aeaeae;
189 | font-size: 0.7rem;
190 | }
191 |
192 | .new_demo_notification {
193 | max-width: 48rem;
194 | }
--------------------------------------------------------------------------------
/public/images/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/watson-developer-cloud/natural-language-understanding-nodejs/b63b0e8eba99fb116a630fa1c6e0fbd32a6d6bd3/public/images/favicon.ico
--------------------------------------------------------------------------------
/public/scripts/analytics.js:
--------------------------------------------------------------------------------
1 | /* eslint no-underscore-dangle: off, no-var: off, vars-on-top: off */
2 |
3 | function loadAnalytics() {
4 | var idaScript = document.createElement('script');
5 | idaScript.src = '//www.ibm.com/common/stats/ida_stats.js';
6 | document.head.appendChild(idaScript);
7 | }
8 |
9 |
10 | window.addEventListener('load', loadAnalytics);
11 |
12 |
--------------------------------------------------------------------------------
/public/scripts/bundle.jsx:
--------------------------------------------------------------------------------
1 | import './polyfills';
2 | import React from 'react';
3 | import ReactDOM from 'react-dom';
4 | import { StyleSheet } from 'aphrodite';
5 | import Demo from '../../views/Demo.jsx';
6 | import { css } from '../../views/index.jsx';
7 |
8 |
9 | StyleSheet.rehydrate(css.renderedClassNames);
10 | ReactDOM.render(, document.getElementById('root'));
11 |
--------------------------------------------------------------------------------
/public/scripts/polyfills.js:
--------------------------------------------------------------------------------
1 | // todo: serve this file seperately and only load when needed...
2 |
3 | // fetch polyfill for Safari / IE
4 | // automatically sets global
5 | import 'whatwg-fetch';
6 |
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | // load environment properties from a .env file for local development
2 | require('dotenv').config();
3 | const app = require('./app.js');
4 |
5 | const port = process.env.PORT || 3000;
6 |
7 | app.listen(port);
8 | console.log('listening at:', port); // eslint-disable-line
9 |
--------------------------------------------------------------------------------
/test/integration/test.mainpage.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable prefer-arrow-callback */
2 | /* eslint-disable no-undef */
3 |
4 | casper.test.begin('Natural Language Understanding', 2, function suite(test) {
5 | const baseHost = 'http://localhost:3000';
6 |
7 | casper.start(baseHost, function start(result) {
8 | casper.test.comment('Starting Testing');
9 |
10 | test.assert(result.status === 200, 'Front page opens');
11 | test.assertEquals(this.getTitle(), 'Natural Language Understanding Demo', 'Title is found');
12 | });
13 |
14 | casper.run(function run() {
15 | test.done();
16 | });
17 | });
18 |
--------------------------------------------------------------------------------
/test/unit/test.express.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 IBM Corp. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | const path = require('path');
18 | // load default variables for testing
19 | require('dotenv').config({ path: path.join(__dirname, '../../.env.example') });
20 |
21 | const request = require('supertest');
22 | const app = require('../../app');
23 | const handleError = require('../utils/handleError');
24 |
25 | describe('express', () => {
26 | it('load home page when GET /', (done) => {
27 | handleError(done, () => {
28 | request(app).get('/').expect(200);
29 | });
30 | });
31 |
32 | it('404 when page not found', () => request(app).get('/foo/bar').expect(404));
33 | });
34 |
--------------------------------------------------------------------------------
/test/utils/handleError.js:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a try-catch wrapper to ensure that asyncronous tests resolves
3 | */
4 | function handleError(done, fn) {
5 | try { // boilerplate to be able to get the assert failures
6 | fn();
7 | done();
8 | } catch (error) {
9 | done(error);
10 | }
11 | }
12 |
13 | module.exports = handleError;
14 |
--------------------------------------------------------------------------------
/views/Bar.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import numeral from 'numeral';
4 | import map from 'map-range';
5 | import { parser } from 'css-math';
6 | import { StyleSheet, css } from 'aphrodite/no-important';
7 | import { colors } from './utils/colors';
8 |
9 | const barColor = colors.GRAY;
10 | const scoreLabelWidth = '1.5rem';
11 | const scorePadding = '0.5rem';
12 |
13 | const styles = StyleSheet.create({
14 | container: {
15 | display: 'flex',
16 | alignItems: 'center',
17 | width: '100%',
18 | maxWidth: '6rem',
19 | },
20 | fullBar: {
21 | height: '0.5rem',
22 | border: `1px solid ${barColor}`,
23 | position: 'relative',
24 | width: `calc(100% - ${parser(`${scoreLabelWidth} + ${scorePadding}`)})`,
25 | marginRight: scorePadding,
26 | },
27 | fullBar_barOnly: {
28 | width: '100%',
29 | },
30 | bar: {
31 | backgroundColor: barColor,
32 | height: '100%',
33 | position: 'absolute',
34 | top: '0rem',
35 | left: '0rem',
36 | },
37 | score: {
38 | width: scoreLabelWidth,
39 | textAlign: 'right',
40 | marginTop: '0rem',
41 | verticalAlign: 'right',
42 | fontSize: '0.8rem',
43 | },
44 | });
45 |
46 | function Bar(props) {
47 | const {
48 | rangeEnd, rangeStart, score, withScore,
49 | } = props;
50 | const mapped = map(x => x, rangeStart, rangeEnd, 0, 1);
51 | return (withScore
52 | ? (
53 |
54 |
55 |
56 |
57 |
58 | {numeral(score).format('0.00')}
59 |
60 |
61 | )
62 | : (
63 |
64 |
65 |
66 | )
67 | );
68 | }
69 |
70 | Bar.propTypes = {
71 | score: PropTypes.number, // percentage number from 0 - 100
72 | withScore: PropTypes.bool, // show score or not
73 | rangeStart: PropTypes.number,
74 | rangeEnd: PropTypes.number,
75 | };
76 |
77 | Bar.defaultProps = {
78 | score: 0,
79 | withScore: true,
80 | rangeStart: 0,
81 | rangeEnd: 1,
82 | };
83 |
84 | export default Bar;
85 |
--------------------------------------------------------------------------------
/views/Demo.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Alert } from 'watson-react-components';
3 | import scrollToElement from 'scroll-to-element';
4 | import Input from './Input.jsx';
5 | import Output from './Output/Output.jsx';
6 | import FloatingCta from './FloatingCta.jsx';
7 | import { analyzeWithAllFeatures } from './utils/request';
8 |
9 | // eslint-disable-next-line
10 | const DEFAULT_TEXT = 'In the rugged Colorado Desert of California, there lies buried a treasure ship sailed there hundreds of years ago by either Viking or Spanish explorers. Some say this is legend; others insist it is fact. A few have even claimed to have seen the ship, its wooden remains poking through the sand like the skeleton of a prehistoric beast. Among those who say they’ve come close to the ship is small-town librarian Myrtle Botts. In 1933, she was hiking with her husband in the Anza-Borrego Desert, not far from the border with Mexico. It was early March, so the desert would have been in bloom, its washed-out yellows and grays beaten back by the riotous invasion of wildflowers. Those wildflowers were what brought the Bottses to the desert, and they ended up near a tiny settlement called Agua Caliente. Surrounding place names reflected the strangeness and severity of the land: Moonlight Canyon, Hellhole Canyon, Indian Gorge. To enter the desert is to succumb to the unknowable. One morning, a prospector appeared in the couple’s camp with news far more astonishing than a new species of desert flora: He’d found a ship lodged in the rocky face of Canebrake Canyon. The vessel was made of wood, and there was a serpentine figure carved into its prow. There were also impressions on its flanks where shields had been attached—all the hallmarks of a Viking craft. Recounting the episode later, Botts said she and her husband saw the ship but couldn’t reach it, so they vowed to return the following day, better prepared for a rugged hike. That wasn’t to be, because, several hours later, there was a 6.4 magnitude earthquake in the waters off Huntington Beach, in Southern California. Botts claimed it dislodged rocks that buried her Viking ship, which she never saw again.There are reasons to doubt her story, yet it is only one of many about sightings of the desert ship. By the time Myrtle and her husband had set out to explore, amid the blooming poppies and evening primrose, the story of the lost desert ship was already about 60 years old. By the time I heard it, while working on a story about desert conservation, it had been nearly a century and a half since explorer Albert S. Evans had published the first account. Traveling to San Bernardino, Evans came into a valley that was “the grim and silent ghost of a dead sea,” presumably Lake Cahuilla. “The moon threw a track of shimmering light,” he wrote, directly upon “the wreck of a gallant ship, which may have gone down there centuries ago.” The route Evans took came nowhere near Canebrake Canyon, and the ship Evans claimed to see was Spanish, not Norse. Others have also seen this vessel, but much farther south, in Baja California, Mexico. Like all great legends, the desert ship is immune to its contradictions: It is fake news for the romantic soul, offering passage into some ancient American dreamtime when blood and gold were the main currencies of civic life. The legend does seem, prima facie, bonkers: a craft loaded with untold riches, sailed by early-European explorers into a vast lake that once stretched over much of inland Southern California, then run aground, abandoned by its crew and covered over by centuries of sand and rock and creosote bush as that lake dried out…and now it lies a few feet below the surface, in sight of the chicken-wire fence at the back of the Desert Dunes motel, $58 a night and HBO in most rooms. Totally insane, right? Let us slink back to our cubicles and never speak of the desert ship again. Let us only believe that which is shared with us on Facebook. Let us banish forever all traces of wonder from our lives. Yet there are believers who insist that, using recent advances in archaeology, the ship can be found. They point, for example, to a wooden sloop from the 1770s unearthed during excavations at the World Trade Center site in lower Manhattan, or the more than 40 ships, dating back perhaps 800 years, discovered in the Black Sea earlier this year.';
11 | const DEFAULT_URL = 'https://newsroom.ibm.com/think-spotlight?item=30994';
12 | const NEW_DEMO_NOTIFICATION = 'A new Natural Language Understanding demo is available, check it out ';
13 |
14 | export default React.createClass({
15 | displayName: 'Demo',
16 |
17 | getInitialState() {
18 | return {
19 | requestType: 'text',
20 | loading: false,
21 | error: null,
22 | data: null,
23 | disableButton: false,
24 | query: {},
25 | };
26 | },
27 |
28 | enableButton(event) {
29 | const disabled = event ? event.target.value.length < 1 : false;
30 | this.setState({ disableButton: disabled });
31 | },
32 |
33 | onSubmitClick(value) {
34 | const query = this.state.requestType === 'url' ? { url: value } : { text: value };
35 | this.setState({
36 | query,
37 | disableButton: true,
38 | loading: true,
39 | });
40 | setTimeout(() => { scrollToElement('#anchor', { duration: 300 }, 100); }, 0);
41 |
42 | // Send the request to NLU
43 | analyzeWithAllFeatures(query)
44 | .then(data => this.setState({ data, loading: false, error: null }))
45 | .catch(error => this.setState({ error, loading: false }))
46 | .then(() => setTimeout(() => { scrollToElement('#anchor', { duration: 300 }, 100); }, 0));
47 | },
48 |
49 | changeRequestType(index) {
50 | const requestType = index === 0 ? 'text' : 'url';
51 | this.setState({
52 | requestType,
53 | });
54 | },
55 |
56 | render() {
57 | const {
58 | data, error, disableButton, loading, query,
59 | } = this.state;
60 |
61 | return (
62 |
For results unique to your business needs consider building a custom model.
166 |
167 | * This system is for demonstration purposes only and is not intended to
168 | process Personal Data. No Personal Data is to be entered into this system as it may not have the
169 | necessary controls in place to meet the requirements of the General Data Protection Regulation (EU)
170 | 2016/679.
171 |
142 | );
143 | }
144 |
145 | JsonLink.propTypes = {
146 | json: PropTypes.oneOfType([
147 | PropTypes.string,
148 | PropTypes.object,
149 | ]).isRequired,
150 | children: PropTypes.oneOfType([
151 | PropTypes.element,
152 | PropTypes.arrayOf(PropTypes.element),
153 | ]),
154 | showJson: PropTypes.bool,
155 | onExit: PropTypes.func,
156 | onShow: PropTypes.func,
157 | description: PropTypes.element,
158 | };
159 |
160 | JsonLink.defaultProps = {
161 | showJson: false,
162 | onExit: () => {},
163 | onShow: () => {},
164 | children: null,
165 | description: null,
166 | };
167 |
--------------------------------------------------------------------------------
/views/Layout.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import { Header, Jumbotron } from 'watson-react-components';
4 |
5 | const demoName = 'Natural Language Understanding';
6 | const DESCRIPTION = 'Natural 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. This system is for demonstration purposes only and is not intended to process Personal Data. No Personal Data is to be entered into this system as it may not have the necessary controls in place to meet the requirements of the General Data Protection Regulation (EU) 2016/679.';
7 |
8 | export default function Layout(props) {
9 | const { css, children } = props;
10 | return (
11 |
12 |
13 |
14 | {`${demoName} Demo`}
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
27 |
28 |
29 |
30 |
36 |
45 |