Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
石磊
/
cihai
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a9604b58
authored
Dec 07, 2017
by
侯昆
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
主题页 动态关联
1 parent
e20155b2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
55 deletions
serverside/cihai-core/src/main/java/com/dookay/cihai/core/aip/AipWordUtilBean.java
serverside/cihai-core/src/main/java/com/dookay/cihai/core/aip/model/WordCount.java
serverside/cihai-wechat/src/main/java/com/dookay/cihai/wechat/controller/ThemeController.java
serverside/cihai-wechat/src/main/webapp/WEB-INF/jsp/portal/theme/detail.jsp
serverside/cihai-core/src/main/java/com/dookay/cihai/core/aip/AipWordUtilBean.java
View file @
a9604b5
...
@@ -22,6 +22,7 @@ import com.dookay.cihai.core.aip.consts.LexerNeConst;
...
@@ -22,6 +22,7 @@ import com.dookay.cihai.core.aip.consts.LexerNeConst;
import
com.dookay.cihai.core.aip.consts.LexerPosConst
;
import
com.dookay.cihai.core.aip.consts.LexerPosConst
;
import
com.dookay.cihai.core.aip.model.DepParserItem
;
import
com.dookay.cihai.core.aip.model.DepParserItem
;
import
com.dookay.cihai.core.aip.model.LexerItem
;
import
com.dookay.cihai.core.aip.model.LexerItem
;
import
com.dookay.cihai.core.aip.model.WordCount
;
import
com.dookay.cihai.core.aip.model.WordRelation
;
import
com.dookay.cihai.core.aip.model.WordRelation
;
import
com.dookay.coral.common.core.exception.ServiceException
;
import
com.dookay.coral.common.core.exception.ServiceException
;
import
com.dookay.coral.common.core.utils.lang.CollectionUtils
;
import
com.dookay.coral.common.core.utils.lang.CollectionUtils
;
...
@@ -142,8 +143,9 @@ public final class AipWordUtilBean {
...
@@ -142,8 +143,9 @@ public final class AipWordUtilBean {
* @author houkun
* @author houkun
* @date 2017/12/6
* @date 2017/12/6
*/
*/
public
Map
<
String
,
Long
>
extractNounWordsWithCount
(
String
document
)
throws
JSONException
{
public
List
<
WordCount
>
extractNounWordsWithCount
(
String
document
)
throws
JSONException
{
List
<
LexerItem
>
lexerItems
=
getLexerItems
(
document
);
List
<
LexerItem
>
lexerItems
=
getLexerItems
(
document
);
ArrayList
<
WordCount
>
wordCounts
=
new
ArrayList
<>();
Map
<
String
,
Long
>
itemCount
=
lexerItems
.
stream
()
Map
<
String
,
Long
>
itemCount
=
lexerItems
.
stream
()
.
filter
(
l
->
LexerPosConst
.
inThis
(
l
.
getPos
())
.
filter
(
l
->
LexerPosConst
.
inThis
(
l
.
getPos
())
||
LexerNeConst
.
inThis
(
l
.
getNe
()))
||
LexerNeConst
.
inThis
(
l
.
getNe
()))
...
@@ -151,7 +153,16 @@ public final class AipWordUtilBean {
...
@@ -151,7 +153,16 @@ public final class AipWordUtilBean {
LexerItem:
:
getItem
,
LexerItem:
:
getItem
,
Collectors
.
counting
()
Collectors
.
counting
()
));
));
return
itemCount
;
int
i
=
0
;
for
(
Map
.
Entry
<
String
,
Long
>
entry
:
itemCount
.
entrySet
())
{
WordCount
wordCount
=
new
WordCount
();
wordCount
.
setId
(
i
);
wordCount
.
setLabel
(
entry
.
getKey
());
wordCount
.
setValue
(
entry
.
getValue
());
wordCounts
.
add
(
wordCount
);
i
++;
}
return
wordCounts
;
}
}
/**
/**
...
...
serverside/cihai-core/src/main/java/com/dookay/cihai/core/aip/model/WordCount.java
0 → 100644
View file @
a9604b5
package
com
.
dookay
.
cihai
.
core
.
aip
.
model
;
/*****************************************
* *
* @dookay.com Internet make it happen *
* ----------- ----------------------- *
* dddd ddddd Internet make it happen *
* o o o Internet make it happen *
* k k k Internet make it happen *
* a a a Internet make it happen *
* yyyy yyyyy Internet make it happen *
* ----------- ----------------------- *
* @dookay.com Internet make it happen *
* *
****************************************/
import
lombok.Data
;
/**
* 关键词次数
*
* @author houkun
* @date 2017/12/7
*/
@Data
public
class
WordCount
{
private
int
id
;
private
String
label
;
private
long
value
;
}
serverside/cihai-wechat/src/main/java/com/dookay/cihai/wechat/controller/ThemeController.java
View file @
a9604b5
...
@@ -16,6 +16,7 @@ package com.dookay.cihai.wechat.controller;
...
@@ -16,6 +16,7 @@ package com.dookay.cihai.wechat.controller;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.dookay.cihai.core.aip.AipWordUtilBean
;
import
com.dookay.cihai.core.aip.AipWordUtilBean
;
import
com.dookay.cihai.core.aip.model.WordCount
;
import
com.dookay.cihai.core.aip.model.WordRelation
;
import
com.dookay.cihai.core.aip.model.WordRelation
;
import
com.dookay.cihai.core.aip.model.WordSequence
;
import
com.dookay.cihai.core.aip.model.WordSequence
;
import
com.dookay.cihai.core.theme.domain.ThemeDomain
;
import
com.dookay.cihai.core.theme.domain.ThemeDomain
;
...
@@ -30,8 +31,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
...
@@ -30,8 +31,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.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -71,8 +73,12 @@ public class ThemeController extends BaseController {
...
@@ -71,8 +73,12 @@ 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
();
Map
<
String
,
Long
>
wordCountMap
=
aipWordUtilBean
.
extractNounWordsWithCount
(
document
);
List
<
WordCount
>
wordCounts
=
aipWordUtilBean
.
extractNounWordsWithCount
(
document
);
return
successResult
(
"关联词出现次数"
,
wordCountMap
);
List
<
WordCount
>
collect
=
wordCounts
.
stream
().
sorted
(
Comparator
.
comparingDouble
(
l
->
Math
.
random
())).
limit
(
8
).
collect
(
Collectors
.
toList
());
JSONObject
result
=
new
JSONObject
();
result
.
put
(
"nodes"
,
collect
);
result
.
put
(
"edges"
,
new
ArrayList
<>(
0
));
return
successResult
(
"关联词出现次数"
,
result
);
}
}
/**
/**
...
...
serverside/cihai-wechat/src/main/webapp/WEB-INF/jsp/portal/theme/detail.jsp
View file @
a9604b5
...
@@ -339,8 +339,32 @@
...
@@ -339,8 +339,32 @@
<script src="${ctx}/static/js/special.js"></script>
<script src="${ctx}/static/js/special.js"></script>
<script>
<script>
function loadMap() {
jQuery.get(location.href + "/map", {}, function (data) {
if (data.code == "OK") {
mapData = data.data;
relationPic('relation-pic', mapData);
} else {
console.log("请求数据失败");
}
});
}
function loadRelated() {
jQuery.get(location.href + "/related", {}, function (data) {
if (data.code == "OK") {
mapData = data.data;
relationPic('word-analysis', relateData);
} else {
console.log("请求数据失败");
}
});
}
function relationPic(id, data) {
function relationPic(id, data) {
return new vis.Network(document.getElementById(id),
relationPic
Data, {
return new vis.Network(document.getElementById(id),
map
Data, {
nodes: {
nodes: {
shape: 'dot',
shape: 'dot',
borderWidth: 3,
borderWidth: 3,
...
@@ -358,57 +382,16 @@
...
@@ -358,57 +382,16 @@
}
}
});
});
};
};
var relationPicData = {
nodes: [{
id: 1,
label: 'Node 1',
value: 15
},
{
id: 2,
label: 'Node 2',
value: 25
},
{
id: 3,
label: 'Node 3',
value: 50
},
{
id: 4,
label: 'Node 4',
value: 30
},
{
id: 5,
label: 'Node 5',
value: 8
}
],
edges: [{
from: 1,
to: 3
},
{
from: 1,
to: 2
},
{
from: 2,
to: 4
},
{
from: 2,
to: 5
}
]
};
relationPic('relation-pic', relationPicData);
relationPicData.edges = [];
var wordAnalysis = relationPic('word-analysis', relationPicData);
$('.js-refresh').click(function () {
$('.js-refresh').click(function () {
wordAnalysis.destroy();
wordAnalysis.destroy();
wordAnalysis = relationPic('word-analysis', relationPicData
);
loadRelated(
);
});
});
var mapData = {};
var relateData = {};
relationPic('relation-pic', mapData);
var wordAnalysis = relationPic('word-analysis', mapData);
loadMap();
loadRelated();
</script>
</script>
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment