0

Most of the other methods in the language api, such as analyze_syntax, analyze_sentiment etc, have the ability to return the constituent elements like

sentiment.score
sentiment.magnitude
token.part_of_speech.tag
etc etc etc....

but I have not found a way to return name and confidence in isolation from classify_text. It doesn't look like it's possible but that seems weird. Am missing something? Thanks

Guillem Xercavins
  • 6,938
  • 1
  • 16
  • 35
Josh Flori
  • 295
  • 1
  • 2
  • 13

1 Answers1

1

The language.documents.classifyText method returns a ClassificationCategory object which contains name and confidence. If you only want one of the fields you can filter by categories/name or categories/confidence. As an example I executed:

POST https://language.googleapis.com/v1/documents:classifyText?fields=categories%2Fname&key={YOUR_API_KEY}

{
 "document": {
  "content": "this is a test for a StackOverflow question. I get an error because I need more words in the document and I don't know what else to say",
  "type": "PLAIN_TEXT"
 }
}

Which returns:

{
 "categories": [
  {
   "name": "/Science/Computer Science"
  },
  {
   "name": "/Computers & Electronics/Programming"
  },
  {
   "name": "/Jobs & Education"
  }
 ]
}

Direct link to API explorer for interactive testing of my example (change content, filters, etc.)

Guillem Xercavins
  • 6,938
  • 1
  • 16
  • 35
  • Thanks. I seem to have forgotten to be more specific. Do you know what the syntax is in python? --edit oh my gosh never mind i found it right in the documentation. https://cloud.google.com/natural-language/docs/classify-text-tutorial idk why it took me so long – Josh Flori Feb 03 '18 at 22:05