当我使用Watson api NLU
和位于city
中的India
发送文本时。我正在获得空实体。它应该随数据实体位置一起提供。那么我该如何在watson NLU
中解决此问题。
发送的句子是:
工商管理学院
布巴内斯瓦尔(Bhubaneswar)是城市
最佳答案
因此,根据您的以下评论句:
“布巴内斯瓦尔的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将为您解决该问题。