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 +4 -4
- data/app/controllers/similar_terms_controller.rb +6 -4
- data/lib/iqvoc/similar_terms/version.rb +1 -1
- data/lib/iqvoc/similar_terms.rb +10 -0
- data/test/functional/api_test.rb +60 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5574670dcaae5eb644031cc3a3001e1ed27e5557
|
4
|
+
data.tar.gz: c17307ce55a94f9dd72b0929778a39fdac65d99f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
23
|
-
|
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
|
|
data/lib/iqvoc/similar_terms.rb
CHANGED
@@ -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
|
data/test/functional/api_test.rb
CHANGED
@@ -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.
|
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-
|
13
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: iqvoc
|