我的城市位置在IBM Watson api NLU中不可用

时间:2017-12-13 07:45:29

标签: watson-conversation watson watson-nlu

当我使用位于Watson api NLU的{​​{1}}使用city发送文字时。我变空了实体。它应该带有数据实体位置。那么如何在India中解决这个问题。

发送的句子是:

  bhubaneswar的mba学院

布巴内斯瓦尔是这座城市的地方

2 个答案:

答案 0 :(得分: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 solution将为您解决此问题。

答案 1 :(得分:1)

Screenshot of NLU Service response如果NLU服务无法识别您输入的城市,您可以使用Watson Knowledge Studio创建自定义模型,然后可以将其部署到NLU服务,从而提供自定义实体和关系。