Skip to content

Commit 7867638

Browse files
sawyerhstephenplusplus
authored andcommitted
language: remove sentiment and salience range conversions (#1834) (#1836)
1 parent 5cddac3 commit 7867638

2 files changed

Lines changed: 17 additions & 27 deletions

File tree

packages/google-cloud-language/src/document.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Document.PART_OF_SPEECH = {
252252
* @param {string} callback.annotation.language - The language detected from the
253253
* text.
254254
* @param {number} callback.annotation.sentiment - A value in the range of
255-
* `-100` to `100`. Large numbers represent more positive sentiments.
255+
* `-1` (negative) to `1` (positive).
256256
* @param {object} callback.annotation.entities - The recognized entities from
257257
* the text, grouped by the type of entity.
258258
* @param {string[]} callback.annotation.entities.art - Art entities detected
@@ -321,7 +321,7 @@ Document.PART_OF_SPEECH = {
321321
*
322322
* // annotation = {
323323
* // language: 'en',
324-
* // sentiment: 100,
324+
* // sentiment: 1,
325325
* // entities: {
326326
* // organizations: [
327327
* // 'Google'
@@ -387,7 +387,7 @@ Document.PART_OF_SPEECH = {
387387
*
388388
* // annotation = {
389389
* // language: 'en',
390-
* // sentiment: 100,
390+
* // sentiment: 1,
391391
* // entities: {
392392
* // organizations: [
393393
* // 'Google'
@@ -414,7 +414,7 @@ Document.PART_OF_SPEECH = {
414414
* // annotation = {
415415
* // language: 'en',
416416
* // sentiment: {
417-
* // score: 100,
417+
* // score: 1,
418418
* // magnitude: 4
419419
* // },
420420
* // entities: {
@@ -425,7 +425,7 @@ Document.PART_OF_SPEECH = {
425425
* // metadata: {
426426
* // wikipedia_url: 'http://en.wikipedia.org/wiki/Google'
427427
* // },
428-
* // salience: 65.137446,
428+
* // salience: 0.65137446,
429429
* // mentions: [
430430
* // {
431431
* // text: {
@@ -444,7 +444,7 @@ Document.PART_OF_SPEECH = {
444444
* // metadata: {
445445
* // wikipedia_url: 'http://en.wikipedia.org/wiki/United_States'
446446
* // },
447-
* // salience: 13.947370648384094,
447+
* // salience: 0.13947370648384094,
448448
* // mentions: [
449449
* // {
450450
* // text: [
@@ -646,7 +646,7 @@ Document.prototype.annotate = function(options, callback) {
646646
* // metadata: {
647647
* // wikipedia_url: 'http: * //en.wikipedia.org/wiki/Google'
648648
* // },
649-
* // salience: 65.137446,
649+
* // salience: 0.65137446,
650650
* // mentions: [
651651
* // {
652652
* // text: {
@@ -664,7 +664,7 @@ Document.prototype.annotate = function(options, callback) {
664664
* // metadata: {
665665
* // wikipedia_url: 'http: * //en.wikipedia.org/wiki/United_States'
666666
* // },
667-
* // salience: 13.947371,
667+
* // salience: 0.13947371,
668668
* // mentions: [
669669
* // {
670670
* // text: {
@@ -721,8 +721,8 @@ Document.prototype.detectEntities = function(options, callback) {
721721
* results. Default: `false`
722722
* @param {function} callback - The callback function.
723723
* @param {?error} callback.err - An error occurred while making this request.
724-
* @param {number} callback.sentiment - A value in the range of `-100` to `100`.
725-
* Large numbers represent more positive sentiments.
724+
* @param {number} callback.sentiment - A value in the range of `-1` (negative)
725+
* to `1` (positive).
726726
* @param {object} callback.apiResponse - The full API response.
727727
*
728728
* @example
@@ -731,7 +731,7 @@ Document.prototype.detectEntities = function(options, callback) {
731731
* // Error handling omitted.
732732
* }
733733
*
734-
* // sentiment = 100
734+
* // sentiment = 1
735735
* });
736736
*
737737
* //-
@@ -747,7 +747,7 @@ Document.prototype.detectEntities = function(options, callback) {
747747
* }
748748
*
749749
* // sentiment = {
750-
* // score: 100,
750+
* // score: 1,
751751
* // magnitude: 4,
752752
* // sentences: [
753753
* // {
@@ -894,7 +894,7 @@ Document.prototype.detectSentiment = function(options, callback) {
894894
* // beginOffset: -1
895895
* // },
896896
* // sentiment: {
897-
* // score: 100
897+
* // score: 1
898898
* // magnitude: 4
899899
* // }
900900
* // }
@@ -997,8 +997,6 @@ Document.formatEntities_ = function(entities, verbose) {
997997

998998
var groupName = GROUP_NAME_TO_TYPE[entity.type];
999999

1000-
entity.salience *= 100;
1001-
10021000
acc[groupName] = arrify(acc[groupName]);
10031001
acc[groupName].push(entity);
10041002
acc[groupName].sort(Document.sortByProperty_('salience'));
@@ -1047,12 +1045,12 @@ Document.formatSentences_ = function(sentences, verbose) {
10471045
* API.
10481046
* @param {boolean} verbose - Enable verbose mode for more detailed results.
10491047
* @return {number|object} - The sentiment represented as a number in the range
1050-
* of `-100` to `100` or an object containing `score` and `magnitude`
1048+
* of `-1` to `1` or an object containing `score` and `magnitude`
10511049
* measurements in verbose mode.
10521050
*/
10531051
Document.formatSentiment_ = function(sentiment, verbose) {
10541052
sentiment = {
1055-
score: sentiment.score *= 100,
1053+
score: sentiment.score,
10561054
magnitude: sentiment.magnitude
10571055
};
10581056

packages/google-cloud-language/test/document.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -883,14 +883,6 @@ describe('Document', function() {
883883
other: [ entitiesCopy[15], entitiesCopy[14] ],
884884
};
885885

886-
for (var entityType in FORMATTED_ENTITIES) {
887-
FORMATTED_ENTITIES[entityType] = FORMATTED_ENTITIES[entityType]
888-
.map(function(entity) {
889-
entity.salience *= 100;
890-
return entity;
891-
});
892-
}
893-
894886
var EXPECTED_FORMATTED_ENTITIES = {
895887
default: extend(true, {}, FORMATTED_ENTITIES),
896888
verbose: extend(true, {}, FORMATTED_ENTITIES)
@@ -976,9 +968,9 @@ describe('Document', function() {
976968
var VERBOSE = false;
977969

978970
var EXPECTED_FORMATTED_SENTIMENT = {
979-
default: SENTIMENT.score * 100,
971+
default: SENTIMENT.score,
980972
verbose: {
981-
score: SENTIMENT.score * 100,
973+
score: SENTIMENT.score,
982974
magnitude: SENTIMENT.magnitude
983975
}
984976
};

0 commit comments

Comments
 (0)