iqvoc_similar_terms 0.8.0 → 2.11.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +67 -0
  3. data/.gitignore +11 -1
  4. data/Gemfile +14 -14
  5. data/Gemfile.lock +526 -146
  6. data/README.md +7 -12
  7. data/app/assets/javascripts/manifest.js +2 -0
  8. data/app/assets/stylesheets/manifest.scss +3 -0
  9. data/app/controllers/similar_terms_controller.rb +45 -12
  10. data/app/models/services/similar_terms_service.rb +141 -0
  11. data/app/views/similar_terms/_form.html.erb +21 -0
  12. data/app/views/similar_terms/new.html.erb +21 -0
  13. data/app/views/similar_terms/show.html.erb +32 -28
  14. data/app/views/similar_terms/show.xml.builder +17 -0
  15. data/bin/bundle +3 -0
  16. data/bin/rails +4 -0
  17. data/bin/rake +4 -0
  18. data/bin/setup +33 -0
  19. data/bin/update +31 -0
  20. data/bin/yarn +17 -0
  21. data/config/application.rb +30 -59
  22. data/config/boot.rb +3 -5
  23. data/config/cable.yml +10 -0
  24. data/config/database.yml.mysql +3 -3
  25. data/config/database.yml.postgresql +26 -0
  26. data/config/engine.rb +1 -1
  27. data/config/environment.rb +4 -4
  28. data/config/environments/development.rb +0 -1
  29. data/config/environments/test.rb +0 -1
  30. data/config/initializers/apipie.rb +5 -0
  31. data/config/initializers/content_security_policy.rb +25 -0
  32. data/config/initializers/filter_parameter_logging.rb +8 -0
  33. data/config/initializers/inflections.rb +16 -0
  34. data/config/initializers/iqvoc.rb +6 -4
  35. data/config/initializers/new_framework_defaults_6_1.rb +67 -0
  36. data/config/initializers/permissions_policy.rb +11 -0
  37. data/config/locales/de.yml +12 -0
  38. data/config/locales/en.yml +12 -0
  39. data/config/routes.rb +4 -7
  40. data/config/secrets.yml +8 -0
  41. data/config/storage.yml +34 -0
  42. data/config.ru +4 -2
  43. data/db/migrate/.gitkeep +0 -0
  44. data/faucet.config.js +46 -0
  45. data/iqvoc_similar_terms.gemspec +1 -2
  46. data/lib/iqvoc/similar_terms/version.rb +1 -1
  47. data/lib/iqvoc/similar_terms.rb +12 -71
  48. data/lib/iqvoc_similar_terms.rb +14 -1
  49. data/package-lock.json +1486 -0
  50. data/package.json +29 -0
  51. data/test/compound_forms.nt +20 -0
  52. data/test/concept_test.nt +25 -0
  53. data/test/concept_test.ttl +33 -0
  54. data/test/controllers/similar_terms_controller_test.rb +167 -0
  55. data/test/models/entity_resolution_test.rb +42 -0
  56. data/test/models/results_test.rb +105 -0
  57. data/test/similar_terms.nt +14 -0
  58. data/test/similar_terms.ttl +19 -0
  59. data/test/test_helper.rb +4 -0
  60. metadata +58 -25
  61. data/.travis.yml +0 -18
  62. data/config/initializers/secret_token.rb.template +0 -16
  63. data/config/initializers/wrap_parameters.rb +0 -14
  64. data/script/ci/travis-before-build +0 -19
  65. data/script/ci/travis-build +0 -11
  66. data/test/functional/api_test.rb +0 -68
  67. data/test/unit/entity_resolution_test.rb +0 -46
  68. data/test/unit/results_test.rb +0 -55
@@ -1,16 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # Be sure to restart your server when you modify this file.
4
-
5
- if Iqvoc::SimilarTerms.const_defined?(:Application)
6
-
7
- # Your secret key for verifying the integrity of signed cookies.
8
- # If you change this key, all old signed cookies will become invalid!
9
- # Make sure the secret is at least 30 characters and all random,
10
- # no regular words or you'll be exposed to dictionary attacks.
11
-
12
- # Run `rake secret` and uncomment the following line
13
- # Replace the secret-placeholder with your generated token
14
- Iqvoc::SimilarTerms::Application.config.secret_token = "S-E-C-R-E-T"
15
-
16
- end
@@ -1,14 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
- #
3
- # This file contains settings for ActionController::ParamsWrapper which
4
- # is enabled by default.
5
-
6
- # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
- ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters format: [:json]
9
- end
10
-
11
- # Disable root element in JSON by default.
12
- ActiveSupport.on_load(:active_record) do
13
- self.include_root_in_json = false
14
- end
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Start virtual X frame buffer
4
- system "sh -e /etc/init.d/xvfb start"
5
- sleep 3
6
-
7
- # Create a database.yml for the current database env
8
- puts "Setting up database.yml for #{ENV["DB"]}"
9
- system "cp config/database.yml.#{ENV["DB"]} config/database.yml"
10
-
11
- # Generate and copy secret token initializer
12
- secret = `bundle exec rake secret`.strip
13
- path = File.join(File.dirname(__FILE__), '../../config/initializers/')
14
- template = File.read(File.join(path, 'secret_token.rb.template'))
15
-
16
- template.gsub!('S-E-C-R-E-T', secret)
17
- File.open(File.join(path, 'secret_token.rb'), 'w') do |file|
18
- file.puts template
19
- end
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env sh
2
-
3
- set -e
4
- set -x
5
-
6
- env="RAILS_ENV=test"
7
-
8
- export DISPLAY=:99.0
9
- bundle exec rake db:drop db:create $env
10
- bundle exec rake db:migrate $env
11
- bundle exec rake test $env
@@ -1,68 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), '../test_helper')
4
- require 'iqvoc/rdfapi' # XXX: only required with Zeus
5
-
6
- class SimilarTermsTest < ActionController::TestCase
7
-
8
- setup do
9
- @controller = SimilarTermsController.new
10
-
11
- forest = Iqvoc::RDFAPI.devour("forest", "a", "skos:Concept") # FIXME: should be ":forest", but https://github.com/innoq/iqvoc/issues/195
12
- Iqvoc::RDFAPI.devour(forest, "skos:prefLabel", '"forest"@en')
13
- Iqvoc::RDFAPI.devour(forest, "skos:altLabel", '"woods"@en')
14
- forest.save
15
-
16
- car = Iqvoc::RDFAPI.devour("car", "a", "skos:Concept") # FIXME: should be ":car"; see above
17
- Iqvoc::RDFAPI.devour(car, "skos:prefLabel", '"car"@en')
18
- Iqvoc::RDFAPI.devour(car, "skos:altLabel", '"automobile"@en')
19
- car.save
20
- end
21
-
22
- test "routing" do
23
- assert_raises ActionController::RoutingError do
24
- get :show
25
- end
26
- assert_raises ActionController::RoutingError do
27
- get :show, :format => "ttl"
28
- end
29
-
30
- get :show, :lang => "en", :format => "ttl"
31
- assert_response 400
32
-
33
- get :show, :lang => "en", :format => "ttl", :terms => "foo"
34
- assert_response 200
35
- assert !@response.body.include?("skos:altLabel")
36
- end
37
-
38
- test "RDF representations" do
39
- get :show, :lang => "en", :format => "ttl", :terms => "forest"
40
- assert_response :success
41
- assert @response.body.include?(<<-EOS)
42
- @prefix skos: <http://www.w3.org/2004/02/skos/core#>.
43
- EOS
44
- assert @response.body.include?(<<-EOS)
45
- @prefix query: <http://test.host/en/similar.ttl?terms=forest#>.
46
- EOS
47
- assert @response.body.include?(<<-EOS.strip)
48
- query:top skos:altLabel "forest"@en;
49
- skos:altLabel "woods"@en.
50
- EOS
51
-
52
- get :show, :lang => "en", :format => "ttl", :terms => "forest,automobile"
53
- assert_response :success
54
- assert @response.body.include?(<<-EOS)
55
- @prefix skos: <http://www.w3.org/2004/02/skos/core#>.
56
- EOS
57
- assert @response.body.include?(<<-EOS)
58
- @prefix query: <http://test.host/en/similar.ttl?terms=forest%2Cautomobile#>.
59
- EOS
60
- assert @response.body.include?(<<-EOS.strip)
61
- query:top skos:altLabel "automobile"@en;
62
- skos:altLabel "car"@en;
63
- skos:altLabel "forest"@en;
64
- skos:altLabel "woods"@en.
65
- EOS
66
- end
67
-
68
- end
@@ -1,46 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), '../test_helper')
4
- require 'iqvoc/rdfapi' # XXX: only required with Zeus
5
- require 'iqvoc/similar_terms' # XXX: should not be necessary!?
6
-
7
- class EntityResolutionTest < ActiveSupport::TestCase
8
-
9
- setup do
10
- forest = Iqvoc::RDFAPI.devour(":forest", "a", "skos:Concept")
11
- Iqvoc::RDFAPI.devour(forest, "skos:prefLabel", '"forest"@en')
12
- Iqvoc::RDFAPI.devour(forest, "skos:altLabel", '"woods"@en')
13
- forest.save
14
- end
15
-
16
- test "concept resolution" do
17
- concepts = Iqvoc::SimilarTerms.terms_to_concepts("en","forest")
18
- assert_equal 1, concepts.length
19
- assert_equal Iqvoc::Concept.base_class, concepts[0].class
20
-
21
- concepts = Iqvoc::SimilarTerms.terms_to_concepts("de","forest")
22
- assert_equal 0, concepts.count
23
-
24
- concepts = Iqvoc::SimilarTerms.terms_to_concepts("en", "foo")
25
- assert_equal 0, concepts.count
26
- end
27
-
28
- test "label resolution" do
29
- labels = Iqvoc::SimilarTerms.terms_to_labels("en", "forest")
30
- assert_equal ActiveRecord::Relation, labels.class
31
- labels = labels.all
32
- assert_equal 1, labels.length
33
- assert_equal Iqvoc::Label.base_class, labels[0].class
34
- assert_equal "forest", labels[0].value
35
- assert_equal "en", labels[0].language
36
-
37
- labels = Iqvoc::SimilarTerms.terms_to_labels("de", "forest")
38
- assert_equal 0, labels.count
39
-
40
- labels = Iqvoc::SimilarTerms.terms_to_labels("en", "foo")
41
- assert_equal 0, labels.count
42
-
43
- # TODO: test XLLabel and Inflectional variants
44
- end
45
-
46
- end
@@ -1,55 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), '../test_helper')
4
- require 'iqvoc/rdfapi' # XXX: only required with Zeus
5
- require 'iqvoc/similar_terms' # XXX: should not be necessary!?
6
-
7
- class ResultsTest < ActiveSupport::TestCase
8
-
9
- setup do
10
- forest = Iqvoc::RDFAPI.devour(":forest", "a", "skos:Concept")
11
- Iqvoc::RDFAPI.devour(forest, "skos:prefLabel", '"forest"@en')
12
- Iqvoc::RDFAPI.devour(forest, "skos:altLabel", '"woods"@en')
13
- forest.save
14
-
15
- car = Iqvoc::RDFAPI.devour(":car", "a", "skos:Concept")
16
- Iqvoc::RDFAPI.devour(car, "skos:prefLabel", '"car"@en')
17
- Iqvoc::RDFAPI.devour(car, "skos:altLabel", '"automobile"@en')
18
- car.save
19
- end
20
-
21
- test "ranked results" do
22
- results = Iqvoc::SimilarTerms.ranked("en", "forest")
23
- assert_equal 2, results.length
24
- assert_equal Iqvoc::Label.base_class, results[0][0].class
25
- assert_equal "forest", results[0][0].value
26
- assert_equal ":forest", results[0][1].origin
27
- assert_equal "woods", results[1][0].value
28
- assert_equal ":forest", results[1][1].origin
29
-
30
- results = Iqvoc::SimilarTerms.ranked("en", "woods", "car")
31
- assert_equal 4, results.length
32
- assert_equal "forest", results[0][0].value
33
- assert_equal ":forest", results[0][1].origin
34
- assert_equal "car", results[1][0].value
35
- assert_equal ":car", results[1][1].origin
36
- assert_equal "woods", results[2][0].value
37
- assert_equal ":forest", results[2][1].origin
38
- assert_equal "automobile", results[3][0].value
39
- assert_equal ":car", results[3][1].origin
40
- assert_equal results[0].length, results[0].uniq.length
41
- end
42
-
43
- test "weighted results" do
44
- results = Iqvoc::SimilarTerms.weighted("en", "forest")
45
- assert_equal 2, results.keys.length
46
- expected = { "forest" => 5, "woods" => 2 }
47
- results.each do |label, data|
48
- assert_equal Iqvoc::Label.base_class, label.class
49
- assert_equal 2, data.length
50
- assert_equal expected[label.value], data[0]
51
- assert_equal Iqvoc::Concept.base_class, data[1].class
52
- end
53
- end
54
-
55
- end