Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ikenohate09/design_exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
cearto committed Jul 24, 2014
2 parents 63f0488 + 42cc946 commit 7f9f18d
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 43 deletions.
5 changes: 4 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ bundle install

rake db:migrate
rake sunspot:solr:start
rake db:seed

Run in the following order
rake db:seed:users
rake db:seed:design_methods
rake db:seed:casestudies
rake db:seed:discussions

Expand Down
1 change: 1 addition & 0 deletions app/models/discussion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#

class Discussion < ActiveRecord::Base
attr_accessible :title, :description, :user_id
validates :title, :description, :user, presence: true

validates_uniqueness_of :title
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class User < ActiveRecord::Base
attr_accessible :email, :first_name, :last_name, :username, :phone_number, :website,
:facebook, :twitter, :linkedin, :about_text , :profile_picture
:facebook, :twitter, :linkedin, :about_text , :profile_picture, :password, :password_confirmation
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
Expand Down
10 changes: 10 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "first_name"
t.string "last_name"
t.string "username"
t.string "profile_picture"
t.string "phone_number"
t.string "website"
t.string "facebook"
t.string "twitter"
t.string "linkedin"
t.string "about_text"
t.datetime "created_at"
t.datetime "updated_at"
end
Expand Down
14 changes: 1 addition & 13 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@
# include RDF
# Reset users

User.destroy_all

# Create default admin user

admin = User.create!(
email: "[email protected]",
password: "thedesignexchange",
password_confirmation: "thedesignexchange",
)

# Read in the ontology

filename = File.join(Rails.root, 'lib/tasks/data/dx.owl')
fields = Hash.new

Expand Down Expand Up @@ -124,7 +112,7 @@
data.query(principle).each do |results|
fields[:principle] = results.principle.to_s
end

design_method.principle = ""
design_method = DesignMethod.new(fields)
design_method.owner = admin

Expand Down
152 changes: 152 additions & 0 deletions db/seeds/design_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
filename = File.join(Rails.root, 'lib/tasks/data/dx.owl')
fields = Hash.new

DesignMethod.destroy_all
MethodCategory.destroy_all
Citation.destroy_all

data = RDF::Graph.load(filename)

# SPARQL prefix
root_prefix = "PREFIX : <http://www.semanticweb.org/howard/ontologies/2014/0/DesignExchange_Methods#>"

# Searching for design methods and method categories, using the subClassOf relationship.
# This should be fixed w/something more convenient -- have some kind of predicate I can search on.
# Hm, based on how this looks, might need to add descriptions to the method categories as well.

methods = SPARQL.parse("SELECT ?subj ?obj { ?subj <#{RDF::RDFS.subClassOf}> ?obj }")
all_objects = Set.new
all_subjects = Set.new

data.query(methods).each do |results|
all_objects << results.obj.to_s.split('#')[1]
all_subjects << results.subj.to_s.split('#')[1]
end

# Deleting entries with punctuation that's troublesome for SPARQL queries
all_objects.delete_if { |str| str == nil || str.match(/,|\(|\)|\\|\//) }
all_subjects.delete_if { |str| str == nil || str.match(/,|\(|\)|\\|\//) }

# The design methods are the individuals (no subclasses) - right now this over-selects
only_methods = all_subjects - all_objects
p only_methods

# The method categories are everything else - right now this under-selects
method_categories = all_objects - only_methods
p method_categories

# # Instantiating method categories
# method_categories.each do |cat|
# method_category = MethodCategory.new(name: cat)
# if method_category.save
# p "Added method category: #{method_category.name}"
# else
# p "Error while creating a method category: "
# method_category.errors.full_messages.each do |message|
# p "\t#{message}"
# end
# end
# end

# method_categories.each do |cat|
# # Load in children of method category
# method_category = MethodCategory.where(name: cat).first
# children = SPARQL.parse("#{root_prefix} SELECT ?child { ?child <#{RDF::RDFS.subClassOf}> :#{cat} }")
# data.query(children).each do |results|
# child_name = results.child.to_s.split('#')[1]
# if method_category.add_child(MethodCategory.where(name: child_name).first)
# p "Added child of #{cat}: #{child_name}"
# end
# end
# end

# def remove_unwanted(method)
# method.children.each do |child|
# name = child.name
# child.destroy
# p " Removed #{name}"
# end
# m_name = method.name
# method.destroy
# p " Removed #{m_name}"
# end

# # Remove any of the classes that don't fall under the Method umbrella. If property paths gets added to the SPARQL gem then this won't be necessary
# to_delete = MethodCategory.where(name: "Person").first
# remove_unwanted(to_delete)
# to_delete = MethodCategory.where(name: "Method_Characteristics").first
# remove_unwanted(to_delete)
# to_delete = MethodCategory.where(name: "Processes").first
# remove_unwanted(to_delete)
# to_delete = MethodCategory.where(name: "Skills").first
# remove_unwanted(to_delete)


# Instantiating design methods; currently filling in contents w/ "default" so that things can get loaded.
# Fix this once more of the ontology is ready, and we want to catch entries that need to get fixed.
only_methods.each do |method|
fields[:name] = method
fields[:overview] = "default"
fields[:process] = "default"
fields[:principle] = "default"

# Add the overview: currently searching on AnnotationProperty Description
overview = SPARQL.parse("#{root_prefix} SELECT ?overview { :#{method} :Description ?overview }")
data.query(overview).each do |results|
fields[:overview] = results.overview.to_s
end

# Add the process: currently searching on AnnotationProperty process
process = SPARQL.parse("#{root_prefix} SELECT ?process { :#{method} :process ?process }")
data.query(process).each do |results|
fields[:process] = results.process.to_s
end

# Add the principle: currently searching on AnnotationProperty Notes
principle = SPARQL.parse("#{root_prefix} SELECT ?principle { :#{method} :Notes ?principle }")
data.query(principle).each do |results|
fields[:principle] = results.principle.to_s
end
design_method.principle = ""
design_method = DesignMethod.new(fields)
design_method.owner = admin

if !design_method.save
p "Error while creating a design method: "
design_method.errors.full_messages.each do |message|
p "\t#{message}"
end
else
p "Added design method: #{design_method.name}"
end

# # Read in categories
# categories = SPARQL.parse("#{root_prefix} SELECT ?obj { :#{design_method.name} <#{RDF::RDFS.subClassOf}> ?obj }")
# data.query(categories).each do |results|
# cat_name = results.obj.to_s.split('#')[1]
# if cat_name
# category = MethodCategory.where(name: cat_name).first
# if category && !design_method.method_categories.include?(category)
# design_method.method_categories << category
# p " Added category #{cat_name}"
# category.parents.each do |gparents|
# if gparents && !design_method.method_categories.include?(gparents)
# design_method.method_categories << gparents
# p " Added category #{gparents.name}"
# end
# end
# end
# end
# end

# # Read in citations
# citations = SPARQL.parse("#{root_prefix} SELECT ?ref { :#{design_method.name} :references ?ref }")
# data.query(citations).each do |results|
# cit_text = results.ref.to_s
# citation = Citation.where(text: cit_text).first_or_create!
# if !design_method.citations.include?(citation)
# design_method.citations << citation
# p " Added citation #{cit_text}"
# end
# end
end
18 changes: 0 additions & 18 deletions db/seeds/discussions.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
require "json"

users_file = 'users.json'
discussion_file = 'discussions.json'

# File should be in public
def get_data_user(json_file)
file = Rails.root.join('public', json_file);
data_users = JSON.parse(IO.read(file))
end

def get_data_discussion(json_file)
file = Rails.root.join('public', json_file);
data_discussions = JSON.parse(IO.read(file))
end

def process_users(data)
# User.destroy_all
p "=============== SEEDING USERS ================"
data.each do |el|
user = User.new(el)
p "Added user: #{user.email}" unless not user.save
# p user.errors unless user.save
end
p "==============================="
end

def process_discussions(data)
Discussion.destroy_all
Expand All @@ -37,7 +21,5 @@ def process_discussions(data)
p "==============================="
end

data_users = get_data_user(users_file)
data_discussions = get_data_discussion(discussion_file)
process_users(data_users)
process_discussions(data_discussions)
23 changes: 23 additions & 0 deletions db/seeds/users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "json"

users_file = 'users.json'

# File should be in public
def get_data_user(json_file)
file = Rails.root.join('public', json_file);
data_users = JSON.parse(IO.read(file))
end

def process_users(data)
# User.destroy_all
p "=============== SEEDING USERS ================"
data.each do |el|
user = User.new(el)
p "Added user: #{user.email}" unless not user.save
# p user.errors unless user.save
end
p "==============================="
end

data_users = get_data_user(users_file)
process_users(data_users)
Loading

0 comments on commit 7f9f18d

Please sign in to comment.