|
|
@ -1,33 +1,6 @@
|
|
|
|
var tsvPath
|
|
|
|
var tsvPath
|
|
|
|
var stopwords = []
|
|
|
|
var stopwords = []
|
|
|
|
|
|
|
|
|
|
|
|
const init = () => {
|
|
|
|
|
|
|
|
$(window).on('mousemove', (e) => {
|
|
|
|
|
|
|
|
$('#nodeTitle').css({
|
|
|
|
|
|
|
|
left: e.pageX,
|
|
|
|
|
|
|
|
top: e.pageY
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
$('#minRatioLabel').on('mouseenter', () => {
|
|
|
|
|
|
|
|
$('#nodeTitle').removeClass('hidden')
|
|
|
|
|
|
|
|
$('#nodeTitleContent').html('兩個相鄰單詞之間出現頻率比值的最小值,小於該值不會被演算法選擇')
|
|
|
|
|
|
|
|
}).on('mouseleave', () => {
|
|
|
|
|
|
|
|
$('#nodeTitle').toggleClass('hidden')
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
$('#maxRatioLabel').on('mouseenter', () => {
|
|
|
|
|
|
|
|
$('#nodeTitle').removeClass('hidden')
|
|
|
|
|
|
|
|
$('#nodeTitleContent').html('兩個相鄰單詞之間出現頻率比值的最大值,大於該值不會被演算法選擇')
|
|
|
|
|
|
|
|
}).on('mouseleave', () => {
|
|
|
|
|
|
|
|
$('#nodeTitle').toggleClass('hidden')
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
$('#wordcount').on('mouseenter', () => {
|
|
|
|
|
|
|
|
$('#nodeTitle').removeClass('hidden')
|
|
|
|
|
|
|
|
$('#nodeTitleContent').html('僅計算中文字的字數')
|
|
|
|
|
|
|
|
}).on('mouseleave', () => {
|
|
|
|
|
|
|
|
$('#nodeTitle').toggleClass('hidden')
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function clearStopWord() {
|
|
|
|
function clearStopWord() {
|
|
|
|
stopwords = []
|
|
|
|
stopwords = []
|
|
|
|
$('#sweContainer').html('')
|
|
|
|
$('#sweContainer').html('')
|
|
|
@ -113,41 +86,22 @@ function submit() {
|
|
|
|
|
|
|
|
|
|
|
|
function buildSentetree() {
|
|
|
|
function buildSentetree() {
|
|
|
|
console.log("Build.")
|
|
|
|
console.log("Build.")
|
|
|
|
let model;
|
|
|
|
var model;
|
|
|
|
let tree;
|
|
|
|
var tree;
|
|
|
|
let data;
|
|
|
|
var data;
|
|
|
|
const graph = d3.json(tsvPath, buildTree);
|
|
|
|
const graph = d3.tsv(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: maxRatio, minSupportRatio: minRatio });
|
|
|
|
.buildModel(data, { maxSupportRatio: 1 });
|
|
|
|
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) => {
|
|
|
|
|
|
|
|
console.log(node)
|
|
|
|
|
|
|
|
$('#nodeTitle').removeClass('hidden')
|
|
|
|
|
|
|
|
$('#nodeTitleContent').html('<ul>' + node.data.topEntries.map((n) => "<li>" + data[n.id].rawtxt + "</li>").join('') + "</ul>")
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.on('nodeMouseleave', () => {
|
|
|
|
|
|
|
|
$('#nodeTitle').addClass('hidden')
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.on('linkMouseenter', (node) => {
|
|
|
|
|
|
|
|
$('#nodeTitle').removeClass('hidden')
|
|
|
|
|
|
|
|
$('#nodeTitleContent').html('出現次數:' + (node.freq / 10))
|
|
|
|
|
|
|
|
}).on('linkMouseleave', () => {
|
|
|
|
|
|
|
|
$('#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))
|
|
|
@ -172,12 +126,3 @@ function switchMessageBox() {
|
|
|
|
$('#toggleTextBox').html('隱藏文字輸入區')
|
|
|
|
$('#toggleTextBox').html('隱藏文字輸入區')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function countWords() {
|
|
|
|
|
|
|
|
text = $("#rawTextBox").val()
|
|
|
|
|
|
|
|
let wordCount = text.split(new RegExp("[\u4e00-\u9fa5]")).length - 1
|
|
|
|
|
|
|
|
console.log(wordCount)
|
|
|
|
|
|
|
|
$("#wordcount").html('字數:' + wordCount)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init()
|
|
|
|
|