|
|
@ -1,6 +1,15 @@
|
|
|
|
var tsvPath
|
|
|
|
var tsvPath
|
|
|
|
var stopwords = []
|
|
|
|
var stopwords = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const init = () => {
|
|
|
|
|
|
|
|
$(window).on('mousemove', function (e) {
|
|
|
|
|
|
|
|
$('#nodeTitle').css({
|
|
|
|
|
|
|
|
left: e.pageX,
|
|
|
|
|
|
|
|
top: e.pageY
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function clearStopWord() {
|
|
|
|
function clearStopWord() {
|
|
|
|
stopwords = []
|
|
|
|
stopwords = []
|
|
|
|
$('#sweContainer').html('')
|
|
|
|
$('#sweContainer').html('')
|
|
|
@ -86,22 +95,34 @@ function submit() {
|
|
|
|
|
|
|
|
|
|
|
|
function buildSentetree() {
|
|
|
|
function buildSentetree() {
|
|
|
|
console.log("Build.")
|
|
|
|
console.log("Build.")
|
|
|
|
var model;
|
|
|
|
let model;
|
|
|
|
var tree;
|
|
|
|
let tree;
|
|
|
|
var data;
|
|
|
|
let data;
|
|
|
|
const graph = d3.tsv(tsvPath, buildTree);
|
|
|
|
const graph = d3.json(tsvPath, buildTree);
|
|
|
|
|
|
|
|
|
|
|
|
function buildTree(error, rawdata) {
|
|
|
|
function buildTree(error, rawdata) {
|
|
|
|
|
|
|
|
console.log(rawdata)
|
|
|
|
const data = rawdata.map(d => Object.assign({}, d, { count: +d.count }));
|
|
|
|
const data = rawdata.map(d => Object.assign({}, d, { count: +d.count }));
|
|
|
|
|
|
|
|
console.log({ data })
|
|
|
|
|
|
|
|
let minRatio = $('#minRatio').val()
|
|
|
|
|
|
|
|
let maxRatio = $('#maxRatio').val()
|
|
|
|
|
|
|
|
console.log({ minRatio, maxRatio })
|
|
|
|
model = new SentenTree.SentenTreeBuilder()
|
|
|
|
model = new SentenTree.SentenTreeBuilder()
|
|
|
|
.tokenize(SentenTree.tokenizer.tokenizeBySpace)
|
|
|
|
.tokenize(SentenTree.tokenizer.tokenizeBySpace)
|
|
|
|
.transformToken(token => (/score(d|s)?/.test(token) ? 'score' : token))
|
|
|
|
.transformToken(token => (/score(d|s)?/.test(token) ? 'score' : token))
|
|
|
|
.buildModel(data, { maxSupportRatio: 1 });
|
|
|
|
.buildModel(data, { maxSupportRatio: maxRatio, minSupportRatio: minRatio });
|
|
|
|
tree = new SentenTree.SentenTreeVis('#vis', {
|
|
|
|
tree = new SentenTree.SentenTreeVis('#vis', {
|
|
|
|
fontSize: [15, 40],
|
|
|
|
fontSize: [15, 40],
|
|
|
|
gapBetweenGraph: 10
|
|
|
|
gapBetweenGraph: 10
|
|
|
|
});
|
|
|
|
});
|
|
|
|
tree.data(model.getRenderedGraphs(2))
|
|
|
|
tree.data(model.getRenderedGraphs(2))
|
|
|
|
|
|
|
|
.on('nodeMouseenter', (node) => {
|
|
|
|
|
|
|
|
$('#nodeTitle').removeClass('hidden')
|
|
|
|
|
|
|
|
$('#nodeTitleContent').html(node.data.topEntries.map((n) => data[n.id].rawtxt).join('<br>'))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.on('nodeMouseleave', () => {
|
|
|
|
|
|
|
|
$('#nodeTitle').addClass('hidden')
|
|
|
|
|
|
|
|
})
|
|
|
|
new ResizeSensor(jQuery('#d3kitRoot'), function () {
|
|
|
|
new ResizeSensor(jQuery('#d3kitRoot'), function () {
|
|
|
|
var scale, origin;
|
|
|
|
var scale, origin;
|
|
|
|
scale = Math.min(2, ($('#graph').outerWidth()) / ($('#d3kitRoot').outerWidth() + 60))
|
|
|
|
scale = Math.min(2, ($('#graph').outerWidth()) / ($('#d3kitRoot').outerWidth() + 60))
|
|
|
@ -133,3 +154,5 @@ function countWords() {
|
|
|
|
console.log(wordCount)
|
|
|
|
console.log(wordCount)
|
|
|
|
$("#wordcount").html('字數:' + wordCount)
|
|
|
|
$("#wordcount").html('字數:' + wordCount)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init()
|