我改了什麼?

dev/addPush
Zovjsra 4 years ago
parent 8237ed570a
commit 24f92cd6f0

@ -67,7 +67,7 @@ def ptt_push():
@app.route('/ptt_push/init', methods=['POST']) @app.route('/ptt_push/init', methods=['POST'])
def pttPushInit(): def pttPushInit():
author = next(pttPush.getMostFrequentAuthor()) author = 'yuetsu'
pushes = pttPush.findAuthorPush( pushes = pttPush.findAuthorPush(
author=[author], stopwords=pttPush.defaultStopWords) author=[author], stopwords=pttPush.defaultStopWords)
result: dict = { result: dict = {

@ -1,6 +1,7 @@
var idfTable var idfTable
var idfTableOrig var idfTableOrig
var idfBase = 1000 var idfBase = 1000
var mode = 0
$.ajax({ $.ajax({
url: '/resource/idfTable.json', url: '/resource/idfTable.json',
async: false, async: false,

@ -76,6 +76,7 @@ function init() {
hideIdfEditor() hideIdfEditor()
} }
}) })
changeMode(0)
} }
function clearStopWord() { function clearStopWord() {
@ -107,6 +108,19 @@ function addStopWord() {
$('#newStopWord').val('') $('#newStopWord').val('')
} }
function changeMode(_mode) {
for (i = 0; i < 4; i++) {
if (i == _mode) {
$('#modeSelector button').eq(i).css("color", "#aaa")
} else {
$('#modeSelector button').eq(i).css("color", "#000")
}
}
mode = _mode
destroyCurrentGraph()
buildSentetree()
}
function scrollIdfList() { function scrollIdfList() {
let targetWord = $('#idfTarget').val() let targetWord = $('#idfTarget').val()
let wordList = $("#ieContainer").find("tr").slice(1).map((_, a) => { return $($(a).find("td")[0]).html() }).get() let wordList = $("#ieContainer").find("tr").slice(1).map((_, a) => { return $($(a).find("td")[0]).html() }).get()
@ -386,7 +400,8 @@ function buildSentetree() {
gapBetweenGraph: 10 gapBetweenGraph: 10
}); });
console.log(tree) console.log(tree)
tree.data(model.getRenderedGraphs(2)) let nGraph = globKeyword == "" ? 5 : 2
tree.data(model.getRenderedGraphs(nGraph))
.on('nodeClick', node => { .on('nodeClick', node => {
if ('mergedData' in node.data) { if ('mergedData' in node.data) {
seqList = node.data.mergedData.map((d) => { seqList = node.data.mergedData.map((d) => {

@ -1,6 +1,7 @@
init() init()
var tsvPath = '' var tsvPath = ''
var titlePath = '' var titlePath = ''
var tsvString
var defaultStartDate var defaultStartDate
var defaultEndDate var defaultEndDate
var totalPosts var totalPosts
@ -111,6 +112,20 @@ function addStopWord() {
$('#newStopWord').val('') $('#newStopWord').val('')
} }
function changeMode(_mode) {
for (i = 0; i < 4; i++) {
if (i == _mode) {
$('#modeSelector button').eq(i).css("color", "#aaa")
} else {
$('#modeSelector button').eq(i).css("color", "#000")
}
}
mode = _mode
destroyCurrentGraph()
d3.select('#graph').append('div').attr('id', 'vis')
buildSentetree(tsvString)
}
function showIdfEditor() { function showIdfEditor() {
$(window).unbind('keydown') $(window).unbind('keydown')
$(window).keydown(function(event) { $(window).keydown(function(event) {
@ -190,6 +205,17 @@ function showIdfEditor() {
$('#idfEditorLayer').removeClass('hidden') $('#idfEditorLayer').removeClass('hidden')
} }
function hideIdfEditor() {
$(window).unbind('keydown')
$(window).keydown(function(event) {
if (event.keyCode == 13) {
event.preventDefault()
sendRequest()
}
})
$('#idfEditorLayer').addClass('hidden')
}
function showStopwordEditor() { function showStopwordEditor() {
console.log(stopwords) console.log(stopwords)
$(window).unbind('keydown') $(window).unbind('keydown')
@ -296,7 +322,7 @@ function sendRequest() {
function changeGraph(data) { function changeGraph(data) {
console.log(data) console.log(data)
let tsvString = data.tsv tsvString = data.tsv
let json = JSON.parse(data.json) let json = JSON.parse(data.json)
destroyCurrentGraph() destroyCurrentGraph()
d3.select('#graph').append('div').attr('id', 'vis') d3.select('#graph').append('div').attr('id', 'vis')

@ -19112,6 +19112,7 @@
var word = null; var word = null;
var count = 0; var count = 0;
var len = seq.words.length; var len = seq.words.length;
var root = seq.newWord ? seq.newWord.word : undefined
var _loop = function _loop(s) { var _loop = function _loop(s) {
var fdist = {}; var fdist = {};
@ -19133,6 +19134,8 @@
} }
}); });
console.log(seq)
var maxw = null; var maxw = null;
var maxc = 0; var maxc = 0;
@ -19143,20 +19146,65 @@
words.forEach(function(w) { words.forEach(function(w) {
var value = fdist[w]; var value = fdist[w];
//if (value < maxSupport && (value / Math.max(idfTable[itemset[w]], idfBase)) * idfBase > maxc) { var distRatio = 0.1
//if (value < maxSupport && value > maxc && (stopwords.indexOf(itemset[w]) < 0 || isNotRoot)) { if (root) {
if (value < maxSupport && value > maxc && stopwords.indexOf(itemset[w]) < 0) { var dist = Math.abs(words.indexOf(w) - words.indexOf(root))
maxw = +w; }
//maxc = (value / Math.max(idfTable[itemset[w]], idfBase)) * idfBase switch (mode) {
maxc = value case 0:
if (!root) {
if (value < maxSupport && value > maxc && stopwords.indexOf(itemset[w]) < 0) {
maxw = +w
maxc = value
}
} else {
if (value < maxSupport && (value * Math.pow(distRatio, dist - 1)) > maxc && stopwords.indexOf(itemset[w]) < 0 && dist == 1) {
maxw = +w
maxc = value
console.log(maxc)
}
}
break
case 1:
if (value < maxSupport && (value / Math.max(idfTable[itemset[w]], idfBase)) * idfBase > maxc) {
//if (value < maxSupport && value > maxc && (stopwords.indexOf(itemset[w]) < 0 || isNotRoot)) {
//if (value < maxSupport && value > maxc && stopwords.indexOf(itemset[w]) < 0) {
maxw = +w;
maxc = (value / Math.max(idfTable[itemset[w]], idfBase)) * idfBase
//maxc = value
}
break
case 3:
//if (value < maxSupport && (value / Math.max(idfTable[itemset[w]], idfBase)) * idfBase > maxc) {
if (value < maxSupport && value > maxc && (stopwords.indexOf(itemset[w]) < 0 || isNotRoot)) {
//if (value < maxSupport && value > maxc && stopwords.indexOf(itemset[w]) < 0) {
maxw = +w;
//maxc = (value / Math.max(idfTable[itemset[w]], idfBase)) * idfBase
maxc = value
}
break
case 2:
//if (value < maxSupport && value > maxc && (stopwords.indexOf(itemset[w]) < 0 || isNotRoot)) {
if (value < maxSupport && value > maxc && stopwords.indexOf(itemset[w]) < 0) {
maxw = +w;
//maxc = (value / Math.max(idfTable[itemset[w]], idfBase)) * idfBase
maxc = value
}
break
default:
break
} }
}); });
console.log(itemset)
if (maxc > count) { if (maxc > count) {
pos = s; pos = s;
word = maxw; word = maxw;
count = maxc; count = maxc;
console.log({ 'word#': maxw, 'word': itemset[maxw], 'root': seq.newWord ? seq.newWord.entity : null, 'count': root ? count : "root" })
} }
}; };
@ -19188,7 +19236,6 @@
} }
} }
} }
console.log({ 's0': s0, 's1': s1 })
return { word: word, pos: pos, count: count, s0: s0, s1: s1 }; return { word: word, pos: pos, count: count, s0: s0, s1: s1 };
} }
@ -19206,12 +19253,10 @@
seqs.push(rootSeq); seqs.push(rootSeq);
var leafSeqs = []; var leafSeqs = [];
console.log(JSON.parse(JSON.stringify(seqs)))
while (!seqs.empty() && expandCnt > 0) { while (!seqs.empty() && expandCnt > 0) {
/* find the candidate sequence with largest support DB */ /* find the candidate sequence with largest support DB */
var s = seqs.pop(); var s = seqs.pop();
console.log({ 's': s, 'seqs': seqs })
var graph = s.graph; var graph = s.graph;
var s0 = s.r; var s0 = s.r;
var s1 = s.l; var s1 = s.l;
@ -19219,7 +19264,6 @@
if (!s0 && !s1) { if (!s0 && !s1) {
/* find the next frequent sequence */ /* find the next frequent sequence */
var result = growSeq(s, terms, minSupport, maxSupport, itemset); var result = growSeq(s, terms, minSupport, maxSupport, itemset);
console.log(result)
s0 = result.s0; s0 = result.s0;
s1 = result.s1; s1 = result.s1;
var word = result.word, var word = result.word,
@ -19237,6 +19281,7 @@
} }
var newWord = { var newWord = {
id: graph.totalNodeCnt++, id: graph.totalNodeCnt++,
word: word,
entity: itemset[word], entity: itemset[word],
freq: count, freq: count,
topEntries: s1.DBs.slice(0, 5), topEntries: s1.DBs.slice(0, 5),
@ -19306,7 +19351,6 @@
var str = words.map(function(w) { var str = words.map(function(w) {
return w.entity; return w.entity;
}).join(' '); }).join(' ');
console.log(str);
} }
var SentenTreeModel = function() { var SentenTreeModel = function() {
@ -19336,7 +19380,6 @@
var size = tokenizedData.computeSize(); var size = tokenizedData.computeSize();
this.supportRange = [Math.max(size * minSupportRatio, minSupportCount), size * maxSupportRatio]; this.supportRange = [Math.max(size * minSupportRatio, minSupportCount), size * maxSupportRatio];
console.log(this.supportRange)
var _supportRange = _slicedToArray(this.supportRange, 2), var _supportRange = _slicedToArray(this.supportRange, 2),
minSupport = _supportRange[0], minSupport = _supportRange[0],
@ -19386,11 +19429,9 @@
key: 'getRenderedGraphs', key: 'getRenderedGraphs',
value: function getRenderedGraphs(limit) { value: function getRenderedGraphs(limit) {
var graphs = arguments.length === 1 ? this.graphs.slice(0, limit) : this.graphs; var graphs = arguments.length === 1 ? this.graphs.slice(0, limit) : this.graphs;
console.log("slice")
var renderedGraphs = graphs.map(function(g) { var renderedGraphs = graphs.map(function(g) {
return g.toRenderedGraph(); return g.toRenderedGraph();
}); });
console.log("toRenderedGraph")
var globalFreqRange = [(0, _lodash.min)(renderedGraphs.map(function(g) { var globalFreqRange = [(0, _lodash.min)(renderedGraphs.map(function(g) {
return g.freqRange[0]; return g.freqRange[0];
})), (0, _lodash.max)(renderedGraphs.map(function(g) { })), (0, _lodash.max)(renderedGraphs.map(function(g) {
@ -37869,15 +37910,12 @@
let counter = 1; let counter = 1;
while (heap.size() > 0) { while (heap.size() > 0) {
console.log(`in while ${counter++}`)
var parent = heap.pop(); var parent = heap.pop();
console.log(heap)
if (parent.merged) { if (parent.merged) {
continue; continue;
} }
var groups = []; var groups = [];
console.log(parent.data.id)
if (parent.leftLinks.length > 1) { if (parent.leftLinks.length > 1) {
var lNodes = parent.leftLinks.map(function(l) { var lNodes = parent.leftLinks.map(function(l) {
return l.source; return l.source;
@ -37891,7 +37929,6 @@
}); });
groups = groups.concat(this.groupMergeableNodes(rNodes)); groups = groups.concat(this.groupMergeableNodes(rNodes));
} }
console.log(groups)
if (groups.length > 0) { if (groups.length > 0) {
var newNodes = groups.map(function(group) { var newNodes = groups.map(function(group) {
@ -38119,7 +38156,6 @@
var RenderedGraph = function() { var RenderedGraph = function() {
function RenderedGraph(rawGraph) { function RenderedGraph(rawGraph) {
console.log(arguments)
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$bundle = _ref.bundle, _ref$bundle = _ref.bundle,
bundle = _ref$bundle === undefined ? true : _ref$bundle, bundle = _ref$bundle === undefined ? true : _ref$bundle,
@ -38152,10 +38188,8 @@
this.assignNodeIds(nodes); this.assignNodeIds(nodes);
console.log(bundle)
if (bundle) { if (bundle) {
var bundled = new _GraphBundler2.default(nodes, links).bundle(); var bundled = new _GraphBundler2.default(nodes, links).bundle();
console.log(bundled)
this.nodes = bundled.nodes; this.nodes = bundled.nodes;
this.links = bundled.links; this.links = bundled.links;
this.assignNodeIds(this.nodes); this.assignNodeIds(this.nodes);
@ -43071,11 +43105,10 @@
var l3 = l * l * l; var l3 = l * l * l;
var hs = 2 * -weight / (D2 * l3); var hs = 2 * -weight / (D2 * l3);
if (!isFinite(gs)) if (!isFinite(gs))
console.log(gs); for (i = 0; i < this.k; ++i) {
for (i = 0; i < this.k; ++i) { this.g[i][u] += d[i] * gs;
this.g[i][u] += d[i] * gs; Huu[i] -= this.H[i][u][v] = hs * (l3 + D * (d2[i] - sd2) + l * sd2);
Huu[i] -= this.H[i][u][v] = hs * (l3 + D * (d2[i] - sd2) + l * sd2); }
}
} }
for (i = 0; i < this.k; ++i) for (i = 0; i < this.k; ++i)
maxH = Math.max(maxH, this.H[i][u][u] = Huu[i]); maxH = Math.max(maxH, this.H[i][u][u] = Huu[i]);

@ -80,7 +80,8 @@
<input id="keywordBox" type="text" name="message" placeholder="輸入關鍵詞"> <input id="keywordBox" type="text" name="message" placeholder="輸入關鍵詞">
<button class="general-button" type="button" id="sendButton" onclick="sendRequest()">搜尋關鍵字</button> <button class="general-button" type="button" id="sendButton" onclick="sendRequest()">搜尋關鍵字</button>
<button class="general-button" type="button" id="resetButton" onclick="document.getElementById('keywordBox').value=''">清除關鍵字</button> <button class="general-button" type="button" id="resetButton" onclick="document.getElementById('keywordBox').value=''">清除關鍵字</button>
<button class="general-button" type="button" id="editSWButton" onclick="showIdfEditor()">編輯停用詞</button> <button class="general-button" type="button" id="editSWButton" onclick="showStopwordEditor()">編輯停用詞</button>
<button class="general-button" type="button" id="editIdeButton" onclick="showIdfEditor()">編輯詞頻</button>
</form> </form>
</div> </div>
<div id="advancedArea"> <div id="advancedArea">
@ -95,6 +96,12 @@
<input type="checkbox" id="other" checked="checked">其他詞性 <input type="checkbox" id="other" checked="checked">其他詞性
</form> </form>
</div> </div>
<div id='modeSelector'>
<button type="button" id='mode0' class='w3-button' onclick="changeMode(0)">相鄰詞模式</button>
<button type="button" id='mode1' class='w3-button ' onclick="changeMode(1)">Idf模式</button>
<button type="button" id='mode2' class='w3-button ' onclick="changeMode(2)">停用詞模式</button>
<button type="button" id='mode3' class='w3-button ' onclick="changeMode(3)">根單詞停用模式</button>
</div>
</div> </div>
<div id="graphInfo"></div> <div id="graphInfo"></div>
<div id="graph"> <div id="graph">

@ -75,6 +75,7 @@
<button class="general-button" type="button" id="sendButton" onclick="sendRequest()">搜尋關鍵字</button> <button class="general-button" type="button" id="sendButton" onclick="sendRequest()">搜尋關鍵字</button>
<button class="general-button" type="button" id="resetButton" onclick="document.getElementById('keywordBox').value=''">清除關鍵字</button> <button class="general-button" type="button" id="resetButton" onclick="document.getElementById('keywordBox').value=''">清除關鍵字</button>
<button class="general-button" type="button" id="editSWButton" onclick="showStopwordEditor()">編輯停用詞</button> <button class="general-button" type="button" id="editSWButton" onclick="showStopwordEditor()">編輯停用詞</button>
<button class="general-button" type="button" id="editIdeButton" onclick="showIdfEditor()">編輯詞頻</button>
</form> </form>
</div> </div>
<div id="advancedArea"> <div id="advancedArea">
@ -89,6 +90,12 @@
<input type="checkbox" id="other" checked="checked">其他詞性 <input type="checkbox" id="other" checked="checked">其他詞性
</form> </form>
</div> </div>
<div id='modeSelector'>
<button type="button" id='mode0' class='w3-button' onclick="changeMode(0)">相鄰詞模式</button>
<button type="button" id='mode1' class='w3-button ' onclick="changeMode(1)">Idf模式</button>
<button type="button" id='mode2' class='w3-button ' onclick="changeMode(2)">停用詞模式</button>
<button type="button" id='mode3' class='w3-button ' onclick="changeMode(3)">根單詞停用模式</button>
</div>
</div> </div>
<div id="graphInfo"></div> <div id="graphInfo"></div>
<div id="graph"> <div id="graph">

Loading…
Cancel
Save