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 { ...@@ -58,7 +58,7 @@ public final class AipWordUtilBean {
private static final String SCORE_KEY_PREFIX = "WORD_SCORE:"; private static final String SCORE_KEY_PREFIX = "WORD_SCORE:";
private static final double CRITICAL_VALUE = 0.4D; 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 { ...@@ -250,7 +250,7 @@ public final class AipWordUtilBean {
* @author houkun * @author houkun
* @date 2017/12/6 * @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<String> documents = splitDocument(document, 10000);
List<LexerItem> lexerItems = new ArrayList<>(); List<LexerItem> lexerItems = new ArrayList<>();
for (String s : documents) { for (String s : documents) {
......
...@@ -82,5 +82,7 @@ public class WordDomain implements Serializable { ...@@ -82,5 +82,7 @@ public class WordDomain implements Serializable {
private String category; private String category;
private String wordAlias;
} }
...@@ -6,6 +6,8 @@ import tk.mybatis.mapper.entity.Example; ...@@ -6,6 +6,8 @@ import tk.mybatis.mapper.entity.Example;
import com.dookay.coral.common.core.persistence.criteria.QueryCriteria; import com.dookay.coral.common.core.persistence.criteria.QueryCriteria;
import com.dookay.cihai.core.word.domain.WordDomain; import com.dookay.cihai.core.word.domain.WordDomain;
import java.util.List;
/** /**
* 词条 * 词条
* *
...@@ -18,12 +20,27 @@ public class WordQuery extends Query { ...@@ -18,12 +20,27 @@ public class WordQuery extends Query {
private String keyword; private String keyword;
private List<String> keywordList;
@Override @Override
public QueryCriteria toCriteria() { public QueryCriteria toCriteria() {
QueryCriteria queryCriteria = new QueryCriteria(WordDomain.class); QueryCriteria queryCriteria = new QueryCriteria(WordDomain.class);
Example.Criteria criteria = queryCriteria.createCriteria(); Example.Criteria criteria = queryCriteria.createCriteria();
if (valid(keyword)) { 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 写查询逻辑 //todo 写查询逻辑
return queryCriteria; return queryCriteria;
......
...@@ -14,15 +14,23 @@ ...@@ -14,15 +14,23 @@
package com.dookay.cihai.wechat.controller; 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.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.domain.ThemeDomain;
import com.dookay.cihai.core.theme.query.ThemeQuery; import com.dookay.cihai.core.theme.query.ThemeQuery;
import com.dookay.cihai.core.theme.service.IThemeService; 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.CustomDictionaryQuery;
import com.dookay.cihai.core.word.query.WordQuery;
import com.dookay.cihai.core.word.service.ICustomDictionaryService; import com.dookay.cihai.core.word.service.ICustomDictionaryService;
import com.dookay.cihai.core.word.service.IWordService; 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.controller.BaseController;
import com.dookay.coral.common.web.response.JsonResult; import com.dookay.coral.common.web.response.JsonResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -30,6 +38,9 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -30,6 +38,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author 石磊 * @author 石磊
* @date 2017/12/6 * @date 2017/12/6
...@@ -49,6 +60,9 @@ public class HomeController extends BaseController { ...@@ -49,6 +60,9 @@ public class HomeController extends BaseController {
@Autowired @Autowired
private AipWordUtilBean aipWordUtilBean; private AipWordUtilBean aipWordUtilBean;
@Autowired
private AipImageClassifyClient aipImageClassifyClient;
/** /**
* @author 石磊 * @author 石磊
* @date 2017/12/6 * @date 2017/12/6
...@@ -68,25 +82,72 @@ public class HomeController extends BaseController { ...@@ -68,25 +82,72 @@ public class HomeController extends BaseController {
@RequestMapping(value = "/home/search", method = RequestMethod.GET) @RequestMapping(value = "/home/search", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public JsonResult search(String keyword) { public JsonResult search(String keyword) {
System.out.println("进入搜索"); System.out.println("进入搜索:" + keyword);
if (StringUtils.isBlank(keyword)) {
return errorResult("搜索内容不能为空");
}
String result = null; String result = null;
CustomDictionaryQuery query1 = new CustomDictionaryQuery(); boolean inDic = false;
query1.setWord(keyword); List<CustomDictionaryDomain> dictionaryDomainList = customDictionaryService.getList(new CustomDictionaryQuery());
for (CustomDictionaryDomain dic : dictionaryDomainList) {
if (keyword.contains(dic.getWord())) {
result = dic.getWord();
inDic = true;
}
}
try { try {
int count = customDictionaryService.count(query1); if (!inDic) {
if (count > 0) {
result = keyword;
} else {
result = aipWordUtilBean.extractQueryKeyword(keyword); result = aipWordUtilBean.extractQueryKeyword(keyword);
} }
ThemeQuery query = new ThemeQuery(); ThemeQuery query = new ThemeQuery();
query.setKeyword(result); query.setKeyword(result);
ThemeDomain themeDomain = themeService.getFirst(query); 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); System.out.println(themeDomain);
return successResult("success", "/theme/detail/" + themeDomain.getId()); return successResult("success", "/theme/detail/" + themeDomain.getId());
} catch (Exception ex) { } 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; ...@@ -23,6 +23,7 @@ import com.dookay.cihai.core.theme.domain.ThemeDomain;
import com.dookay.cihai.core.theme.service.IThemeService; import com.dookay.cihai.core.theme.service.IThemeService;
import com.dookay.coral.common.web.controller.BaseController; import com.dookay.coral.common.web.controller.BaseController;
import com.dookay.coral.common.web.response.JsonResult; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -57,8 +58,16 @@ public class ThemeController extends BaseController { ...@@ -57,8 +58,16 @@ public class ThemeController extends BaseController {
@RequestMapping(value = "/detail/{id}", method = RequestMethod.GET) @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
public ModelAndView detail(@PathVariable Long id) { public ModelAndView detail(@PathVariable Long id) {
ThemeDomain themeDomain = themeService.get(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"); ModelAndView mv = new ModelAndView("portal/theme/detail");
mv.addObject("theme", themeDomain); mv.addObject("theme", themeDomain);
mv.addObject("wordCounts", wordCounts);
return mv; return mv;
} }
...@@ -73,6 +82,7 @@ public class ThemeController extends BaseController { ...@@ -73,6 +82,7 @@ public class ThemeController extends BaseController {
public JsonResult related(@PathVariable Long id) { public JsonResult related(@PathVariable Long id) {
ThemeDomain themeDomain = themeService.get(id); ThemeDomain themeDomain = themeService.get(id);
String document = themeDomain.getIntroduce(); String document = themeDomain.getIntroduce();
document = HtmlUtils.removeTag(document);
List<WordCount> wordCounts = aipWordUtilBean.extractNounWordsWithCount(document); List<WordCount> wordCounts = aipWordUtilBean.extractNounWordsWithCount(document);
List<WordCount> collect = wordCounts.stream().sorted(Comparator.comparingDouble(l -> Math.random())).limit(8).collect(Collectors.toList()); List<WordCount> collect = wordCounts.stream().sorted(Comparator.comparingDouble(l -> Math.random())).limit(8).collect(Collectors.toList());
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
...@@ -92,6 +102,7 @@ public class ThemeController extends BaseController { ...@@ -92,6 +102,7 @@ public class ThemeController extends BaseController {
public JsonResult map(@PathVariable Long id) { public JsonResult map(@PathVariable Long id) {
ThemeDomain themeDomain = themeService.get(id); ThemeDomain themeDomain = themeService.get(id);
String document = themeDomain.getIntroduce(); String document = themeDomain.getIntroduce();
document = HtmlUtils.removeTag(document);
List<String> keywords = aipWordUtilBean.extractKeyWords(themeDomain.getTitle(), document, 15); 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<WordSequence> wordSequences = keywords.stream().map(l -> new WordSequence(keywords.indexOf(l), l)).collect(Collectors.toList());
List<WordRelation> wordRelations = aipWordUtilBean.generateWordsMap(keywords); List<WordRelation> wordRelations = aipWordUtilBean.generateWordsMap(keywords);
......
...@@ -57,7 +57,6 @@ ...@@ -57,7 +57,6 @@
wx.stopRecord({ wx.stopRecord({
success: function (res) { success: function (res) {
myApp.dialog.preloader(); myApp.dialog.preloader();
var localId = res.localId; var localId = res.localId;
wx.translateVoice({ wx.translateVoice({
localId: localId, // 需要识别的音频的本地Id,由录音相关接口获得 localId: localId, // 需要识别的音频的本地Id,由录音相关接口获得
...@@ -105,9 +104,19 @@ ...@@ -105,9 +104,19 @@
localId: localIds[0], // 图片的localID localId: localIds[0], // 图片的localID
success: function (res) { success: function (res) {
myApp.dialog.preloader();
var localData = res.localData; // localData是图片的base64数据,可以用img标签显示 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);
}
})
} }
}); });
......
...@@ -290,7 +290,7 @@ ...@@ -290,7 +290,7 @@
<div class="navbar"> <div class="navbar">
<div class="navbar-inner"> <div class="navbar-inner">
<div class="left"> <div class="left">
<a class="link back" href="/"> <a class="link back js-jump-page" href="/">
<i class="iconfont icon-jiantou"></i> <i class="iconfont icon-jiantou"></i>
<span class="ios-only">返回</span> <span class="ios-only">返回</span>
</a> </a>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!