googleapis / nodejs-language

This repository is deprecated. All of its content and history has been moved to googleapis/google-cloud-node.
https://cloud.google.com/natural-language/
Apache License 2.0
127 stars 99 forks source link

beginOffset is always -1 with analyzeEntities #47

Closed lowi closed 6 years ago

lowi commented 6 years ago

Using this text to be analyzed: Fashion Original Phone Case for IPhone X High-end Transparent Plated Mobile Phone Back Shell for IPhone X TPU Soft Case Shell (Support Wireless Charging) Women's Stylish Vintage Flower Elastic Stretch Wide Belt Waistband Pen Multi Function Tool Stylus Ballpoint Screwdriver Ruler Bottle Opener Natural Wood Soap Tray Holder Dish Storage Bath Shower Plate Home Bathroom Decor Soft Cross Makeup False Eyelashes Handmade Eye Lashes Extension 100% Real 3D False Eyelashes 1pc New Mini Stereo Microphone Mic 3.5mm Mini Jack PC Laptop Notebook Auto Child Colorful Car Shoulder Belt Protection Car Styling Pad on The Seat Belt Cover ZIZI Women 's Fashion Leather Band Analog Quartz Wrist Watch Watch Bracelet Dress Men's Business Wallet ID Card Leather Wallet Purse Credit Card Holder Checkbook Black Wallet pink/blue Swimwear Gym Bags School Sports Drawstring Fishing Print Bags Foam Foldable Folding Seat Cushion EVA Pad EVA Kneeler Camping Outdoor Cushion

I get this response:

[
  {
    "entities": [
      {
        "mentions": [
          {
            "text": {
              "content": "Eye Lashes Extension",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          },
          {
            "text": {
              "content": "TPU Soft Case Shell",
              "beginOffset": -1
            },
            "type": "PROPER",
            "sentiment": null
          },
          {
            "text": {
              "content": "Support Wireless Charging",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "TPU Soft Case Shell",
        "type": "OTHER",
        "salience": 0.10348371416330338,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Mobile Phone",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Mobile Phone",
        "type": "CONSUMER_GOOD",
        "salience": 0.0656983032822609,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Shell",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Shell",
        "type": "OTHER",
        "salience": 0.0656983032822609,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Phone Case",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Phone Case",
        "type": "OTHER",
        "salience": 0.0656983032822609,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Fashion",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Fashion",
        "type": "OTHER",
        "salience": 0.0656983032822609,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Back",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Back",
        "type": "OTHER",
        "salience": 0.05776122957468033,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "IPhone X",
              "beginOffset": -1
            },
            "type": "PROPER",
            "sentiment": null
          }
        ],
        "metadata": {
          "mid": "/g/11f0wxpnn4",
          "wikipedia_url": "https://en.wikipedia.org/wiki/IPhone_X"
        },
        "name": "IPhone X",
        "type": "ORGANIZATION",
        "salience": 0.03952040523290634,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Shoulder Belt Protection Car Styling Pad",
              "beginOffset": -1
            },
            "type": "PROPER",
            "sentiment": null
          },
          {
            "text": {
              "content": "Car",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Shoulder Belt Protection Car Styling Pad",
        "type": "CONSUMER_GOOD",
        "salience": 0.03554096445441246,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "IPhone X High",
              "beginOffset": -1
            },
            "type": "PROPER",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "IPhone X High",
        "type": "ORGANIZATION",
        "salience": 0.03467646986246109,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Soap Tray",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          },
          {
            "text": {
              "content": "Natural Wood",
              "beginOffset": -1
            },
            "type": "PROPER",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Natural Wood",
        "type": "CONSUMER_GOOD",
        "salience": 0.03401121869683266,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Women",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Women",
        "type": "PERSON",
        "salience": 0.025680547580122948,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Waistband",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Waistband",
        "type": "PERSON",
        "salience": 0.022509152069687843,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Eyelashes",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Eyelashes",
        "type": "OTHER",
        "salience": 0.01741732284426689,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Eyelashes",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Eyelashes",
        "type": "OTHER",
        "salience": 0.01741732284426689,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Stylus",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Stylus",
        "type": "CONSUMER_GOOD",
        "salience": 0.01741732284426689,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Function Tool",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Function Tool",
        "type": "OTHER",
        "salience": 0.015256771817803383,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Ballpoint",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Ballpoint",
        "type": "CONSUMER_GOOD",
        "salience": 0.015256771817803383,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Screwdriver Ruler",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Screwdriver Ruler",
        "type": "ORGANIZATION",
        "salience": 0.015256771817803383,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Bottle Opener",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Bottle Opener",
        "type": "ORGANIZATION",
        "salience": 0.015256771817803383,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Dish Storage",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Dish Storage",
        "type": "OTHER",
        "salience": 0.015256771817803383,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Home",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Home",
        "type": "OTHER",
        "salience": 0.015256771817803383,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Bathroom Decor",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Bathroom Decor",
        "type": "OTHER",
        "salience": 0.015256771817803383,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Cross",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Cross",
        "type": "OTHER",
        "salience": 0.015256771817803383,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Makeup",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Makeup",
        "type": "OTHER",
        "salience": 0.015256771817803383,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Child",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Child",
        "type": "PERSON",
        "salience": 0.013971075415611267,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Jack PC",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Jack PC",
        "type": "CONSUMER_GOOD",
        "salience": 0.013971075415611267,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Notebook Auto",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Notebook Auto",
        "type": "ORGANIZATION",
        "salience": 0.013971075415611267,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Stylish Vintage Flower",
              "beginOffset": -1
            },
            "type": "PROPER",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Stylish Vintage Flower",
        "type": "ORGANIZATION",
        "salience": 0.013394285924732685,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Wallet",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Wallet",
        "type": "CONSUMER_GOOD",
        "salience": 0.01312266942113638,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Business Wallet ID Card",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Business Wallet ID Card",
        "type": "OTHER",
        "salience": 0.011943099088966846,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Credit Card",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Credit Card",
        "type": "OTHER",
        "salience": 0.011943099088966846,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Holder",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Holder",
        "type": "ORGANIZATION",
        "salience": 0.011943099088966846,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Men",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Men",
        "type": "PERSON",
        "salience": 0.010457240976393223,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Wallet Purse",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Wallet Purse",
        "type": "OTHER",
        "salience": 0.010457240976393223,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "New Mini Stereo",
              "beginOffset": -1
            },
            "type": "PROPER",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "New Mini Stereo",
        "type": "OTHER",
        "salience": 0.008295943960547447,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Gym Bags",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Gym Bags",
        "type": "CONSUMER_GOOD",
        "salience": 0.008284702897071838,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Print Bags",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Print Bags",
        "type": "CONSUMER_GOOD",
        "salience": 0.008284702897071838,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Folding Seat Cushion",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Folding Seat Cushion",
        "type": "CONSUMER_GOOD",
        "salience": 0.008284702897071838,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "EVA Pad",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "EVA Pad",
        "type": "PERSON",
        "salience": 0.008284702897071838,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Camping Outdoor Cushion",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Camping Outdoor Cushion",
        "type": "CONSUMER_GOOD",
        "salience": 0.008284702897071838,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "School Sports",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "School Sports",
        "type": "ORGANIZATION",
        "salience": 0.007251970004290342,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Quartz",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Quartz",
        "type": "OTHER",
        "salience": 0.004600143991410732,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "Fashion Leather Band",
              "beginOffset": -1
            },
            "type": "COMMON",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "Fashion Leather Band",
        "type": "ORGANIZATION",
        "salience": 0.004600143991410732,
        "sentiment": null
      },
      {
        "mentions": [
          {
            "text": {
              "content": "The Seat Belt Cover ZIZI Women",
              "beginOffset": -1
            },
            "type": "PROPER",
            "sentiment": null
          }
        ],
        "metadata": {},
        "name": "The Seat Belt Cover ZIZI Women",
        "type": "PERSON",
        "salience": 0.003114490071311593,
        "sentiment": null
      }
    ],
    "language": "en"
  }
]
stephenplusplus commented 6 years ago

This is a question better left to the API Support team. We are simply passing through the response they give us. Here are some better ways to reach them: https://cloud.google.com/natural-language/docs/support

Sorry I couldn't be more help.

firemuzzy commented 5 years ago

@lowi after digging through google's confusing docs I figured it out. Their sample code does not match the docs and is missing an encodingType

You have to pass in an "encodingType" parameter, which the sample code does not mention.

Your code should look like this

const document = {
  content: "I want this to be sentimented",
  type: 'PLAIN_TEXT'
};
googleLanguageClient.analyzeSentiment({document: document, encodingType: 'UTF16'})

this applies to all the analyze calls; analyzeSentiment, analyzeEntities

@stephenplusplus this is somewhat a problem on your end, your analyze.v1.js sample code does not send an encodingType parameter making it seem like a bug when users do not get an offset.

stephenplusplus commented 5 years ago

@firemuzzy awesome, thank you for figuring that out. If updating the samples would make this more clear, let's do that 👍 Anybody interested in sending a PR?