iqvoc_similar_terms 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ab6e1a52bdf7c9b433aa8793ee99c7f33f9856c
4
- data.tar.gz: aa3a4dc8b7cd9e38220e9a3ca1691bec0081468e
3
+ metadata.gz: 678825bf98b35eb1efde46b62dee95e589153df3
4
+ data.tar.gz: fe480e5b3fc2c6cce66b23843a6ab87a41ea740f
5
5
  SHA512:
6
- metadata.gz: 03ff663565c62aced948707330dbee0f14029390fd3c6b233c531a27aafbdcc30aec72f714db7ce8b232bdf169b6f7351524ddf7ada1f2fe99e65ed8c9ea92b7
7
- data.tar.gz: 60d19cb18ae35ad602c4b21dc7d6240a9b98efd59fdddc4446144daf3075171b5913fe3ab4ff4b8f05d5c969430ba5499be96e4106b5dd29a686d849161008aa
6
+ metadata.gz: b24fbe1ac5958cc4df9d4d0959529faf8278d3127339cdd397710faa8ebfb15f619b18fea1c9bcae2197af4ec49c7971ff4e48d27d9eb40aeb9f856465a7434c
7
+ data.tar.gz: b575c7488f9c3a39f2529ab29254702f735af26d552119e9bfd0e5d2f1b549d73a5a8f45517f0acc4a70d4fc62661d9769ef656775fa52486e9fc5ec23fdab7e
@@ -17,11 +17,27 @@ class SimilarTermsController < ApplicationController
17
17
 
18
18
 
19
19
  respond_to do |format|
20
- format.any(:html, :ttl, :rdf) do
20
+ format.html do
21
21
  @results = Iqvoc::SimilarTerms.ranked(lang, *@terms)
22
22
  end
23
- format.text do
24
- render :text => Iqvoc::SimilarTerms.alphabetical(lang, *@terms).join("\n")
23
+ format.ttl do
24
+ @results = Iqvoc::SimilarTerms.alphabetical(lang, *@terms)
25
+
26
+ # manually generating Turtle here to allow users to process the data
27
+ # without requiring an RDF parser (not using IqRdf because it doesn't
28
+ # appear to support this format and we want to avoid subtle changes in
29
+ # the serialization).
30
+ query = url_for(request.query_parameters.
31
+ merge(:only_path => false, :anchor => ""))
32
+ literals = @results.
33
+ map { |label| IqRdf::Literal.new label.value, label.language }.
34
+ join(", ")
35
+ render :text => <<-rdf.strip
36
+ @prefix skos: <http://www.w3.org/2004/02/skos/core#>.
37
+ @prefix query: <#{query}>.
38
+
39
+ query:top skos:altLabel #{literals}.
40
+ rdf
25
41
  end
26
42
  end
27
43
  end
@@ -6,7 +6,6 @@
6
6
  <%= sidebar_item :icon => 'share', :text => 'HTML', :path => similar_path(:terms => params[:terms], :format => :html) %>
7
7
  <%= sidebar_item :icon => 'share', :text => 'RDF/XML', :path => similar_path(:terms => params[:terms], :format => :rdf) %>
8
8
  <%= sidebar_item :icon => 'share', :text => 'RDF/Turtle', :path => similar_path(:terms => params[:terms], :format => :ttl) %>
9
- <%= sidebar_item :icon => 'share', :text => 'text/plain', :path => similar_path(:terms => params[:terms], :format => :text) %>
10
9
  <% end %>
11
10
  <% end %>
12
11
 
@@ -1,5 +1,5 @@
1
1
  module Iqvoc
2
2
  module SimilarTerms
3
- VERSION = "0.6.1"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  module Iqvoc
2
2
  module SimilarTerms # TODO: make language constraints optional
3
3
 
4
- WEIGHTINGS = { # XXX: hard-coded - should be read from configuration
4
+ WEIGHTINGS = { # XXX: hard-coded - should be read from configuration -- XXX: unused/deprecated
5
5
  "Labeling::SKOS::PrefLabel" => 5,
6
6
  "Labeling::SKOS::AltLabel" => 2,
7
7
  "Labeling::SKOS::HiddenLabel" => 1,
@@ -11,13 +11,13 @@ module Iqvoc
11
11
  "Labeling::SKOSXL::HiddenLabel" => 1
12
12
  }
13
13
 
14
- # returns an array of label/concepts pairs, sorted descendingly by weighting
14
+ # returns an array of label/concepts pairs, sorted descendingly by weighting -- XXX: unused/deprecated
15
15
  def self.ranked(lang, *terms) # TODO: rename
16
16
  weighted(lang, *terms).sort_by { |label, data| data[0] }.reverse.
17
17
  map { |label, data| [label] + data[1..-1] } # drop weighting
18
18
  end
19
19
 
20
- # returns a hash of label/weighting+concepts pairs
20
+ # returns a hash of label/weighting+concepts pairs -- XXX: unused/deprecated
21
21
  def self.weighted(lang, *terms) # TODO: rename
22
22
  concepts = terms_to_concepts(lang, *terms).
23
23
  includes(:labelings => [:owner, :target]).
@@ -39,93 +39,25 @@ class SimilarTermsTest < ActionController::TestCase
39
39
  get :show, :lang => "en", :format => "ttl", :terms => "forest"
40
40
  assert_response :success
41
41
  assert @response.body.include?(<<-EOS)
42
- @prefix sdc: <http://sindice.com/vocab/search#>.
43
- EOS
44
- assert @response.body.include?(<<-EOS)
45
42
  @prefix skos: <http://www.w3.org/2004/02/skos/core#>.
46
43
  EOS
47
44
  assert @response.body.include?(<<-EOS)
48
45
  @prefix query: <http://test.host/en/similar.ttl?terms=forest#>.
49
46
  EOS
50
- assert @response.body.include?(<<-EOS)
51
- query:top a sdc:Query;
52
- sdc:totalResults 2;
53
- sdc:itemsPerPage 2;
54
- sdc:searchTerms ("forest");
55
- sdc:result query:result1;
56
- sdc:result query:result2.
57
- EOS
58
- assert @response.body.include?(<<-EOS)
59
- query:result1 a sdc:Result;
60
- rdfs:label "forest"@en;
61
- sdc:rank 1;
62
- sdc:link :forest.
47
+ assert @response.body.include?(<<-EOS.strip)
48
+ query:top skos:altLabel "forest"@en, "woods"@en.
63
49
  EOS
64
- assert @response.body.include?(<<-EOS)
65
- query:result2 a sdc:Result;
66
- rdfs:label "woods"@en;
67
- sdc:rank 2;
68
- sdc:link :forest.
69
- EOS
70
- assert @response.body.include?(<<-EOS)
71
- :forest a skos:Concept.
72
- EOS
73
- # ensure there are no duplicates
74
- assert_equal 2, @response.body.split("a skos:Concept").length
75
50
 
76
51
  get :show, :lang => "en", :format => "ttl", :terms => "forest,automobile"
77
52
  assert_response :success
78
53
  assert @response.body.include?(<<-EOS)
79
- query:top a sdc:Query;
80
- sdc:totalResults 4;
81
- sdc:itemsPerPage 4;
82
- sdc:searchTerms ("forest" "automobile");
83
- sdc:result query:result1;
84
- sdc:result query:result2;
85
- sdc:result query:result3;
86
- sdc:result query:result4.
87
- EOS
88
- assert @response.body.include?(<<-EOS)
89
- query:result1 a sdc:Result;
90
- rdfs:label "forest"@en;
91
- sdc:rank 1;
92
- sdc:link :forest.
93
- EOS
94
- assert @response.body.include?(<<-EOS)
95
- query:result2 a sdc:Result;
96
- rdfs:label "car"@en;
97
- sdc:rank 2;
98
- sdc:link :car.
99
- EOS
100
- assert @response.body.include?(<<-EOS)
101
- query:result3 a sdc:Result;
102
- rdfs:label "woods"@en;
103
- sdc:rank 3;
104
- sdc:link :forest.
54
+ @prefix skos: <http://www.w3.org/2004/02/skos/core#>.
105
55
  EOS
106
56
  assert @response.body.include?(<<-EOS)
107
- query:result4 a sdc:Result;
108
- rdfs:label "automobile"@en;
109
- sdc:rank 4;
110
- sdc:link :car.
57
+ @prefix query: <http://test.host/en/similar.ttl?terms=forest%2Cautomobile#>.
111
58
  EOS
112
- end
113
-
114
- test "plain text representation" do
115
- get :show, :lang => "en", :format => "text", :terms => "car"
116
- assert_response :success
117
- assert_equal @response.body, <<-EOS.strip
118
- automobile
119
- car
120
- EOS
121
-
122
- get :show, :lang => "en", :format => "text", :terms => "forest,automobile"
123
- assert_response :success
124
- assert_equal @response.body, <<-EOS.strip
125
- automobile
126
- car
127
- forest
128
- woods
59
+ assert @response.body.include?(<<-EOS.strip)
60
+ query:top skos:altLabel "automobile"@en, "car"@en, "forest"@en, "woods"@en.
129
61
  EOS
130
62
  end
131
63
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iqvoc_similar_terms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederik Dohr
@@ -41,7 +41,6 @@ files:
41
41
  - Rakefile
42
42
  - app/controllers/similar_terms_controller.rb
43
43
  - app/views/similar_terms/show.html.erb
44
- - app/views/similar_terms/show.iqrdf
45
44
  - config.ru
46
45
  - config/application.rb
47
46
  - config/boot.rb
@@ -1,41 +0,0 @@
1
- Iqvoc.default_rdf_namespace_helper_methods.each do |meth|
2
- document.namespaces(self.send(meth))
3
- end
4
-
5
- subject = url_for(request.query_parameters.
6
- merge(:only_path => false, :anchor => ""))
7
-
8
- document.namespaces(:sdc => "http://sindice.com/vocab/search#",
9
- :query => subject)
10
-
11
- document << IqRdf::Query.build_uri("top",
12
- IqRdf::Sdc::build_uri("Query")) do |query|
13
- query.Sdc::totalResults(@results.length)
14
- query.Sdc::itemsPerPage(@results.length) # XXX: preliminary
15
- query.Sdc::searchTerms(@terms)
16
-
17
- skos = IqRdf::Namespace.find_namespace_class("skos")
18
- processed_concepts = {} # XXX: crutch
19
- @results.each_with_index do |data, i|
20
- i += 1
21
-
22
- # XXX: data structure smell
23
- label = data[0]
24
- concepts = data[1..-1]
25
-
26
- result = "result#{i}"
27
- query.Sdc::result(IqRdf::Query::build_uri(result))
28
- document << IqRdf::Query::build_uri(result,
29
- IqRdf::Sdc::build_uri("Result")) do |sbj|
30
- sbj.Rdfs::label(label.value, :lang => label.language)
31
- sbj.Sdc::rank(i)
32
- concepts.each do |concept|
33
- sbj.Sdc::link(IqRdf.build_uri(concept.origin))
34
- unless processed_concepts[concept.origin]
35
- document << IqRdf.build_uri(concept.origin, skos.build_uri("Concept"))
36
- processed_concepts[concept.origin] = true
37
- end
38
- end
39
- end
40
- end
41
- end