generate.rake revision 7cc85babaf117501a3a0846f6ebff3ae44a2709b
883N/Adef update_or_create_by_name(klass, h)
883N/A x = klass.find_by_name(h[:name])
883N/A if x.nil?
883N/A x = klass.create!(h)
883N/A else
883N/A x.update_attributes!(h)
883N/A end
883N/A x
883N/Aend
883N/A
883N/Adef meta_repository
883N/A Repository.where(name: 'meta').
883N/A first_or_create!(description: 'Meta ontologies for Ontohub')
883N/Aend
883N/A
883N/Adef download_from_ontohub_meta(source_file, target_file)
883N/A meta_repository
883N/A user = User.where(admin: true).first
883N/A filepath = "#{Rails.root}/spec/fixtures/ontologies/#{target_file}"
883N/A system("wget -O #{filepath} https://ontohub.org/repositories/meta/master/download/#{source_file}")
883N/A basename = File.basename(filepath)
883N/A version = meta_repository.
883N/A save_file(filepath, basename, "Add #{basename}.", user, do_not_parse: true)
883N/A version.parse
883N/A system("rm #{filepath}")
883N/A version.ontology
883N/Aend
namespace :generate do
desc 'Import the categories for the ontologies'
task :categories => :environment do
ontology = meta_repository.ontologies.
where("name ilike '%Domain Fields Core'").first
if ontology
ontology.create_categories
else
ontology = download_from_ontohub_meta(
'Domain_Fields_Core.owl', 'categories.owl')
end
ontology.create_categories
end
desc 'Import the proof statuses for theorems'
task :proof_statuses => :environment do
meta_repository
download_from_ontohub_meta('proof_statuses.owl', 'proof_statuses.owl')
ProofStatus.refresh_statuses
end
desc 'Generate symbol trees for ALL OWL ontologies'
task :owl_ontology_class_hierarchies => :environment do
#cleaning up
SymbolGroup.destroy_all
#generating new
logics = Logic.where(name: ["OWL2", "OWL"])
ontologies = Ontology.where(logic_id: logics)
ontologies.each do |ontology|
begin
TarjanTree.for(ontology)
rescue ActiveRecord::RecordNotFound => e
puts "Could not create symbol tree for: #{ontology.name} (#{ontology.id}) caused #{e}"
end
end
end
desc 'Generate symbol tree for one specific OWL ontologies'
task :class_hierachy_for_specific_ontology, [:ontology_id] => :environment do |t,args|
ontology = Ontology.find!(args.ontology_id)
#cleaning up to prevent duplicated symbol_groups
ontology.symbol_groups.destroy_all
#generating new
begin
TarjanTree.for(ontology)
rescue ActiveRecord::RecordNotFound => e
puts "Could not create entity tree for: #{ontology.name} (#{ontology.id}) caused #{e}"
end
end
desc 'Import the values for metadata'
task :metadata => :environment do
Settings.formality_levels.each { |t| update_or_create_by_name(FormalityLevel, t.to_h) }
Settings.license_models.each { |t| update_or_create_by_name(LicenseModel, t.to_h) }
Settings.ontology_types.each { |t| update_or_create_by_name(OntologyType, t.to_h) }
Settings.tasks.each { |t| update_or_create_by_name(Task, t.to_h) }
end
end