关键词共现(KeywordCooccurrenceController)¶
提供 KMS 知识管理模块「关键词共现图域」的能力:返回全部关键词及关键词共现关系,供前端力导向图等可视化场景使用。本控制器仅有 1 个端点。
- 接口类型:REST 资源(
@RestController,方法级produces = MediaType.APPLICATION_JSON_VALUE) - 基址:
${myapps.context-path.kms:}/api/keywords(类级@RequestMapping仅声明单一前缀) - Tag:kms关键词模块
公共说明¶
- 鉴权(据源码
KmsMvcConfig+KmsSecurityFilter):KmsMvcConfig注册全局 Servlet 过滤器KmsSecurityFilter(URL 模式/*,context-path 为/时为/kms/*)。本控制器路径/api/keywords/cooccurrence-graph不在KmsSecurityFilter.isExcludeURI的豁免名单内(豁免仅覆盖/login.*、/admin、/domain.*、/tray/service、/authtime、service/OfficeServer、.*outsideshare/.*/preview、静态资源后缀、actuator/health等)。过滤器调用Security.getUserIdFromToken(request),取不到用户则返回 HTTP401。因此本端点需 accessToken,可通过以下任一方式传递(据Security.getUserIdFromToken):query 参数accessToken、query 参数access_token(移动端)、请求头accessToken、CookieaccessToken、请求头Authorization: Bearer <token>。完整鉴权机制见 index.md「鉴权说明」。 - 执行用户:本端点不调用
getUser(),无用户态过滤,返回全局关键词与共现数据。 - 响应结构:统一
Resource(见 ../index.md「统一响应结构」),字段为errcode/errmsg/data/errors。
1. 关键词共现图数据¶
返回全部关键词及关键词两两共现关系(同一文件中共同出现的关键词对),构造为力导向图节点 / 边结构。
- 接口类型:REST 资源
- 请求方式:
GET - 请求路径:
/cooccurrence-graph(完整:{kms-context}/api/keywords/cooccurrence-graph) - 鉴权:是(需 accessToken,据源码)
- Tag:kms关键词模块
请求参数¶
无。
请求示例¶
响应¶
结构:统一 Resource。
data:CooccurrenceGraphData,结构如下:
| 字段 | 类型 | 说明 |
|---|---|---|
| nodes | array | 关键词节点列表,每项见下表 |
| edges | array | 关键词共现边列表,每项见下表 |
节点(CooccurrenceGraphNode):
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 关键词Id(KmsKeyword.id) |
| label | string | 关键词文本(KmsKeyword.content,空串安全) |
| weight | long | 关键词关联文件数(KmsKeyword.count,null 作 0) |
边(CooccurrenceGraphEdge):
| 字段 | 类型 | 说明 |
|---|---|---|
| source | string | 关键词1Id(KeywordCooccurrence.keywordId1) |
| target | string | 关键词2Id(KeywordCooccurrence.keywordId2) |
| weight | long/number | 同文件共现次数(KeywordCooccurrence.weight) |
成功示例:
{
"errcode": 0,
"errmsg": "ok",
"data": {
"nodes": [
{ "id": "__KWID1__", "label": "报销", "weight": 12 },
{ "id": "__KWID2__", "label": "审批", "weight": 8 }
],
"edges": [
{ "source": "__KWID1__", "target": "__KWID2__", "weight": 5 }
]
},
"errors": null
}