Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
nning committed Jan 9, 2014
2 parents 8f0b16d + 3c4b1bd commit aeeca6f
Show file tree
Hide file tree
Showing 19 changed files with 2,716 additions and 1,375 deletions.
33 changes: 17 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ GEM
activesupport (3.2.16)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
acts_as_tree (1.4.0)
acts_as_tree (1.5.0)
activerecord (>= 3.0.0)
addressable (2.3.5)
arel (3.0.3)
bcrypt-ruby (3.1.2)
better_errors (1.0.1)
better_errors (1.1.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.0.2.0)
bootstrap-sass (3.0.3.0)
sass (~> 3.2)
builder (3.0.4)
byebug (2.3.1)
byebug (2.5.0)
columnize (~> 0.3.6)
debugger-linecache (~> 1.2.0)
cancan (1.6.10)
Expand All @@ -72,13 +72,13 @@ GEM
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
capybara (2.1.0)
capybara (2.2.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
capybara-webkit (1.0.0)
capybara-webkit (1.1.0)
capybara (~> 2.0, >= 2.0.2)
json
celluloid (0.15.2)
Expand All @@ -103,7 +103,7 @@ GEM
connection_pool (1.2.0)
crack (0.4.1)
safe_yaml (~> 0.9.0)
d3_rails (3.3.9)
d3_rails (3.3.13)
railties (>= 3.1.0)
dagnabit (3.0.1)
activerecord (>= 2.3.0)
Expand Down Expand Up @@ -132,11 +132,11 @@ GEM
i18n (~> 0.5)
fattr (2.2.1)
font_awesome (3.101.0)
foreigner (1.6.0)
foreigner (1.6.1)
activerecord (>= 3.0.0)
fssm (0.2.10)
god (0.13.3)
haml (4.0.4)
haml (4.0.5)
tilt
haml-rails (0.4)
actionpack (>= 3.1, < 4.1)
Expand Down Expand Up @@ -167,15 +167,15 @@ GEM
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (4.1.0)
jquery-ui-rails (4.1.1)
railties (>= 3.1.0)
js-routes (0.9.4)
rails (>= 3.2)
json (1.8.1)
kaminari (0.14.1)
kaminari (0.15.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
launchy (2.3.0)
launchy (2.4.2)
addressable (~> 2.3)
libv8 (3.16.14.3)
mail (2.5.4)
Expand All @@ -201,7 +201,7 @@ GEM
mini_portile (~> 0.5.0)
options (2.3.0)
fattr
orm_adapter (0.4.0)
orm_adapter (0.5.0)
pg (0.17.1)
polyglot (0.3.3)
pr_geohash (1.0.0)
Expand All @@ -212,7 +212,7 @@ GEM
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
pry-byebug (1.2.0)
pry-byebug (1.2.1)
byebug (~> 2.2)
pry (~> 0.9.12)
pry-rails (0.3.2)
Expand Down Expand Up @@ -284,8 +284,9 @@ GEM
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
rspec-rails (2.14.0)
rspec-rails (2.14.1)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.14.0)
Expand Down Expand Up @@ -346,7 +347,7 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.38)
uglifier (2.3.0)
uglifier (2.4.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
vcr (2.8.0)
Expand Down
12 changes: 2 additions & 10 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,12 @@ def index

def new
@ontology_version = build_resource.versions.build
@c_vertices = []
vert = Category.first
if vert
@c_vertices = vert.roots.first.children
end
@c_vertices = Category.first.roots.first.children rescue []
end

def edit
@ontology = resource
@c_vertices = []
vert = Category.first
if vert
@c_vertices = vert.roots.first.children
end
@c_vertices = Category.first.roots.first.children rescue []
end

def update
Expand Down
2 changes: 2 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def initialize(user)
# TODO tests written?
subject.user == user || subject.metadatable.permission?(:editor, user)
end

can :read, Category
else
can :show, Repository do |subject|
!subject.is_private
Expand Down
22 changes: 13 additions & 9 deletions app/models/ontology/categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ module Ontology::Categories


def create_categories
if !self.is?('OWL')
raise Exception.new('Error: No OWL')
end
# Delete previous set of categories
[ Category.all, CEdge.all ].flatten.each { |c| c.destroy }
raise Exception.new('Error: No OWL') unless self.is? 'OWL'

# Delete previous set of categories.
[Category, CEdge].map(&:destroy_all)

classes = self.entities.select { |e| e.kind == 'Class' }
subclasses = self.sentences.select { |e| e.text.include?('SubClassOf')}
classes.each { |c| categorify(c) }
classes.map! { |c| categorify(c) }

subclasses = self.sentences.select { |e| e.text.include?('SubClassOf')}
subclasses.each do |s|
c1,c2 = s.hierarchical_class_names
c1, c2 = s.hierarchical_class_names

e1 = self.entities.where('name = ? OR iri = ?', c1, c1).first
e2 = self.entities.where('name = ? OR iri = ?', c2, c2).first
CEdge.create!(:child_id => categorify(e1).id, :parent_id => categorify(e2).id)

CEdge.create!(child_id: categorify(e1).id, parent_id: categorify(e2).id)
end
end


protected

def categorify(entity)
return if entity.kind != 'Class'
Category.where(name: entity.display_name || entity.name).
Expand Down
4 changes: 2 additions & 2 deletions app/models/ontology/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def delete_edges
end

def create_entity_tree
if !self.is?('OWL2')
raise Exception.new('Error: No OWL2')
if !self.is?('OWL')
raise Exception.new('Error: No OWL')
end

# Delete previous set of categories
Expand Down
4 changes: 2 additions & 2 deletions app/views/categories/_category.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- if category then
%li{ :id => category.id }
%li{:id => category.id}
%a
=link_to "#{category.name.gsub(/_/, ' ')} (#{category.related_ontologies.count})", category
= link_to "#{category.name.gsub(/_/, ' ')} (#{category.related_ontologies.count})", category
%ul
= render :partial => 'category', :collection => category.children.to_a
4 changes: 2 additions & 2 deletions app/views/categories/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%h2= @category.name
%h2= @category.name.gsub(/_/, ' ')

Following ontologies are in this category
%ul.ontology_list
-@ontologies.each do |ontology|
%li= fancy_link ontology
%li= fancy_link ontology
8 changes: 8 additions & 0 deletions app/views/shared/_form_errors.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- if resource.errors.any?
.flash.alert.alert-danger
%strong
= pluralize resource.errors.count, 'error'
prohibited this resource from being saved:
%ul
- resource.errors.full_messages.each do |msg|
%li= msg
2 changes: 1 addition & 1 deletion db/seeds/003-git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# Import ontologies
ontologies = %w[
owl/Domain_Fields_Extension.owl
owl/Domain_Fields_Core.owl
casl/partial_order.casl
casl/test1.casl
casl/test2.casl
Expand Down
2 changes: 2 additions & 0 deletions db/seeds/007-metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Create metadata objects (FormalityLevel, LicenseModel, OntologyType, Task).
Rake::Task['generate:metadata'].invoke
2 changes: 2 additions & 0 deletions db/seeds/008-categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Create categories from Domain_Fields_Core ontology.
Rake::Task['generate:categories'].invoke
2 changes: 1 addition & 1 deletion lib/tasks/generate.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace :generate do
desc 'Import the categories for the ontologies'
task :categories => :environment do
Ontology.find_by_name('Domain_fields_core').create_categories
Ontology.where("name ilike 'Domain_Fields_Core'").first.create_categories
end

desc 'Generate entity trees for ALL OWL ontologies'
Expand Down
20 changes: 19 additions & 1 deletion spec/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Category do

context "get ontologies of a category and subcategories" do
context 'get ontologies of a category and subcategories' do
before do
edge = FactoryGirl.create(:c_edge)

Expand All @@ -28,4 +28,22 @@
end
end

context 'creation of categories from ontology' do
before do
@user = FactoryGirl.create :user
@ontology = FactoryGirl.create :single_ontology
@ontology.import_xml_from_file fixture_file('Domain_Fields_Core.xml'),
fixture_file('Domain_Fields_Core.pp.xml'), @user
@ontology.create_categories
end

it 'should be the correct categories count' do
Category.count.should == 123
end

it 'should be the correct category edges count' do
CEdge.count.should == 122
end
end

end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def query_string

end

def fixture_file(name)
Rails.root + 'test/fixtures/ontologies/xml/' + name
end

RSpec.configure do |config|
# ## Mock Framework
# config.mock_with :mocha
Expand Down

0 comments on commit aeeca6f

Please sign in to comment.