Skip to content
Snippets Groups Projects
Commit 5343b99a authored by bfs15's avatar bfs15
Browse files

Parsing infomap ftree output

parent 12421110
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,12 @@ require 'json'
namespace :tag do
desc 'Generate tag clusters'
task generate_clusters: :environment do
outDIR = "tmp"
fileName = "tags"
hash = {}
edges_total = 0
filepath = Rails.root.join("tmp","pajek.net")
graphPath = Rails.root.join(outDir, fileName + ".net")
def swap(a, b)
tmp = a
......@@ -40,7 +43,7 @@ namespace :tag do
end
end
File.open(filepath, "w+") do |f|
File.open(graphPath, "w+") do |f|
f << "*Vertices #{Tag.all.size}\n"
# tags = Tag.all.to_ary
tag_index = {}
......@@ -60,6 +63,39 @@ namespace :tag do
end
end
system("infomap --ftree #{filepath} #{Rails.root.join("tmp")}")
system("infomap --ftree #{graphPath} #{Rails.root.join(outDIR)}")
clusters = {childs: [], parent: nil}
tags = {}
File.open(Rails.root.join(outDIR, fileName + ".ftree"), "r") do |f|
f.gets
f.gets
while line = f.gets
break if !line.include? ':'
tmp = line.split(' ')
ftree = tmp[0].split(':')[0..-2]
leafId = tmp[0].split(':')[-1].to_i
tagId = tmp[-1].to_i
rank = tmp[1].to_f
name = tmp[2..-2].join(' ')[1..-2]
it = clusters
ftree.each do |clusterId|
# p it
clusterId = clusterId.to_i
if it[:childs][clusterId].nil?
it[:childs][clusterId] = {childs: [], parent: nil}
it[:childs][clusterId][:parent] = it
end
it = it[:childs][clusterId]
end
it[:childs][leafId] = {id: tagId, rank: rank, name: name, parent: it}
tags[tagId] = it
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment