依存句法分析,是指识别语句中词与词之间的依存关系,并揭示其句法结构,包括主谓关系、动宾关系、核心关系等。用依存语言学来理解语义,精准掌握用户意图
依存句法分析可以帮助我们去理解文本含义,语法分析是理解语言的重要一环,如果一个人只背单词而不学语法,看到长句子时依然无法理解语义,机器系统也是一样的道理。 语法分析目标是分析句子的语法结构并将其表示为容易理解的结构,通常是树形结构。而依存句法理论认为词与词之间存在主从关系,在一个句子中如果一个词修饰另外一个词,称修饰词为从属词,被修饰的词称为支配词,两者之间的语法关系成为依存关系。如“大梦想”中形容词大和名词梦想之间的依存关系为“定中关系”,即定语和中心语,“大”修饰“梦想”...





POST
| 参数名称 | 参数说明 | 请求类型 | 是否必须 | 数据类型 |
|---|---|---|---|---|
| text | 已完成分词的文本 | Body:form-data | true | string |
| token | 使用API时系统需要验证的身份信息 | Headers | true | string |
| 参数名称 | 参数示例 |
|---|---|
| 参数为json格式,json 中包含除token外所有参数 | {"text":"我的希望是希望张晚霞的背影被晚霞映红"} |
<dependencies> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.4.13</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.11</version> </dependency> </dependencies>
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* nlp分词范例
*/
public class test {
public static void main(String[] args) {
//请求头中的token 需要进行替换成在官网申请的新token
String token="TOKEN请在官网自行获取";
//申请的接口地址
String url="http://comdo.hanlp.com/hanlp/v1/segment/nlp";
//处理分析的文本,作为params参数传入
Map<String,Object> params=new HashMap<String,Object>();
//参数传入要处理分析的文本
params.put("text", "我的希望是希望张晚霞的背影被晚霞映红");
//执行HanLP接口,result为返回的结果
String result=doHanlpApi(token,url,params);
//打印输出结果
System.out.println(result);
}
public static String doHanlpApi(String token,String url,Map<String,Object> params) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
//添加header请求头,token请放在header里
httpPost.setHeader("token", token);
// 创建参数列表
List<NameValuePair> paramList = new ArrayList<>();
if (params != null) {
for (String key : params.keySet()) {
//所有参数依次放在paramList中
paramList.add(new BasicNameValuePair(key, (String) params.get(key)));
}
//模拟表单
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList, "utf-8");
httpPost.setEntity(entity);
}
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
return resultString;
} catch (Exception e) {
e.printStackTrace();
} finally {
if(response!=null) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
}
{
"code":0,
"data":[
{
"nature":"r",
"word":"我"
},
{
"nature":"u",
"word":"的"
},
{
"nature":"n",
"word":"希望"
},
{
"nature":"v",
"word":"是"
},
{
"nature":"v",
"word":"希望"
},
{
"nature":"nr",
"word":"张晚霞"
},
{
"nature":"u",
"word":"的"
},
{
"nature":"n",
"word":"背影"
},
{
"nature":"p",
"word":"被"
},
{
"nature":"n",
"word":"晚霞"
},
{
"nature":"v",
"word":"映"
},
{
"nature":"a",
"word":"红"
}
]
}