如何从classify_text单独获得名字/信心?

时间:2018-02-03 02:47:12

标签: google-api google-cloud-nl

语言api中的大多数其他方法,例如analyze_syntax,analyze_sentiment等,都能够返回组成元素,如

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

但是我没有找到一种方法来从classify_text中隔离返回名字和信心。它看起来不太可能,但这看起来很奇怪。我错过了什么?感谢

1 个答案:

答案 0 :(得分:1)

language.documents.classifyText方法返回ClassificationCategory对象,其中包含nameconfidence。如果您只想要其中一个字段,则可以按categories/namecategories/confidence进行过滤。作为一个例子,我执行了:

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"
 }
}

返回:

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

Direct link到API资源管理器,用于我的示例的交互式测试(更改内容,过滤器等)