Skip to content
Snippets Groups Projects
Commit 69f3142e authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Generating json with tags names on tag frequency task

parent 81bd18a3
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ namespace :tag do ...@@ -3,6 +3,7 @@ namespace :tag do
desc 'Generate tag frequency hash' desc 'Generate tag frequency hash'
task generate_tag_frequency_hash: :environment do task generate_tag_frequency_hash: :environment do
hash = {} hash = {}
name = {}
LearningObject.all.each do |lo| LearningObject.all.each do |lo|
# for each lo, count tags and tag pairs and add to hash # for each lo, count tags and tag pairs and add to hash
...@@ -10,7 +11,13 @@ namespace :tag do ...@@ -10,7 +11,13 @@ namespace :tag do
# hash[id1][id2] will equal how many times tags with id1 and id2 appear together on a LO # hash[id1][id2] will equal how many times tags with id1 and id2 appear together on a LO
# hash[id][id] will equal how many times tag of id appears # hash[id][id] will equal how many times tag of id appears
lo.tags.each.with_index do |t, i| lo.tags.each.with_index do |t, i|
name[t.id] = t.name
hash[t.id] = {} if hash[t.id].nil? hash[t.id] = {} if hash[t.id].nil?
if hash[t.id][t.id] != nil
hash[t.id][t.id] += 1
else
hash[t.id][t.id] = 1
end
lo.tags.drop(i+1).each do |t2| lo.tags.drop(i+1).each do |t2|
hash[t2.id] = {} if hash[t2.id].nil? hash[t2.id] = {} if hash[t2.id].nil?
...@@ -28,13 +35,8 @@ namespace :tag do ...@@ -28,13 +35,8 @@ namespace :tag do
File.open("tag_frequency_hash.json", "w+") do |f| File.open("tag_frequency_hash.json", "w+") do |f|
f << hash.to_json f << hash.to_json
end end
File.open("tag_name.json", "w+") do |f|
File.open("community_input.txt", "w+") do |f| f << name.to_json
hash.each do |id1, ids2Hash|
ids2Hash.each do |id2, value|
f << "#{id1}, #{id2}, #{value}\n"
end
end
end end
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