Commit 6d444bb4 by 徐甲彬

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	serverside/cihai-core/src/main/java/com/dookay/cihai/core/aip/AipImageClassifyClient.java
2 parents 59312ac5 9c96653b
......@@ -58,7 +58,7 @@ public final class AipWordUtilBean {
private static final String SCORE_KEY_PREFIX = "WORD_SCORE:";
private static final double CRITICAL_VALUE = 0.4D;
private static final double RELATE_CRITICAL_VALUE = 0.6D;
private static final double RELATE_CRITICAL_VALUE = 0.65D;
/**
* 内部错误
......@@ -250,7 +250,7 @@ public final class AipWordUtilBean {
* @author houkun
* @date 2017/12/6
*/
private List<LexerItem> getLexerItems(String document) throws JSONException {
public List<LexerItem> getLexerItems(String document) throws JSONException {
List<String> documents = splitDocument(document, 10000);
List<LexerItem> lexerItems = new ArrayList<>();
for (String s : documents) {
......
......@@ -81,6 +81,8 @@ public class WordDomain implements Serializable {
private String wordSpell;
private String category;
private String wordAlias;
}
......@@ -6,6 +6,8 @@ import tk.mybatis.mapper.entity.Example;
import com.dookay.coral.common.core.persistence.criteria.QueryCriteria;
import com.dookay.cihai.core.word.domain.WordDomain;
import java.util.List;
/**
* 词条
*
......@@ -18,12 +20,27 @@ public class WordQuery extends Query {
private String keyword;
private List<String> keywordList;
@Override
public QueryCriteria toCriteria() {
QueryCriteria queryCriteria = new QueryCriteria(WordDomain.class);
Example.Criteria criteria = queryCriteria.createCriteria();
if (valid(keyword)) {
String str = "%" + keyword + "%";
criteria.andCondition(String.format("(word like '%s' or word_alias like '%s')", str, str));
}
if (valid(keywordList)) {
String sql = "";
for (int i = 0; i < keywordList.size(); i++) {
if (i == 0) {
sql += " word like '%" + keywordList.get(i) + "%'";
} else {
sql += " or word like '%" + keywordList.get(i) + "%'";
}
}
System.out.println(sql);
criteria.andCondition(sql);
}
//todo 写查询逻辑
return queryCriteria;
......
......@@ -14,15 +14,23 @@
package com.dookay.cihai.wechat.controller;
import com.dookay.cihai.core.aip.AipImageClassifyClient;
import com.dookay.cihai.core.aip.AipWordUtilBean;
import com.dookay.cihai.core.aip.model.ImageResult;
import com.dookay.cihai.core.aip.model.LexerItem;
import com.dookay.cihai.core.theme.domain.ThemeDomain;
import com.dookay.cihai.core.theme.query.ThemeQuery;
import com.dookay.cihai.core.theme.service.IThemeService;
import com.dookay.cihai.core.word.domain.WordDomain;
import com.dookay.cihai.core.word.domain.CustomDictionaryDomain;
import com.dookay.cihai.core.word.query.CustomDictionaryQuery;
import com.dookay.cihai.core.word.query.WordQuery;
import com.dookay.cihai.core.word.service.ICustomDictionaryService;
import com.dookay.cihai.core.word.service.IWordService;
import com.dookay.coral.common.web.constant.MediaTypes;
import com.dookay.coral.common.web.controller.BaseController;
import com.dookay.coral.common.web.response.JsonResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -30,6 +38,9 @@ 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.stream.Collectors;
/**
* @author 石磊
* @date 2017/12/6
......@@ -49,6 +60,9 @@ public class HomeController extends BaseController {
@Autowired
private AipWordUtilBean aipWordUtilBean;
@Autowired
private AipImageClassifyClient aipImageClassifyClient;
/**
* @author 石磊
* @date 2017/12/6
......@@ -68,25 +82,72 @@ public class HomeController extends BaseController {
@RequestMapping(value = "/home/search", method = RequestMethod.GET)
@ResponseBody
public JsonResult search(String keyword) {
System.out.println("进入搜索");
System.out.println("进入搜索:" + keyword);
if (StringUtils.isBlank(keyword)) {
return errorResult("搜索内容不能为空");
}
String result = null;
CustomDictionaryQuery query1 = new CustomDictionaryQuery();
query1.setWord(keyword);
boolean inDic = false;
List<CustomDictionaryDomain> dictionaryDomainList = customDictionaryService.getList(new CustomDictionaryQuery());
for (CustomDictionaryDomain dic : dictionaryDomainList) {
if (keyword.contains(dic.getWord())) {
result = dic.getWord();
inDic = true;
}
}
try {
int count = customDictionaryService.count(query1);
if (count > 0) {
result = keyword;
} else {
if (!inDic) {
result = aipWordUtilBean.extractQueryKeyword(keyword);
}
ThemeQuery query = new ThemeQuery();
query.setKeyword(result);
ThemeDomain themeDomain = themeService.getFirst(query);
if (themeDomain == null) return errorResult(String.format("暂无\"%s\"检索结果",keyword));
if (themeDomain == null) {
WordQuery wordQuery = new WordQuery();
wordQuery.setKeyword(result);
WordDomain wordDomain = wordService.getFirst(wordQuery);
if (wordDomain == null) {
List<LexerItem> items = aipWordUtilBean.getLexerItems(result);
wordQuery.setKeywordList(items.stream().map(n -> n.getItem()).collect(Collectors.toList()));
wordQuery.setKeyword(null);
wordDomain = wordService.getFirst(wordQuery);
if (wordDomain == null) return errorResult(String.format("暂无\"%s\"检索结果", keyword));
}
return successResult("success", "/word/baike/" + wordDomain.getId());
}
System.out.println(themeDomain);
return successResult("success", "/theme/detail/" + themeDomain.getId());
} catch (Exception ex) {
return errorResult(String.format("暂无\"%s\"检索结果",keyword));
return errorResult(String.format("暂无\"%s\"检索结果", keyword));
}
}
/**
* @author 石磊
* @date 2017/12/7
* @description 图片搜索
*/
@RequestMapping(value = "/image/search", method = RequestMethod.POST, produces = MediaTypes.JSON_UTF_8)
@ResponseBody
public JsonResult imageSearch(String image) {
System.out.println("进入图片检索");
try {
ImageResult imageResult = aipImageClassifyClient.getImageResult(image);
String name = imageResult.getName();
System.out.println(name);
WordQuery wordQuery = new WordQuery();
wordQuery.setKeyword(name);
WordDomain wordDomain = wordService.getFirst(wordQuery);
if (wordDomain == null) {
List<LexerItem> items = aipWordUtilBean.getLexerItems(name);
wordQuery.setKeywordList(items.stream().map(n -> n.getItem()).collect(Collectors.toList()));
wordQuery.setKeyword(null);
wordDomain = wordService.getFirst(wordQuery);
if (wordDomain == null) return errorResult("暂无检索结果");
}
return successResult("success", "/word/baike/" + wordDomain.getId());
} catch (Exception ex) {
return errorResult("暂无检索结果");
}
}
......
......@@ -23,6 +23,7 @@ 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 com.dookay.coral.common.web.utils.HtmlUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -57,8 +58,16 @@ public class ThemeController extends BaseController {
@RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
public ModelAndView detail(@PathVariable Long id) {
ThemeDomain themeDomain = themeService.get(id);
String document = themeDomain.getIntroduce();
document = HtmlUtils.removeTag(document);
List<WordCount> wordCounts = aipWordUtilBean.extractNounWordsWithCount(document)
.stream().sorted(Comparator.comparing(WordCount::getValue).reversed())
.filter(w -> !w.getLabel().equals(themeDomain.getTitle()))
.limit(10)
.collect(Collectors.toList());
ModelAndView mv = new ModelAndView("portal/theme/detail");
mv.addObject("theme", themeDomain);
mv.addObject("wordCounts", wordCounts);
return mv;
}
......@@ -73,6 +82,7 @@ public class ThemeController extends BaseController {
public JsonResult related(@PathVariable Long id) {
ThemeDomain themeDomain = themeService.get(id);
String document = themeDomain.getIntroduce();
document = HtmlUtils.removeTag(document);
List<WordCount> wordCounts = aipWordUtilBean.extractNounWordsWithCount(document);
List<WordCount> collect = wordCounts.stream().sorted(Comparator.comparingDouble(l -> Math.random())).limit(8).collect(Collectors.toList());
JSONObject result = new JSONObject();
......@@ -92,6 +102,7 @@ public class ThemeController extends BaseController {
public JsonResult map(@PathVariable Long id) {
ThemeDomain themeDomain = themeService.get(id);
String document = themeDomain.getIntroduce();
document = HtmlUtils.removeTag(document);
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);
......
......@@ -57,7 +57,6 @@
wx.stopRecord({
success: function (res) {
myApp.dialog.preloader();
var localId = res.localId;
wx.translateVoice({
localId: localId, // 需要识别的音频的本地Id,由录音相关接口获得
......@@ -105,9 +104,19 @@
localId: localIds[0], // 图片的localID
success: function (res) {
myApp.dialog.preloader();
var localData = res.localData; // localData是图片的base64数据,可以用img标签显示
alert(localData);
jQuery.post("/image/search",{image:localData},function (data) {
myApp.dialog.close();
if (data.code == "OK") {
// myApp.view.main.router.load({
// url:data.data
// });
location.href = data.data;
} else {
myApp.dialog.alert(data.message);
}
})
}
});
......
<%--@elvariable id="theme" type="com.dookay.cihai.core.theme.domain.ThemeDomain"--%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
......@@ -27,30 +28,14 @@
<img src="${ctx}/static/images/special-top.png">
</div>
<div class="txt-content">
<p class="intro-txt">中国共产党第十九次全国代表大会(简称党的十九大)于2017年10月18日至10月24日在北京召开。</p>
<p class="intro-txt">2017年10月18日上午9:00,中国共产党第十九次全国代表大会在人民大会堂开幕。习近平代表第十八届中央委员会向大会作了题为《决胜全面建成小康社会 夺取新时代中国特色社会主义伟大胜利》的报告。</p>
<p class="intro-txt">这次大会的主题是:不忘初心,牢记使命,高举中国特色社会主义伟大旗帜,决胜全面建成小康社会,夺取新时代中国特色社会主义伟大胜利,为实现中华民族伟大复兴的中国梦不懈奋斗。</p>
${theme.introduce}
</div>
<div class="read-more js-read-more">
<span class="txt">展开阅读全部</span>
<span class="iconfont icon-zhankai"></span>
</div>
<h5 class="sub-title">基本信息</h5>
<div class="basic-msg">
<b>中文名称:</b>中国共产党第十九次全国代表大会
</div>
<div class="basic-msg">
<b>会议简称:</b>党的十九大
</div>
<div class="basic-msg">
<b>会议时间:</b>2017年10月18日-24日
</div>
<div class="basic-msg">
<b>会议地点:</b>北京
</div>
<div class="basic-msg">
<b>代表人数:</b>2287(确认2280名代表资格有效)
</div>
${theme.basicInfo}
</div>
</div>
<!--相关词条-->
......@@ -77,149 +62,143 @@
<div class="extend-word">
<div class="name">延伸词条</div>
<div class="word-list">
<div class="item">新时代</div>
<div class="item">主要矛盾</div>
<div class="item">四个伟大</div>
<div class="item">全面小康</div>
<div class="item">新征程</div>
<div class="item">新时代</div>
<div class="item">中国特色社会主义思想</div>
<div class="item">土地承包</div>
<div class="item">全面依法治国</div>
<div class="item">青春梦想</div>
<%--@elvariable id="wordCounts" type="java.util.List<com.dookay.cihai.core.aip.model.WordCount>"--%>
<c:forEach items="${wordCounts}" var="item">
<div class="item">${item.label}</div>
</c:forEach>
</div>
</div>
</div>
</div>
<!--"数"说十九大-->
<div class="num-progress">
<div class="special-title">
<div class="tip">
<img src="${ctx}/static/images/special-tip.png">
</div>
<div class="title">"数"说十九大</div>
</div>
<div class="block block-strong inset">
<div class="swiper-button-prev iconfont icon-jiantou"></div>
<div class="swiper-button-next iconfont icon-jiantou"></div>
<div class="swiper-container num-swiper">
<div class="swiper-wrapper">
<div class="swiper-slide active">350公里</div>
<div class="swiper-slide">6000多万</div>
<div class="swiper-slide">103个国家</div>
<div class="swiper-slide">1.2亿吨</div>
<div class="swiper-slide active">350公里</div>
<div class="swiper-slide">6000多万</div>
</div>
</div>
<div class="swiper-container num-content-swiper">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="time">2017年9月21号</div>
<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>
<div class="key-word">
<span class="name">延展关键词:</span>
<span class="item">高铁</span>
<span class="item">速度</span>
<span class="item">铁路</span>
<span class="item">复兴号</span>
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-02.jpg">
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-08.jpg">
</div>
</div>
<div class="swiper-slide">
<div class="time">2017年9月22号</div>
<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>
<div class="key-word">
<span class="name">延展关键词:</span>
<span class="item">高铁</span>
<span class="item">速度</span>
<span class="item">铁路</span>
<span class="item">复兴号</span>
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-02.jpg">
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-08.jpg">
</div>
</div>
<div class="swiper-slide">
<div class="time">2017年9月23号</div>
<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>
<div class="key-word">
<span class="name">延展关键词:</span>
<span class="item">高铁</span>
<span class="item">速度</span>
<span class="item">铁路</span>
<span class="item">复兴号</span>
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-02.jpg">
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-08.jpg">
</div>
</div>
<div class="swiper-slide">
<div class="time">2017年9月24号</div>
<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>
<div class="key-word">
<span class="name">延展关键词:</span>
<span class="item">高铁</span>
<span class="item">速度</span>
<span class="item">铁路</span>
<span class="item">复兴号</span>
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-02.jpg">
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-08.jpg">
</div>
</div>
<div class="swiper-slide">
<div class="time">2017年9月21号</div>
<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>
<div class="key-word">
<span class="name">延展关键词:</span>
<span class="item">高铁</span>
<span class="item">速度</span>
<span class="item">铁路</span>
<span class="item">复兴号</span>
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-02.jpg">
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-08.jpg">
</div>
</div>
<div class="swiper-slide">
<div class="time">2017年9月22号</div>
<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>
<div class="key-word">
<span class="name">延展关键词:</span>
<span class="item">高铁</span>
<span class="item">速度</span>
<span class="item">铁路</span>
<span class="item">复兴号</span>
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-02.jpg">
</div>
<div class="pic">
<img src="${ctx}/static/images/special-pic-08.jpg">
</div>
</div>
</div>
</div>
</div>
</div>
<%--<div class="num-progress">--%>
<%--<div class="special-title">--%>
<%--<div class="tip">--%>
<%--<img src="${ctx}/static/images/special-tip.png">--%>
<%--</div>--%>
<%--<div class="title">"数"说十九大</div>--%>
<%--</div>--%>
<%--<div class="block block-strong inset">--%>
<%--<div class="swiper-button-prev iconfont icon-jiantou"></div>--%>
<%--<div class="swiper-button-next iconfont icon-jiantou"></div>--%>
<%--<div class="swiper-container num-swiper">--%>
<%--<div class="swiper-wrapper">--%>
<%--<div class="swiper-slide active">350公里</div>--%>
<%--<div class="swiper-slide">6000多万</div>--%>
<%--<div class="swiper-slide">103个国家</div>--%>
<%--<div class="swiper-slide">1.2亿吨</div>--%>
<%--<div class="swiper-slide active">350公里</div>--%>
<%--<div class="swiper-slide">6000多万</div>--%>
<%--</div>--%>
<%--</div>--%>
<%--<div class="swiper-container num-content-swiper">--%>
<%--<div class="swiper-wrapper">--%>
<%--<div class="swiper-slide">--%>
<%--<div class="time">2017年9月21号</div>--%>
<%--<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>--%>
<%--<div class="key-word">--%>
<%--<span class="name">延展关键词:</span>--%>
<%--<span class="item">高铁</span>--%>
<%--<span class="item">速度</span>--%>
<%--<span class="item">铁路</span>--%>
<%--<span class="item">复兴号</span>--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-02.jpg">--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-08.jpg">--%>
<%--</div>--%>
<%--</div>--%>
<%--<div class="swiper-slide">--%>
<%--<div class="time">2017年9月22号</div>--%>
<%--<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>--%>
<%--<div class="key-word">--%>
<%--<span class="name">延展关键词:</span>--%>
<%--<span class="item">高铁</span>--%>
<%--<span class="item">速度</span>--%>
<%--<span class="item">铁路</span>--%>
<%--<span class="item">复兴号</span>--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-02.jpg">--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-08.jpg">--%>
<%--</div>--%>
<%--</div>--%>
<%--<div class="swiper-slide">--%>
<%--<div class="time">2017年9月23号</div>--%>
<%--<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>--%>
<%--<div class="key-word">--%>
<%--<span class="name">延展关键词:</span>--%>
<%--<span class="item">高铁</span>--%>
<%--<span class="item">速度</span>--%>
<%--<span class="item">铁路</span>--%>
<%--<span class="item">复兴号</span>--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-02.jpg">--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-08.jpg">--%>
<%--</div>--%>
<%--</div>--%>
<%--<div class="swiper-slide">--%>
<%--<div class="time">2017年9月24号</div>--%>
<%--<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>--%>
<%--<div class="key-word">--%>
<%--<span class="name">延展关键词:</span>--%>
<%--<span class="item">高铁</span>--%>
<%--<span class="item">速度</span>--%>
<%--<span class="item">铁路</span>--%>
<%--<span class="item">复兴号</span>--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-02.jpg">--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-08.jpg">--%>
<%--</div>--%>
<%--</div>--%>
<%--<div class="swiper-slide">--%>
<%--<div class="time">2017年9月21号</div>--%>
<%--<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>--%>
<%--<div class="key-word">--%>
<%--<span class="name">延展关键词:</span>--%>
<%--<span class="item">高铁</span>--%>
<%--<span class="item">速度</span>--%>
<%--<span class="item">铁路</span>--%>
<%--<span class="item">复兴号</span>--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-02.jpg">--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-08.jpg">--%>
<%--</div>--%>
<%--</div>--%>
<%--<div class="swiper-slide">--%>
<%--<div class="time">2017年9月22号</div>--%>
<%--<p class="txt">中车生产的自主知识产权的中国高铁“复兴号”在京沪线上以每小时350公里的速度正式运营。中车产品出口到世界七大洲 103个国家。</p>--%>
<%--<div class="key-word">--%>
<%--<span class="name">延展关键词:</span>--%>
<%--<span class="item">高铁</span>--%>
<%--<span class="item">速度</span>--%>
<%--<span class="item">铁路</span>--%>
<%--<span class="item">复兴号</span>--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-02.jpg">--%>
<%--</div>--%>
<%--<div class="pic">--%>
<%--<img src="${ctx}/static/images/special-pic-08.jpg">--%>
<%--</div>--%>
<%--</div>--%>
<%--</div>--%>
<%--</div>--%>
<%--</div>--%>
<%--</div>--%>
<!--十九大图谱-->
<div class="relation-pic">
<div class="special-title">
......
......@@ -290,7 +290,7 @@
<div class="navbar">
<div class="navbar-inner">
<div class="left">
<a class="link back" href="/">
<a class="link back js-jump-page" href="/">
<i class="iconfont icon-jiantou"></i>
<span class="ios-only">返回</span>
</a>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!