2

当我Watson api NLU使用city位于India. 我得到空实体。它应该带有数据实体位置。那么我该如何解决这个问题watson NLU

发送的语句是:

布巴内斯瓦尔MBA学院

布巴内斯瓦尔是城市

4

2 回答 2

4

因此,根据您的评论语句:

“布巴内斯瓦尔 MBA 学院”

将其放入 NLU 和实体检测失败:

Error: unsupported text language: unknown, Code: 400

第一个问题是因为没有指定语言,它试图猜测语言。但是那里没有足够的猜测(即使对你来说很明显)。

第二个问题是,即使您指定语言,它也无法完全识别。这是因为它不是一个真正的句子,它是一个片段。

NLU 不只是进行关键字查找,它试图理解词性 (POS) 并从中确定单词的含义。

因此,如果我给它一个真实的句子,它将起作用。例如:

I go to an MBA college in Bhubaneswar

我使用了这个示例代码:

import json
from watson_developer_cloud import NaturalLanguageUnderstandingV1
from watson_developer_cloud.natural_language_understanding_v1 import Features, EntitiesOptions, RelationsOptions

ctx = {
  "url": "https://gateway.watsonplatform.net/natural-language-understanding/api",
  "username": "USERNAME",
  "password": "PASSWORD"
}
version = '2017-02-27'

text = "I go to an MBA college in Bhubaneswar"
#text = "mba college in bhubaneswar"

nlu = NaturalLanguageUnderstandingV1(version=version, username=ctx.get('username'),password=ctx.get('password'))
entities = EntitiesOptions()
relations = RelationsOptions()

response = nlu.analyze(text=text, features=Features(entities=entities,relations=relations),language='en')

print(json.dumps(response, indent=2))

这给了我以下结果。

{
  "usage": {
    "text_units": 1,
    "text_characters": 37,
    "features": 2
  },
  "relations": [
    {
      "type": "basedIn",
      "sentence": "I go to an MBA college in Bhubaneswar",
      "score": 0.669215,
      "arguments": [
        {
          "text": "college",
          "location": [
            15,
            22
          ],
          "entities": [
            {
              "type": "Organization",
              "text": "college"
            }
          ]
        },
        {
          "text": "Bhubaneswar",
          "location": [
            26,
            37
          ],
          "entities": [
            {
              "type": "GeopoliticalEntity",
              "text": "Bhubaneswar"
            }
          ]
        }
      ]
    }
  ],
  "language": "en",
  "entities": [
    {
      "type": "Location",
      "text": "Bhubaneswar",
      "relevance": 0.33,
      "disambiguation": {
        "subtype": [
          "IndianCity",
          "City"
        ],
        "name": "Bhubaneswar",
        "dbpedia_resource": "http://dbpedia.org/resource/Bhubaneswar"
      },
      "count": 1
    }
  ]
}

如果您只是要扫描碎片,那么@ReeceMed 解决方案将为您解决它。

于 2017-12-13T11:00:12.613 回答
1

NLU 服务响应的屏幕截图 如果 NLU 服务无法识别您输入的城市,您可以使用 Watson Knowledge Studio 创建自定义模型,然后将其部署到 NLU 服务,提供自定义实体和关系。

于 2017-12-13T10:02:57.000 回答