iqvoc_similar_terms 0.5.3 → 0.6.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: e3ea57358c45c7cc868c3a44d141a5b2051b5db1
4
- data.tar.gz: 4ac8cbf661214eb8a5b616f6bbc192177306aab4
3
+ metadata.gz: 5574670dcaae5eb644031cc3a3001e1ed27e5557
4
+ data.tar.gz: c17307ce55a94f9dd72b0929778a39fdac65d99f
5
5
  SHA512:
6
- metadata.gz: 531a03c3dc4f6a7cf90d0757187fee0009d848df1a5ee2ab97a6c9530a40846a7515adde1ea1852d559680386435184b01b7a6776c2beb7f8f7677218a45bccc
7
- data.tar.gz: e621fa0f2d54c532955fbbfb9eddf340b1ed9c6edcf025c49510368a46a5cbf7717ae53dc3555d398a05a0094f9ff508b1d3d15f14b4fbd23b502d9109802b74
6
+ metadata.gz: 2dd41734dcbef3833adb297c7afb4a4de4f4639fafb9e208d775314c8f85c0085128cdb8e22870ff4061802ac6169af7077e5c875ea9e0ef003d90b4f7d6bbec
7
+ data.tar.gz: 1c75a25789b1f75eb0e821f6e9abd4c401d6df42bec6ccffb87006e638442f4d21cdd10b9f122af5fec17764791f7f23df00a59ddf229e867498f335c343d507
@@ -15,12 +15,14 @@ class SimilarTermsController < ApplicationController
15
15
  @terms = Iqvoc::InlineDataHelper.parse_inline_values(params[:terms])
16
16
  lang = params[:lang]
17
17
 
18
- @results = Iqvoc::SimilarTerms.ranked(lang, *@terms)
19
18
 
20
19
  respond_to do |format|
21
- format.html
22
- format.ttl
23
- format.rdf
20
+ format.any(:html, :ttl, :rdf) do
21
+ @results = Iqvoc::SimilarTerms.ranked(lang, *@terms)
22
+ end
23
+ format.text do
24
+ render :text => Iqvoc::SimilarTerms.alphabetical(lang, *@terms).join("\n")
25
+ end
24
26
  end
25
27
  end
26
28
 
@@ -1,5 +1,5 @@
1
1
  module Iqvoc
2
2
  module SimilarTerms
3
- VERSION = "0.5.3"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -42,6 +42,16 @@ module Iqvoc
42
42
  end
43
43
  end
44
44
 
45
+ # returns a list of labels, sorted alphabetically
46
+ def self.alphabetical(lang, *terms)
47
+ concepts = terms_to_concepts(lang, *terms).
48
+ includes(:labelings => [:owner, :target]).
49
+ where("labels.language" => lang) # applies language constraint to results
50
+ return concepts.map do |concept|
51
+ concept.labelings.map { |ln| ln.target }
52
+ end.flatten.sort_by { |label| label.value }
53
+ end
54
+
45
55
  def self.terms_to_concepts(lang, *terms)
46
56
  concept_ids = terms_to_labels(lang, *terms).includes(:labelings).
47
57
  map { |label| label.labelings.map(&:owner_id) }.flatten.uniq
@@ -49,6 +49,11 @@ class SimilarTermsTest < ActionController::TestCase
49
49
  EOS
50
50
  assert @response.body.include?(<<-EOS)
51
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.
52
57
  EOS
53
58
  assert @response.body.include?(<<-EOS)
54
59
  query:result1 a sdc:Result;
@@ -67,6 +72,61 @@ query:result2 a sdc:Result;
67
72
  EOS
68
73
  # ensure there are no duplicates
69
74
  assert_equal 2, @response.body.split("a skos:Concept").length
75
+
76
+ get :show, :lang => "en", :format => "ttl", :terms => "forest,automobile"
77
+ assert_response :success
78
+ 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.
105
+ EOS
106
+ assert @response.body.include?(<<-EOS)
107
+ query:result4 a sdc:Result;
108
+ rdfs:label "automobile"@en;
109
+ sdc:rank 4;
110
+ sdc:link :car.
111
+ 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
129
+ EOS
70
130
  end
71
131
 
72
132
  end
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.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederik Dohr
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-22 00:00:00.000000000 Z
13
+ date: 2013-04-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: iqvoc