Commit 56839b02 by 侯昆

主题 关联词 与 图谱数据

1 parent be04608f
......@@ -14,16 +14,26 @@
package com.dookay.cihai.wechat.controller;
import com.alibaba.fastjson.JSONObject;
import com.dookay.cihai.core.aip.AipWordUtilBean;
import com.dookay.cihai.core.aip.model.WordRelation;
import com.dookay.cihai.core.aip.model.WordSequence;
import com.dookay.cihai.core.theme.domain.ThemeDomain;
import com.dookay.cihai.core.theme.service.IThemeService;
import com.dookay.coral.common.web.controller.BaseController;
import com.dookay.coral.common.web.response.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author 石磊
* @date 2017/12/6
......@@ -34,6 +44,8 @@ public class ThemeController extends BaseController {
@Autowired
private IThemeService themeService;
@Autowired
private AipWordUtilBean aipWordUtilBean;
/**
* @author 石磊
......@@ -47,4 +59,39 @@ public class ThemeController extends BaseController {
mv.addObject("theme", themeDomain);
return mv;
}
/**
* 关联词出现次数
*
* @author houkun
* @date 2017/12/7
*/
@RequestMapping(value = "/detail/{id}/related", method = RequestMethod.GET)
@ResponseBody
public JsonResult related(@PathVariable Long id) {
ThemeDomain themeDomain = themeService.get(id);
String document = themeDomain.getIntroduce();
Map<String, Long> wordCountMap = aipWordUtilBean.extractNounWordsWithCount(document);
return successResult("关联词出现次数", wordCountMap);
}
/**
* 图谱信息
*
* @author houkun
* @date 2017/12/7
*/
@RequestMapping(value = "/detail/{id}/map", method = RequestMethod.GET)
@ResponseBody
public JsonResult map(@PathVariable Long id) {
ThemeDomain themeDomain = themeService.get(id);
String document = themeDomain.getIntroduce();
List<String> keywords = aipWordUtilBean.extractKeyWords(themeDomain.getTitle(), document, 15);
List<WordSequence> wordSequences = keywords.stream().map(l -> new WordSequence(keywords.indexOf(l), l)).collect(Collectors.toList());
List<WordRelation> wordRelations = aipWordUtilBean.generateWordsMap(keywords);
JSONObject jsonObject = new JSONObject();
jsonObject.put("nodes", wordSequences);
jsonObject.put("edges", wordRelations);
return successResult("success", jsonObject);
}
}
......@@ -11,7 +11,7 @@ logging.level.root=info
logging.level.com.dookay.core=trace
# redis
spring.redis.host=192.168.2.27
spring.redis.password=lyd123456
spring.redis.password=100001
# 文件存储
coral.web.resource.mapping.uploads-inner=/uploads/*
coral.web.resource.mapping.uploads-mapping=/data/www/uploads/cihai
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!