一、什么是ambiversenlu?
Demo:https://ambiversenlu.mpi-inf.mpg.de
简而言之,它能够帮助我们进行实体识别、足够方便的进行实体连接操作。
二、如何使用ambiversenlu?
在上面的demo链接页面使用ambiversenlu十分方便,只需要将句子复制到输入框,点击analysis就能够轻松得到结果。但是如何在程序中使用ambiversenlu呢?
(要在程序中使用ambiversenlu其实并不那么容易。我花了近两个晚上才实现在代码中使用。)
在JAVA中使用ambiversenlu有两种方式:一种是通过OKHTTP对ambiversenlu服务器访问,进行实体识别、实体连接。一种是使用ambiverse-nlu/nlu-api-client-java。
1、注册ambiversenlu developerID
无论使用哪一种方法,都必须要注册一个ambiversenlu账号。注册好后会有一个ID和Secret,如图:
方法一:使用OKHTTP访问:
(具体见:https://developer.ambiverse.com/overview)
首先,在https://developer.ambiverse.com/docs中获得一个token。这个token有效期是24小时。
如图:
然后会得到一个token:
接着,在你配置好OKHTTP。
配置好后就可以使用了!下面是简单示例代码:
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient();
okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"coherentDocument\": \"true\", \"confidenceThreshold\": \"0\", \"docId\": \"doc1\", \"text\": \"When Who played Tommy in Columbus, Pete was at his best.\", \"language\": \"en\", \"annotatedMentions\" : [ { \"charLength\":3, \"charOffset\":5 } ] }");
Request request = new Request.Builder()
.url("https://api.ambiverse.com/v2/entitylinking/analyze")
.post(body)
.addHeader("content-type", "application/json")
.addHeader("accept", "application/json")
.addHeader("authorization", "填入你得到的token")
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
} catch (IOException e) {
e.printStackTrace();
}
}
方法二:使用Ambiverse Natural Language Understanding API Client Library for Java
这个项目可以直接在GitHub上找到,下载下来后主要是一些依赖问题。如果不适用maven的话,整个依赖jar包在这里,把这些jar包导入项目,就可以运行了!(这些jar包我可是踩了很多坑踩弄全的!)