From 30ff1d60fb5aaf7f509c069a654564039a505e02 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Tue, 5 Jun 2018 14:36:39 +0200 Subject: [PATCH] fix --- blog/api.lua | 40 +++++++++++++++++++++++++++++++++++++++- blog/view.lua | 2 ++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/blog/api.lua b/blog/api.lua index 95372d9..c52d5a7 100644 --- a/blog/api.lua +++ b/blog/api.lua @@ -88,5 +88,43 @@ get.bytag = function(user, b64tag, limit, action, id) return data, sort 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 "

Analyse complete

" + else + return "

Cannot get database objectw/h3>" + end + else + return "

Cannot find data to analyse

" + end +end +return get \ No newline at end of file diff --git a/blog/view.lua b/blog/view.lua index 39e2cb7..a9ae3bc 100644 --- a/blog/view.lua +++ b/blog/view.lua @@ -19,6 +19,8 @@ view.render = function(action, data, sort, min, max) fn, e = loadscript(path.."/detail.ls") --echo(data[0].rendered) --fn = require("blog.view.compiledd") + elseif action == "analyse" then + fn, e = loadscript(path.."/analyse.ls") else --fn = require("blog.view.compiledd")