Skip to content
Snippets Groups Projects
Commit 6590821a authored by bfs15's avatar bfs15
Browse files

Added comments

parent a5cd92d9
No related branches found
No related tags found
No related merge requests found
......@@ -22,12 +22,14 @@ namespace :tag do
task :generate_clusters => [:environment] do
# DEBUG = true
graph_path = TagSearchService.file_path+".net"
# Create hash of tag co occurrence
hash = create_hash()
# Create a graph infomap can read
create_pajek_net_graph(hash, graph_path)
infomap_ftree(graph_path, TagSearchService.root_dir)
# Cluster needs to be read from disk again, so clear cache of TagSearchService
Rails.cache.delete(TagSearchService::CACHE_KEY)
end # task
......@@ -42,28 +44,25 @@ namespace :tag do
# for each lo, count tags and tag pairs and add to hash
# if id1 <= id2
lo.tags.each.with_index do |t, i|
# initialize value
# initialize values
hash[t.id] = {} if hash[t.id].nil?
hash[t.id][t.id] = 0 if hash[t.id][t.id].nil?
hash[t.id][t.id] += 1
hash[t.id][t.id] += 1 # add self occurrence
# for each next tags (with higher index)
# for each next tags (with higher index than t)
lo.tags.drop(i+1).each do |t2|
# [t1][t2], t1 should always be lower
# swap if necessary ([t1][t2], t1 should always have lower id)
if t.id > t2.id
# swaps
# swaps t with t2
t, t2 = t2, t
# check nil
hash[t.id] = {} if hash[t.id].nil?
end
# initialize value
if hash[t.id][t2.id].nil?
hash[t.id][t2.id] = 0
end
hash[t.id][t2.id] = 0 if hash[t.id][t2.id].nil?
hash[t.id][t2.id] += 1
hash[t.id][t2.id] += 1 # add co occurrence
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