1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 02:18:20 +01:00
This commit is contained in:
Xuan Sang LE 2018-06-05 14:36:39 +02:00
parent f32ccc8766
commit 30ff1d60fb
2 changed files with 41 additions and 1 deletions

View File

@ -88,5 +88,43 @@ get.bytag = function(user, b64tag, limit, action, id)
return data, sort return data, sort
end end
return get get.analyse = function(user)
local path = "/home/mrsang/aiws/blog-clustering"
local gettext = loadfile(path.."/gettext.lua")()
local cluster = loadfile(path.."/cluster.lua")()
local data = gettext.get({publish=1})
local documents = {}
if data then
local sw = gettext.stopwords(path.."/stopwords.txt")
for k,v in pairs(data) do
local bag = cluster.bow(data[k].content, sw)
documents[data[k].id] = bag
end
cluster.tfidf(documents)
--local v = cluster.search("arm", documents)
--echo(JSON.encode(v))
local vectors, maxv, size = cluster.get_vectors(documents)
local sample_data = {pid = 1, sid = 2, score = 0.1}
local db = require("db.model").get(user, "st_similarity", sample_data)
if db then
-- purge the table
db:delete({["="] = {["1"] = 1}})
-- get similarity and put to the table
for id,v in pairs(vectors) do
local top = cluster.top_similarity(id,vectors,3)
for a,b in pairs(top) do
local record = {pid = id, sid = a, score = b}
db:insert(record)
end
end
db:close()
return "<h3>Analyse complete</h3>"
else
return "<h3>Cannot get database objectw/h3>"
end
else
return "<h3>Cannot find data to analyse</h3>"
end
end
return get

View File

@ -19,6 +19,8 @@ view.render = function(action, data, sort, min, max)
fn, e = loadscript(path.."/detail.ls") fn, e = loadscript(path.."/detail.ls")
--echo(data[0].rendered) --echo(data[0].rendered)
--fn = require("blog.view.compiledd") --fn = require("blog.view.compiledd")
elseif action == "analyse" then
fn, e = loadscript(path.."/analyse.ls")
else else
--fn = require("blog.view.compiledd") --fn = require("blog.view.compiledd")