iqvoc_inflectionals 2.1.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- Inflectionals for iQvoc
1
+ [![Build Status](https://travis-ci.org/innoq/iqvoc_inflectionals.svg?branch=master)](https://travis-ci.org/innoq/iqvoc_inflectionals)
2
2
 
3
+ Inflectionals for iQvoc
3
4
 
4
5
  Getting Started
5
6
  ===============
@@ -7,7 +8,3 @@ Getting Started
7
8
  1. Initialize database:
8
9
 
9
10
  $ rake db:create iqvoc:db:migrate_all iqvoc:db:seed_all
10
-
11
- 2. Generate secret token:
12
-
13
- $ rake iqvoc:setup:generate_secret_token
@@ -0,0 +1,2 @@
1
+ @import 'framework';
2
+ @import 'iqvoc/manifest';
@@ -0,0 +1,67 @@
1
+ module Inflectionable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ attr_reader :inflectionals_attributes
6
+ after_save :overwrite_inflectionals!
7
+ after_save :create_default_inflectional
8
+
9
+ has_many :inflectionals,
10
+ :class_name => "Inflectional::Base",
11
+ :foreign_key => "label_id",
12
+ :dependent => :destroy
13
+ end
14
+
15
+ def endings
16
+ Inflectional::Base.for_language_and_code(language, inflectional_code)
17
+ end
18
+
19
+ def generate_inflectionals!
20
+ return send(Inflectional::Base.name.to_relation_name) if base_form.blank?
21
+
22
+ converted_literal_form = Iqvoc::Origin.new(value).to_s
23
+
24
+ diff = Iqvoc::Origin.new(converted_literal_form).sanitize_base_form.to_s.size - base_form.size
25
+
26
+ unless base_form.blank?
27
+ new_base_form = converted_literal_form[0..(base_form.length-1)]
28
+ end
29
+
30
+ Rails.logger.debug "converted_literal_form => #{converted_literal_form} (#{converted_literal_form.size}) |
31
+ base_form => #{base_form} (#{base_form.size}) |
32
+ new_base_form => #{new_base_form} |
33
+ value => #{value} (#{value.size}) |
34
+ diff => #{diff}"
35
+
36
+ endings.each do |ending|
37
+ value = ending == "." ? new_base_form : (new_base_form + ending.downcase)
38
+ send(Inflectional::Base.name.to_relation_name).create!(:value => value)
39
+ end
40
+
41
+ self.base_form = new_base_form
42
+ save(:validate => false)
43
+
44
+ inflectionals
45
+ end
46
+
47
+ def inflectionals_attributes=(str)
48
+ @inflectionals_attributes = str.split("\r\n")
49
+ end
50
+
51
+ def overwrite_inflectionals!
52
+ return unless inflectionals_attributes
53
+ transaction do
54
+ inflectionals.delete_all
55
+ inflectionals_attributes.each do |value|
56
+ inflectionals.create!(:value => value)
57
+ end
58
+ end
59
+ end
60
+
61
+ def create_default_inflectional
62
+ # ensure a matching inflectional exists
63
+ if value && inflectionals.where(:value => value).none?
64
+ inflectionals.create(:value => value)
65
+ end
66
+ end
67
+ end
@@ -1,17 +1,18 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'digest/md5'
4
+ require 'iqvoc/rdfapi'
4
5
 
5
6
  class Inflectional::Base < ActiveRecord::Base
6
7
 
7
8
  class_attribute :rdf_namespace, :rdf_predicate
8
- self.rdf_namespace = 'umt'
9
+ self.rdf_namespace = 'iqvoc'
9
10
  self.rdf_predicate = 'inflectional'
10
11
 
11
12
  self.table_name ='inflectionals'
12
13
 
13
14
  validates :value, :presence => true
14
- validates :label_id, :presence => true
15
+ # validates :label_id, :presence => true
15
16
 
16
17
  belongs_to :label, :class_name => Iqvoc::XLLabel.base_class_name
17
18
 
@@ -19,6 +20,21 @@ class Inflectional::Base < ActiveRecord::Base
19
20
  self.normal_hash = self.class.normalize(self.value)
20
21
  end
21
22
 
23
+ def self.build_from_rdf(subject, predicate, object)
24
+ unless object =~ Iqvoc::RDFAPI::LITERAL_REGEXP
25
+ raise InvalidStringLiteralError, "#{self.name}#build_from_rdf: Object (#{object}) must be a string literal"
26
+ end
27
+
28
+ lang = $3
29
+ value = begin
30
+ JSON.parse(%Q{["#{$1}"]})[0].gsub("\\n", "\n") # Trick to decode \uHHHHH chars
31
+ rescue JSON::ParserError
32
+ $1
33
+ end
34
+
35
+ where(:label => subject, :value => value).first_or_create
36
+ end
37
+
22
38
  def self.by_query_value(query)
23
39
  where(["LOWER(#{table_name}.value) LIKE ?", query.to_s.downcase])
24
40
  end
@@ -289,8 +305,9 @@ class Inflectional::Base < ActiveRecord::Base
289
305
  def self.single_query(params = {})
290
306
  query_str = build_query_string(params)
291
307
 
292
- by_query_value(query_str).
293
- includes(:label).merge(Label::UMT::Base.by_language(params[:languages].to_a).published.order("LOWER(#{Label::Base.table_name}.value)"))
308
+ scope = by_query_value(query_str).includes(:label)
309
+ scope = scope.references(:labels).merge(Label::UMT::Base.by_language(params[:languages].to_a).published.order("LOWER(#{Label::Base.table_name}.value)"))
310
+ scope.map { |result| SearchResult.new(result) }
294
311
  end
295
312
 
296
313
  # def self.single_query(params = {})
@@ -310,7 +327,7 @@ class Inflectional::Base < ActiveRecord::Base
310
327
 
311
328
  def self.referenced_by(label_class)
312
329
  # To something with the label class
313
- label_class.send(:include, Iqvoc::Inflectionals::LabelExtensions)
330
+ label_class.send(:include, Inflectionable)
314
331
  end
315
332
 
316
333
  def self.deep_cloning_relations
@@ -334,12 +351,11 @@ class Inflectional::Base < ActiveRecord::Base
334
351
  end
335
352
 
336
353
  def build_rdf(document, subject)
337
- subject.Umt.inflectional(value, :lang => label.language)
354
+ subject.send(rdf_namespace).send(rdf_predicate, value, :lang => label.language)
338
355
  end
339
356
 
340
357
  def self.normalize(str)
341
- str = str.to_s.mb_chars.downcase
342
- Digest::MD5.hexdigest(str)
358
+ Digest::MD5.hexdigest(str.to_s.mb_chars.downcase)
343
359
  end
344
360
 
345
361
  end
@@ -1,8 +1,5 @@
1
- <%= f.input :inflectionals_attributes,
2
- :as => :text,
3
- :label => t("txt.views.labels.inflectionals"),
4
- :value => label.send(klass.name.to_relation_name).map(&:value).join("\n"),
5
- :input_html => {
1
+ <%= f.text_area :inflectionals_attributes,
2
+ :label => t("txt.views.labels.inflectionals"),
3
+ :value => label.send(klass.name.to_relation_name).map(&:value).join("\n"),
6
4
  :rows => 10,
7
- :cols => 40
8
- } %>
5
+ :cols => 80 %>
@@ -6,7 +6,9 @@
6
6
  <%= t("txt.views.search_results.no_results") %>
7
7
  <% else %>
8
8
  <% result[:result].group_by{|i| i.label}.each do |key, value| %>
9
- <%= link_to(key.value, label_path(:id => key)) %> (<%= value.map(&:value).join(", ") %>)<br>
9
+ <% concept = key.concepts_for_labeling_class(Labeling::SKOSXL::PrefLabel).try(:first) %>
10
+ <% concept_path = concept ? concept_path(:id => concept.origin) : '' %>
11
+ <%= link_to(key.value, label_path(:id => key), :data => { 'pref-label-for' => concept_path }) %> (<%= value.map(&:value).join(", ") %>)<br>
10
12
  <% end %>
11
13
  <% end %>
12
14
  </span>
data/bin/rails ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
7
+
8
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
9
+ require File.expand_path('../../config/boot', __FILE__)
10
+ require 'rails/commands'
data/bin/rake ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ require 'bundler/setup'
7
+ load Gem.bin_path('rake', 'rake')
data/bin/spring ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This file loads spring without using Bundler, in order to be fast
4
+ # It gets overwritten when you run the `spring binstub` command
5
+
6
+ unless defined?(Spring)
7
+ require "rubygems"
8
+ require "bundler"
9
+
10
+ if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
11
+ ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
12
+ ENV["GEM_HOME"] = ""
13
+ Gem.paths = ENV
14
+
15
+ gem "spring", match[1]
16
+ require "spring/binstub"
17
+ end
18
+ end
@@ -1,20 +1,20 @@
1
1
  development:
2
2
  adapter: mysql2
3
- database: iqvoc_skosxl_development
3
+ database: iqvoc_inflectionals_development
4
4
  username: root
5
5
  password:
6
6
  encoding: utf8
7
7
 
8
8
  test:
9
9
  adapter: mysql2
10
- database: iqvoc_skosxl_test
10
+ database: iqvoc_inflectionals_test
11
11
  username: root
12
12
  password:
13
13
  encoding: utf8
14
14
 
15
15
  production:
16
16
  adapter: mysql2
17
- database: iqvoc_skosxl_production
17
+ database: iqvoc_inflectionals_production
18
18
  username: root
19
19
  password:
20
20
  encoding: utf8
data/config/engine.rb CHANGED
@@ -7,7 +7,7 @@ module Iqvoc
7
7
  paths["lib/tasks"] << "lib/engine_tasks"
8
8
 
9
9
  initializer "iqvoc_inflectionals.load_migrations" do |app|
10
- app.config.paths['db/migrate'] += Iqvoc::Inflectionals::Engine.paths['db/migrate'].existent
10
+ app.config.paths['db/migrate'].concat(Iqvoc::Inflectionals::Engine.paths['db/migrate'].existent)
11
11
  end
12
12
  end
13
13
 
@@ -1,4 +1,3 @@
1
- require 'debug'
2
1
  require 'iqvoc/environments/development'
3
2
 
4
3
  if Iqvoc::Inflectionals.const_defined?(:Application)
@@ -1,4 +1,3 @@
1
- require 'debug'
2
1
  require 'iqvoc/environments/test'
3
2
 
4
3
  if Iqvoc::Inflectionals.const_defined?(:Application)
@@ -1,10 +1,13 @@
1
1
  # initializer for both iqvoc and iqvoc_skosxl
2
2
 
3
- require 'iqvoc/xllabel' # XXX: this basically duplicates iqvoc_skosxl's initializer - but is required to ensure correct loading order!?
3
+ # This basically duplicates iqvoc_skosxl's initializer
4
+ # but is required to ensure correct loading order!?
5
+ require 'iqvoc/xllabel'
4
6
 
5
7
  Iqvoc.config.register_setting("title", "iQvoc Inflectionals")
6
8
 
7
- #Iqvoc.searchable_class_names << "Inflectional::Base" # XXX: application's responsibility!?
9
+ # Application's responsibility!
10
+ # Iqvoc.searchable_class_names << "Inflectional::Base"
8
11
 
9
12
  Iqvoc::XLLabel.additional_association_class_names.
10
13
  merge!("Inflectional::Base" => "label_id")
@@ -0,0 +1,11 @@
1
+ development:
2
+ secret_key_base: development
3
+
4
+ test:
5
+ secret_key_base: test
6
+
7
+ production:
8
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
9
+
10
+ heroku:
11
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -15,11 +15,10 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.rubyforge_project = "iqvoc_inflectionals"
17
17
 
18
- s.add_dependency "iqvoc", "~> 4.1.0"
19
- s.add_dependency "iqvoc_skosxl", "~> 2.1.0"
18
+ s.add_dependency "iqvoc", ">= 4.5.0", "~> 4.6"
19
+ s.add_dependency "iqvoc_skosxl", "~> 2.5.0"
20
20
 
21
21
  s.files = `git ls-files`.split("\n")
22
22
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
- s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
24
23
  s.require_paths = ["lib"]
25
24
  end
@@ -1,5 +1,5 @@
1
1
  module Iqvoc
2
2
  module Inflectionals
3
- VERSION = "2.1.0"
3
+ VERSION = "2.5.0"
4
4
  end
5
5
  end
@@ -0,0 +1,10 @@
1
+ # encoding: UTF-8
2
+
3
+ namespace :iqvoc_inflectionals do
4
+ desc "Generate inflectionals based on a mapping table in the Inflectional model class."
5
+ task :generate_inflectionals => :environment do
6
+ Iqvoc::XLLabel.base_class.find_each do |label|
7
+ label.generate_inflectionals!
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ <http://hobbies.com/computer_programming> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept> .
2
+ <http://hobbies.com/computer_programming> <http://www.w3.org/2004/02/skos/core#prefLabel> "Computer programming"@en .
3
+ <http://hobbies.com/computer_programming> <http://www.w3.org/2008/05/skos-xl#prefLabel> <http://hobbies.com/computer_programming-xl-preflabel-en> .
4
+ <http://hobbies.com/computer_programming-xl-preflabel-en> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2008/05/skos-xl#Label> .
5
+ <http://hobbies.com/computer_programming-xl-preflabel-en> <http://www.w3.org/2008/05/skos-xl#literalForm> "Computer programming (used as xl:prefLabel)"@en .
6
+ <http://hobbies.com/computer_programming-xl-preflabel-en> <http://try.iqvoc.net/schema#inflectional> "Computer programmings"@en .
7
+ <http://hobbies.com/computering> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2008/05/skos-xl#Label> .
8
+ <http://hobbies.com/computering> <http://www.w3.org/2008/05/skos-xl#literalForm> "Computering"@en .
9
+ <http://hobbies.com/nerding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2008/05/skos-xl#Label> .
10
+ <http://hobbies.com/nerding> <http://www.w3.org/2008/05/skos-xl#literalForm> "Nerding"@en .
11
+ <http://hobbies.com/nerding> <http://try.iqvoc.net/schema#inflectional> "Nerding"@en .
data/test/test_helper.rb CHANGED
@@ -1,3 +1,3 @@
1
- ENV["RAILS_ENV"] = "test"
1
+ ENV["RAILS_ENV"] ||= "test"
2
2
  require File.expand_path('../../config/environment', __FILE__)
3
3
  require 'rails/test_help'
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), '../test_helper')
4
+ require "iqvoc/skos_importer"
5
+
6
+ class ImportTest < ActiveSupport::TestCase
7
+ TEST_DATA = File.open(File.expand_path("../../fixtures/hobbies.nt", __FILE__))
8
+
9
+ setup do
10
+ @importer = Iqvoc::SkosImporter.new(TEST_DATA, "http://hobbies.com/")
11
+ end
12
+
13
+ test "import inflectionals" do
14
+ assert_difference "Concept::SKOS::Base.count" do
15
+ @importer.run
16
+ end
17
+
18
+ concept = Concept::SKOS::Base.first
19
+
20
+ assert_equal 2, concept.pref_labels.first.inflectionals.count
21
+ assert_equal 1, concept.pref_labels.first.inflectionals.where(:value => "Computer programming (used as xl:prefLabel)").count
22
+ assert_equal 1, concept.pref_labels.first.inflectionals.where(:value => "Computer programmings").count
23
+
24
+ nerding = Label::SKOSXL::Base.where(:origin => "nerding").first
25
+
26
+ # test for duplicate inflectionals not getting created
27
+ assert_not_nil nerding
28
+ assert_equal 1, nerding.inflectionals.count
29
+ assert_equal "Nerding", nerding.inflectionals.first.value
30
+ end
31
+
32
+ end
@@ -24,10 +24,6 @@ class InflectionalTest < ActiveSupport::TestCase
24
24
  end
25
25
 
26
26
  assert_equal @words.count, Inflectional::Base.count
27
- Inflectional::Base.all.each do |inflectional|
28
- normalized = Inflectional::Base.normalize(inflectional.value)
29
- assert_equal normalized, inflectional.normal_hash
30
- end
31
27
  end
32
28
 
33
29
  test "base form sanitizer extension for origin generator" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iqvoc_inflectionals
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Glaser
@@ -10,36 +10,42 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-17 00:00:00.000000000 Z
13
+ date: 2014-10-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: iqvoc
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ~>
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 4.1.0
21
+ version: 4.5.0
22
+ - - "~>"
23
+ - !ruby/object:Gem::Version
24
+ version: '4.6'
22
25
  type: :runtime
23
26
  prerelease: false
24
27
  version_requirements: !ruby/object:Gem::Requirement
25
28
  requirements:
26
- - - ~>
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 4.5.0
32
+ - - "~>"
27
33
  - !ruby/object:Gem::Version
28
- version: 4.1.0
34
+ version: '4.6'
29
35
  - !ruby/object:Gem::Dependency
30
36
  name: iqvoc_skosxl
31
37
  requirement: !ruby/object:Gem::Requirement
32
38
  requirements:
33
- - - ~>
39
+ - - "~>"
34
40
  - !ruby/object:Gem::Version
35
- version: 2.1.0
41
+ version: 2.5.0
36
42
  type: :runtime
37
43
  prerelease: false
38
44
  version_requirements: !ruby/object:Gem::Requirement
39
45
  requirements:
40
- - - ~>
46
+ - - "~>"
41
47
  - !ruby/object:Gem::Version
42
- version: 2.1.0
48
+ version: 2.5.0
43
49
  description: ''
44
50
  email:
45
51
  - robert.glaser@innoq.com
@@ -47,16 +53,21 @@ executables: []
47
53
  extensions: []
48
54
  extra_rdoc_files: []
49
55
  files:
50
- - .gitignore
51
- - .travis.yml
56
+ - ".gitignore"
57
+ - ".travis.yml"
52
58
  - Gemfile
53
59
  - Gemfile.lock
54
60
  - README.md
55
61
  - Rakefile
62
+ - app/assets/stylesheets/manifest.css.scss
63
+ - app/models/concerns/inflectionable.rb
56
64
  - app/models/inflectional/base.rb
57
65
  - app/views/partials/inflectional/_base.html.erb
58
66
  - app/views/partials/inflectional/_edit_base.html.erb
59
67
  - app/views/partials/inflectional/_search_result.html.erb
68
+ - bin/rails
69
+ - bin/rake
70
+ - bin/spring
60
71
  - config.ru
61
72
  - config/application.rb
62
73
  - config/boot.rb
@@ -69,29 +80,27 @@ files:
69
80
  - config/environments/production.rb
70
81
  - config/environments/test.rb
71
82
  - config/initializers/iqvoc.rb
72
- - config/initializers/label_extensions.rb
73
83
  - config/initializers/origin_filters.rb
74
- - config/initializers/secret_token.rb.template
75
84
  - config/initializers/session_store.rb
76
85
  - config/locales/activerecord.de.yml
77
86
  - config/locales/activerecord.en.yml
78
87
  - config/locales/de.yml
79
88
  - config/locales/en.yml
80
89
  - config/routes.rb
90
+ - config/secrets.yml
81
91
  - db/migrate/20120109143704_create_inflectionals.rb
82
- - db/schema.rb
83
92
  - db/seeds.rb
84
93
  - iqvoc_inflectionals.gemspec
85
94
  - lib/engine_tasks/db.rake
86
95
  - lib/iqvoc/inflectionals/base_form_sanitizer.rb
87
- - lib/iqvoc/inflectionals/label_extensions.rb
88
96
  - lib/iqvoc/inflectionals/version.rb
89
97
  - lib/iqvoc_inflectionals.rb
98
+ - lib/tasks/inflectionals.rake
90
99
  - public/.gitkeep
91
- - script/ci/travis-before-build
92
- - script/ci/travis-build
93
100
  - script/rails
101
+ - test/fixtures/hobbies.nt
94
102
  - test/test_helper.rb
103
+ - test/unit/import_test.rb
95
104
  - test/unit/inflectional_test.rb
96
105
  homepage: ''
97
106
  licenses: []
@@ -102,20 +111,22 @@ require_paths:
102
111
  - lib
103
112
  required_ruby_version: !ruby/object:Gem::Requirement
104
113
  requirements:
105
- - - '>='
114
+ - - ">="
106
115
  - !ruby/object:Gem::Version
107
116
  version: '0'
108
117
  required_rubygems_version: !ruby/object:Gem::Requirement
109
118
  requirements:
110
- - - '>='
119
+ - - ">="
111
120
  - !ruby/object:Gem::Version
112
121
  version: '0'
113
122
  requirements: []
114
123
  rubyforge_project: iqvoc_inflectionals
115
- rubygems_version: 2.0.0
124
+ rubygems_version: 2.4.2
116
125
  signing_key:
117
126
  specification_version: 4
118
127
  summary: ''
119
128
  test_files:
129
+ - test/fixtures/hobbies.nt
120
130
  - test/test_helper.rb
131
+ - test/unit/import_test.rb
121
132
  - test/unit/inflectional_test.rb