Skip to content

Commit

Permalink
Merge pull request #453 from chughts/syntax
Browse files Browse the repository at this point in the history
NLU Syntax
  • Loading branch information
chughts committed Mar 25, 2019
2 parents 2eab7e0 + f794455 commit 2869917
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ Node-RED Watson Nodes for IBM Cloud

<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>

### New in version 0.7.8
- NLU Node - Add Syntax to list of selectable features

### New in version 0.7.7
- STT Node - Set correct content-type when File-Type reports a mime type of audio/opus for ogg;codec=opus files.
- STT Node - Set correct content-type when File-Type reports a mime type of audio/opus for ogg;codec=opus files.

### New in version 0.7.6
- Bump SDK Dependency to 3.18.2
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-node-watson",
"version": "0.7.7",
"version": "0.7.8",
"description": "A collection of Node-RED nodes for IBM Watson services",
"dependencies": {
"async": "^1.5.2",
Expand All @@ -10,7 +10,7 @@
"temp": "^0.9.0",
"qs": "6.x",
"image-type": "^2.0.2",
"watson-developer-cloud": "^3.18.2",
"watson-developer-cloud": "^3.18.3",
"ibm-cloud-sdk-core": "^0.0.1",
"word-count": "^0.2.2",
"is-docx": "^0.0.3",
Expand Down
38 changes: 37 additions & 1 deletion services/natural_language_understanding/v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,27 @@
id="node-input-maxsemantics" />
</div>

<div>
<input style="width: 30px; margin-left: 20px; margin-top: 0;"
type="checkbox" id="node-input-syntax" />
<label style="width: auto;" for="node-input-syntax">Syntax</label>
</div>
<div>
<input style="width: 30px; margin-left: 20px; margin-top: 0;"
type="checkbox" id="node-input-syntax-sentences" />
<label style="width: auto;" for="node-input-syntax-sentences">Syntax Sentences</label>
</div>
<div>
<input style="width: 30px; margin-left: 20px; margin-top: 0;"
type="checkbox" id="node-input-syntax-tokens-lemma" />
<label style="width: auto;" for="node-input-syntax-tokens-lemma">Lemma Tokens</label>
</div>
<div>
<input style="width: 30px; margin-left: 20px; margin-top: 0;"
type="checkbox" id="node-input-syntax-tokens-pos" />
<label style="width: auto;" for="node-input-syntax-tokens-pos">Part of Speech</label>
</div>

</div>
</div>

Expand Down Expand Up @@ -215,11 +236,13 @@
<li><b>Relations</b>, identify Subject-Action-Object relations.</li>
<li><b>Semantic Roles</b>, parse out sentences into subject,
action, and object form.</li>
<li><b>Syntax</b>, Returns information about the tokens and sentences in
the input text. </li>
</ul>
<p>
You can limit the text analyzed by setting limit text characters. A value
of 0 applies no limit.
of 0 applies no limit.
</p>
<p>For full details on the feature details,
please see the
Expand Down Expand Up @@ -265,6 +288,9 @@
$('#node-input-semantic-entities').parent().hide();
$('#node-input-semantic-keywords').parent().hide();
$('#node-input-maxsemantics').parent().hide();
$('#node-input-syntax-sentences').parent().hide();
$('#node-input-syntax-tokens-lemma').parent().hide();
$('#node-input-syntax-tokens-pos').parent().hide();
};

nluV1.setVisibility = function(field, visible) {
Expand Down Expand Up @@ -318,6 +344,12 @@
nluV1.CreateIListener($('#node-input-default-endpoint'),
$('#node-input-service-endpoint'), true);

nluV1.CreateIListener($('#node-input-syntax'),
$('#node-input-syntax-sentences'
+ ', #node-input-syntax-tokens-lemma'
+ ', #node-input-syntax-tokens-pos'));


}

nluV1.checkForPrepare = function () {
Expand Down Expand Up @@ -368,6 +400,10 @@
'semantic-keywords': {value: false},
'maxsemantics' :{value: '50'},
'limittextcharacters': {value: '0'},
'syntax': {value: false},
'syntax-sentences': {value: false},
'syntax-tokens-lemma': {value: false},
'syntax-tokens-pos': {value: false},
'default-endpoint' :{value: true},
'service-endpoint' :{value: 'https://gateway.watsonplatform.net/natural-language-understanding/api'}
},
Expand Down
18 changes: 17 additions & 1 deletion services/natural_language_understanding/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports = function (RED) {
'keyword': 'keywords',
'metadata': 'metadata',
'relation': 'relations',
'semantic': 'semantic_roles'
'semantic': 'semantic_roles',
'syntax': 'syntax'
};

var pkg = require('../../package.json'),
Expand Down Expand Up @@ -153,6 +154,20 @@ module.exports = function (RED) {
}
}

function processSyntaxOptions(msg, config, features) {
if (features.syntax) {
features.syntax.sentences =
config['syntax-sentences'] ? config['syntax-sentences'] : false;
if (config['syntax-tokens-lemma'] || config['syntax-tokens-pos']) {
features.syntax.tokens = {};
features.syntax.tokens.lemma =
config['syntax-tokens-lemma'] ? config['syntax-tokens-lemma'] : false;
features.syntax.tokens.part_of_speech =
config['syntax-tokens-pos'] ? config['syntax-tokens-pos'] : false;
}
}
}

function processRelationsOptions(msg, config, features) {
if (features.relations) {
if (msg.nlu_options && msg.nlu_options.relations_model) {
Expand Down Expand Up @@ -195,6 +210,7 @@ module.exports = function (RED) {
processRelationsOptions(msg,config, options.features);
processKeywordsOptions(config, options.features);
processSemanticRolesOptions(config, options.features);
processSyntaxOptions(msg,config, options.features);
}
return Promise.resolve();
}
Expand Down

0 comments on commit 2869917

Please sign in to comment.