Skip to content

Commit

Permalink
language: remove sentiment and salience range conversions (#1834) (#1836
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sawyerh authored and stephenplusplus committed Nov 29, 2016
1 parent 4436c1d commit 50082da
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Jesse Friedman <jesse@jesse.ws>
Johan Euphrosine <proppy@google.com>
Marco Ziccardi <marco.ziccard@gmail.com>
Patrick Costello <pcostell@google.com>
Sawyer Hollenshead <hi@sawyerh.com>
Silvano Luciani <silvano@google.com>
Stephen Sawchuk <sawchuk@gmail.com>
Thomas Rognon <tcrognon@gmail.com>
Expand Down
32 changes: 15 additions & 17 deletions packages/language/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Document.PART_OF_SPEECH = {
* @param {string} callback.annotation.language - The language detected from the
* text.
* @param {number} callback.annotation.sentiment - A value in the range of
* `-100` to `100`. Large numbers represent more positive sentiments.
* `-1` (negative) to `1` (positive).
* @param {object} callback.annotation.entities - The recognized entities from
* the text, grouped by the type of entity.
* @param {string[]} callback.annotation.entities.art - Art entities detected
Expand Down Expand Up @@ -321,7 +321,7 @@ Document.PART_OF_SPEECH = {
*
* // annotation = {
* // language: 'en',
* // sentiment: 100,
* // sentiment: 1,
* // entities: {
* // organizations: [
* // 'Google'
Expand Down Expand Up @@ -387,7 +387,7 @@ Document.PART_OF_SPEECH = {
*
* // annotation = {
* // language: 'en',
* // sentiment: 100,
* // sentiment: 1,
* // entities: {
* // organizations: [
* // 'Google'
Expand All @@ -414,7 +414,7 @@ Document.PART_OF_SPEECH = {
* // annotation = {
* // language: 'en',
* // sentiment: {
* // score: 100,
* // score: 1,
* // magnitude: 4
* // },
* // entities: {
Expand All @@ -425,7 +425,7 @@ Document.PART_OF_SPEECH = {
* // metadata: {
* // wikipedia_url: 'http://en.wikipedia.org/wiki/Google'
* // },
* // salience: 65.137446,
* // salience: 0.65137446,
* // mentions: [
* // {
* // text: {
Expand All @@ -444,7 +444,7 @@ Document.PART_OF_SPEECH = {
* // metadata: {
* // wikipedia_url: 'http://en.wikipedia.org/wiki/United_States'
* // },
* // salience: 13.947370648384094,
* // salience: 0.13947370648384094,
* // mentions: [
* // {
* // text: [
Expand Down Expand Up @@ -646,7 +646,7 @@ Document.prototype.annotate = function(options, callback) {
* // metadata: {
* // wikipedia_url: 'http: * //en.wikipedia.org/wiki/Google'
* // },
* // salience: 65.137446,
* // salience: 0.65137446,
* // mentions: [
* // {
* // text: {
Expand All @@ -664,7 +664,7 @@ Document.prototype.annotate = function(options, callback) {
* // metadata: {
* // wikipedia_url: 'http: * //en.wikipedia.org/wiki/United_States'
* // },
* // salience: 13.947371,
* // salience: 0.13947371,
* // mentions: [
* // {
* // text: {
Expand Down Expand Up @@ -721,8 +721,8 @@ Document.prototype.detectEntities = function(options, callback) {
* results. Default: `false`
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error occurred while making this request.
* @param {number} callback.sentiment - A value in the range of `-100` to `100`.
* Large numbers represent more positive sentiments.
* @param {number} callback.sentiment - A value in the range of `-1` (negative)
* to `1` (positive).
* @param {object} callback.apiResponse - The full API response.
*
* @example
Expand All @@ -731,7 +731,7 @@ Document.prototype.detectEntities = function(options, callback) {
* // Error handling omitted.
* }
*
* // sentiment = 100
* // sentiment = 1
* });
*
* //-
Expand All @@ -747,7 +747,7 @@ Document.prototype.detectEntities = function(options, callback) {
* }
*
* // sentiment = {
* // score: 100,
* // score: 1,
* // magnitude: 4,
* // sentences: [
* // {
Expand Down Expand Up @@ -894,7 +894,7 @@ Document.prototype.detectSentiment = function(options, callback) {
* // beginOffset: -1
* // },
* // sentiment: {
* // score: 100
* // score: 1
* // magnitude: 4
* // }
* // }
Expand Down Expand Up @@ -997,8 +997,6 @@ Document.formatEntities_ = function(entities, verbose) {

var groupName = GROUP_NAME_TO_TYPE[entity.type];

entity.salience *= 100;

acc[groupName] = arrify(acc[groupName]);
acc[groupName].push(entity);
acc[groupName].sort(Document.sortByProperty_('salience'));
Expand Down Expand Up @@ -1047,12 +1045,12 @@ Document.formatSentences_ = function(sentences, verbose) {
* API.
* @param {boolean} verbose - Enable verbose mode for more detailed results.
* @return {number|object} - The sentiment represented as a number in the range
* of `-100` to `100` or an object containing `score` and `magnitude`
* of `-1` to `1` or an object containing `score` and `magnitude`
* measurements in verbose mode.
*/
Document.formatSentiment_ = function(sentiment, verbose) {
sentiment = {
score: sentiment.score *= 100,
score: sentiment.score,
magnitude: sentiment.magnitude
};

Expand Down
12 changes: 2 additions & 10 deletions packages/language/test/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,14 +883,6 @@ describe('Document', function() {
other: [ entitiesCopy[15], entitiesCopy[14] ],
};

for (var entityType in FORMATTED_ENTITIES) {
FORMATTED_ENTITIES[entityType] = FORMATTED_ENTITIES[entityType]
.map(function(entity) {
entity.salience *= 100;
return entity;
});
}

var EXPECTED_FORMATTED_ENTITIES = {
default: extend(true, {}, FORMATTED_ENTITIES),
verbose: extend(true, {}, FORMATTED_ENTITIES)
Expand Down Expand Up @@ -976,9 +968,9 @@ describe('Document', function() {
var VERBOSE = false;

var EXPECTED_FORMATTED_SENTIMENT = {
default: SENTIMENT.score * 100,
default: SENTIMENT.score,
verbose: {
score: SENTIMENT.score * 100,
score: SENTIMENT.score,
magnitude: SENTIMENT.magnitude
}
};
Expand Down

0 comments on commit 50082da

Please sign in to comment.