seeds.rb revision 8e9749fa7f715b073417d5629d4a14135369d297
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Create Admin User
:admin => true,
:password => 'foobar'
# Create Team
team = Team.create! \
:name => 'Lorem Ipsum',
:admin_user => user
# Create some other users
user = User.create! \
:email => "#{name}@example.com",
:password => 'foobar'
# add two users to the first team
team.users << user if i < 2
end
# Registry ontology
#
#
require 'rdf'
require 'rdf/rdfxml'
require 'rdf/ntriples'
statements = nil
RDF::RDFXML::Reader.open("registry/registry.rdf") do |reader|
statements = reader.statements.to_a
end && 0
# Map relations
reldir = Hash.new(nil)
relinv = Hash.new(nil)
statements.each do |statement|
a = "#{statement[0]}"
b = "#{statement[1]}"
c = "#{statement[2]}"
if reldir[b] == nil
reldir[b] = Hash.new
relinv[b] = Hash.new
end
if reldir[b][a] == nil
reldir[b][a] = Array.new
end
reldir[b][a].push c
if relinv[b][c] == nil
relinv[b][c] = Array.new
end
relinv[b][c].push a
end
typeIri = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
labelIri = 'http://www.w3.org/2000/01/rdf-schema#label'
commentIri = 'http://www.w3.org/2000/01/rdf-schema#comment'
isDefinedByIri = 'http://www.w3.org/2000/01/rdf-schema#isDefinedBy'
logicTypeIri = 'http://purl.net/dol/1.0/rdf#Logic'
languageTypeIri = 'http://purl.net/dol/1.0/rdf#OntologyLanguage'
# Logic Section
#
# Author: Daniel Couto Vale <danielvale@uni-bremen.de>
# Source: The registry ontology
logicIris = relinv[typeIri][logicTypeIri]
logicIris.each do |logicIri|
print "\nLOGIC "
print logicIri
print "\n"
logicName = reldir[labelIri][logicIri] != nil ? reldir[labelIri][logicIri][0] : logicIri;
logicDesc = reldir[commentIri][logicIri] != nil ? reldir[commentIri][logicIri][0] : logicIri;
logicDefi = reldir[isDefinedByIri][logicIri] != nil ? reldir[isDefinedByIri][logicIri][0] : logicIri;
logic = Logic.new({
:iri => logicIri,
:name => logicName,
:description => logicDesc,
:defined_by => logicDefi
})
logic.save!
end
# Language Section
#
# Author: Daniel Couto Vale <danielvale@uni-bremen.de>
# Source: The Distributed Otology Language (DOL): use cases, syntax and extensibility
#
# Logics:
# * Common Logic
# * OWL2-DL
# * OWL2-RL
# * OWL2-QL
# * OWL2-EL
# * RDFS
# * RDF
language = Language.new({
:name => "Common Logic",
:iri => "http://ontohub.org/lang/cl",
:description => "Common Logic Language"
})
language.save!
language = Language.new({
:name => "OWL2-DL",
:iri => "http://ontohub.org/lang/owl2-dl",
:description => "OWL2 DL"
})
language.save!
language = Language.new({
:name => "OWL2-RL",
:iri => "http://ontohub.org/lang/owl2-rl",
:description => "OWL2 RL"
})
language.save!
language = Language.new({
:name => "OWL2-QL",
:iri => "http://ontohub.org/lang/owl2-ql",
:description => "OWL2 QL"
})
language.save!
language = Language.new({
:name => "OWL2-EL",
:iri => "http://ontohub.org/lang/owl2-el",
:description => "OWL2 EL"
})
language.save!
language = Language.new({
:name => "RDFS",
:iri => "http://ontohub.org/lang/rdfs",
:description => "RDFS"
})
language.save!
language = Language.new({
:name => "RDF",
:iri => "http://ontohub.org/lang/rdf",
:description => "RDF"
})
language.save!
# Import ontologies
Dir["#{Rails.root}/test/fixtures/ontologies/*/*.{casl,clf,clif,owl}"].each do |file|
basename = File.basename(file)
clazz = basename.ends_with?('.casl') ? DistributedOntology : SingleOntology
o = clazz.new \
iri: "file://db/seeds/#{basename}",
name: basename.split(".")[0].capitalize,
description: Faker::Lorem.paragraph
v = o.versions.build raw_file: File.open(file)
v.user = user
v.created_at = rand(60).minutes.ago
v.number = 1
o.save!
o.ontology_version = v;
o.save!
end
# Add permissions
Ontology.find_each do |o|
o.permissions.create! \
subject: Team.first,
role: 'owner'
end
Ontology.first.permissions.create! \
subject: User.first,
role: 'editor'
# Add comments
5.times do |n|
c = Ontology.first.comments.build \
text: (1 + rand(4)).times.map{ Faker::Lorem.paragraph(5+rand(10)) }.join("\n\n")
c.user = User.first
c.created_at = (60 - n*5).minutes.ago
c.save!
end