微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用restsharp

如何解决使用restsharp

我使用以下命令运行从 here 获取的 docker 映像:

docker run -e ANNOTATORS=truecase,ner -p 9000:9000 -ti nlpBox/corenlp

使用前端时,可以很好地识别人/实体 john smith:

enter image description here

前端发出这个:

http://localhost:9000/?properties=%7B%22annotators%22%3A%20%22tokenize%2Cssplit%2Cner%22%2C%20%22date%22%3A%20%222021-07-23T11%3A18%3A21%22%7D&pipelineLanguage=en

解码:

http://localhost:9000/?properties={"annotators": "tokenize,ssplit,ner","date": "2021-07-23T11:18:21"}&pipelineLanguage=en

enter image description here

enter image description here

我的 C# 代码是:

var client = new RestClient(@"http://localhost:9000/")
{
    Timeout = 5000 // default 100 s
};

var request = new RestRequest(Method.POST)
{
    RequestFormat = DataFormat.Json
};
request.AddParameter("properties",@"{""annotators"":""truecase,tokenize,ner"",""date"": ""2021-07-23T11:29:23""}",ParameterType.QueryString);
request.AddParameter("pipelineLanguage","en",ParameterType.QueryString);
request.AddHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");

request.AddBody(@"hello john smith" );
var response = client.Execute(request);

不幸的是,它没有在返回的 JSON 中返回/识别此人:

剪辑

{
 "index": 3,"word": "john","originalText": "john","lemma": "john","characterOffsetBegin": 7,"characterOffsetEnd": 11,"pos": "NNP","ner": "O","truecase": "INIT_UPPER","truecaseText": "John","before": " ","after": " "
    },{
      "index": 4,"word": "smith","originalText": "smith","lemma": "smith","characterOffsetBegin": 12,"characterOffsetEnd": 17,"truecaseText": "Smith","after": ""
    },

剪辑

如果我将 John Smith 大写(我不想这样做),我会得到正确答案:

{
          "index": 3,"word": "John","originalText": "John","lemma": "John","ner": "PERSON","after": " "
        },{
          "index": 4,"word": "Smith","originalText": "Smith","lemma": "Smith","after": ""
        },

我可以破解这个并确保每个单词都以大写字母开头,但在理想的世界中,我想避免这种情况。谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。