|
|
|
@ -71,6 +71,11 @@ function init() {
|
|
|
|
|
hideStopWordEditor()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
$('#idfEditorLayer').click(function(e) {
|
|
|
|
|
if ($('#idfEditorLayer').is(e.target)) {
|
|
|
|
|
hideIdfEditor()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearStopWord() {
|
|
|
|
@ -102,6 +107,23 @@ function addStopWord() {
|
|
|
|
|
$('#newStopWord').val('')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scrollIdfList() {
|
|
|
|
|
let targetWord = $('#idfTarget').val()
|
|
|
|
|
let wordList = $("#ieContainer").find("tr").slice(1).map((_, a) => { return $($(a).find("td")[0]).html() }).get()
|
|
|
|
|
console.log({ "targetWord": targetWord, 'list': wordList })
|
|
|
|
|
if (targetWord != '') {
|
|
|
|
|
if (wordList.indexOf(targetWord) >= 0) {
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
wordList.push(targetWord)
|
|
|
|
|
$('#ieContainer').find('tbody').append($('<tr>').attr('class', 'w3-display-container').append($('<td>').attr('style', 'vertical-align: middle;').append(targetWord)).append($('<td>').attr('class', 'w3-right-align').attr('style', 'vertical-align: middle;').append($('<input>').attr('type', 'number').val(Object.keys(idfTable).indexOf(targetWord) < 0 ? 0 : idfTable[targetWord]))))
|
|
|
|
|
}
|
|
|
|
|
console.log($($('#ieContainer').children('tbody').find('tr')[[wordList.indexOf(targetWord)]]).position())
|
|
|
|
|
$("#ieTableContainer").scrollTop($($('#ieContainer').children('tbody').find('tr')[[wordList.indexOf(targetWord)]]).position().top - 50)
|
|
|
|
|
}
|
|
|
|
|
$('#newStopWord').val('')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showStopwordEditor() {
|
|
|
|
|
$(window).unbind('keydown')
|
|
|
|
|
$(window).keydown(function(event) {
|
|
|
|
@ -111,7 +133,7 @@ function showStopwordEditor() {
|
|
|
|
|
})
|
|
|
|
|
$('#sweContainer').empty()
|
|
|
|
|
for (word of stopwords) {
|
|
|
|
|
$('#sweContainer').append($('<li>').attr('class', 'w3-display-container').append($('<span>').append(word)).append($('<span>').attr('class', 'w3-button w3-hover-red w3-transparent w3-display-right').click(function(e) {
|
|
|
|
|
$('#sweContainer').append($('<li>').append($('<span>').append(word)).append($('<span>').attr('class', 'w3-button w3-hover-red w3-transparent w3-display-right').click(function(e) {
|
|
|
|
|
var index = $(this).parent().index()
|
|
|
|
|
console.log(stopwords[index])
|
|
|
|
|
stopwords.splice(index, 1)
|
|
|
|
@ -122,6 +144,85 @@ function showStopwordEditor() {
|
|
|
|
|
$('#stopWordEditorLayer').removeClass('hidden')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showIdfEditor() {
|
|
|
|
|
$(window).unbind('keydown')
|
|
|
|
|
$(window).keydown(function(event) {
|
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
|
scrollIdfList()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
$('#ieContainer').empty().append(
|
|
|
|
|
$('<thead>').append($('<tr>')
|
|
|
|
|
.append($('<th>')
|
|
|
|
|
.attr('style', 'position: sticky; top: 0; background: white;')
|
|
|
|
|
.append('單詞'))
|
|
|
|
|
.append($('<th>'))
|
|
|
|
|
.append($('<th>').attr('class', 'w3-right-align')
|
|
|
|
|
.attr('style', 'position: sticky; top: 0; background: white;')
|
|
|
|
|
.append('單詞頻率')
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.append($('<tbody>'))
|
|
|
|
|
for (word of Object.entries(idfTable).sort((a, b) => { return (b[1] - a[1]) }).map((a) => { return a[0] }).slice(0, 1000)) {
|
|
|
|
|
$('#ieContainer').find('tbody')
|
|
|
|
|
.append($('<tr>')
|
|
|
|
|
.attr('class', 'w3-display-container')
|
|
|
|
|
.append($('<td>')
|
|
|
|
|
.attr('style', 'vertical-align: middle;')
|
|
|
|
|
.append(word))
|
|
|
|
|
.append($('<td>')
|
|
|
|
|
.attr('class', 'w3-right-align')
|
|
|
|
|
.append($('<button>')
|
|
|
|
|
.attr('class', 'general-button')
|
|
|
|
|
.html('設為最小')
|
|
|
|
|
.click(function() {
|
|
|
|
|
$(this)
|
|
|
|
|
.parent()
|
|
|
|
|
.parent()
|
|
|
|
|
.find('input').val(0)
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.append($('<button>')
|
|
|
|
|
.attr('class', 'general-button')
|
|
|
|
|
.html('設為最大')
|
|
|
|
|
.click(function() {
|
|
|
|
|
$(this)
|
|
|
|
|
.parent()
|
|
|
|
|
.parent()
|
|
|
|
|
.find('input').val(Object.values(idfTableOrig).reduce((a, b) => {
|
|
|
|
|
return a > b ? a : b
|
|
|
|
|
}))
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.append($('<button>')
|
|
|
|
|
.attr('class', 'general-button')
|
|
|
|
|
.html('重設')
|
|
|
|
|
.click(function() {
|
|
|
|
|
var _word = $($(this)
|
|
|
|
|
.parent()
|
|
|
|
|
.parent()
|
|
|
|
|
.find('td')[0]).html()
|
|
|
|
|
$(this)
|
|
|
|
|
.parent()
|
|
|
|
|
.parent()
|
|
|
|
|
.find('input').val(idfTableOrig[_word])
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.append($('<td>')
|
|
|
|
|
.attr('class', 'w3-right-align')
|
|
|
|
|
.attr('style', 'vertical-align: middle;')
|
|
|
|
|
.append($('<input>')
|
|
|
|
|
.attr('type', 'number')
|
|
|
|
|
.val(idfTable[word])
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
$('#idfEditorLayer').removeClass('hidden')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideStopWordEditor() {
|
|
|
|
|
$(window).unbind('keydown')
|
|
|
|
|
$(window).keydown(function(event) {
|
|
|
|
@ -133,11 +234,40 @@ function hideStopWordEditor() {
|
|
|
|
|
$('#stopWordEditorLayer').addClass('hidden')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideIdfEditor() {
|
|
|
|
|
$(window).unbind('keydown')
|
|
|
|
|
$(window).keydown(function(event) {
|
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
sendRequest()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
$('#idfEditorLayer').addClass('hidden')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateIdfTable() {
|
|
|
|
|
let wordList = $("#ieContainer").find("tr").slice(1).map((_, a) => {
|
|
|
|
|
return [
|
|
|
|
|
[$($(a).find("td")[0]).html(), $($(a).find("td")[1]).find('input').val()]
|
|
|
|
|
]
|
|
|
|
|
}).get()
|
|
|
|
|
console.log(wordList)
|
|
|
|
|
for (p of wordList) {
|
|
|
|
|
idfTable[p[0]] = p[1]
|
|
|
|
|
}
|
|
|
|
|
console.log(idfTable)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function downloadStopWord() {
|
|
|
|
|
stopWordString = stopwords.join('\n')
|
|
|
|
|
download(stopWordString, 'stopwords.txt', 'text/plain')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function downloadIdfTable() {
|
|
|
|
|
let idfTableJson = JSON.stringify(idfTable, null, "\t")
|
|
|
|
|
download(idfTableJson, 'idfTable.json', 'text/plain')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function hidePopup() {
|
|
|
|
|
$('#infoWindowLayer').toggleClass('hidden')
|
|
|
|
|