ur-sab 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +18 -0
- data/README.markdown +14 -0
- data/lib/ur-sab.rb +5 -0
- data/lib/ur/sab.rb +34 -0
- data/lib/ur/sab_codes.rb +25896 -0
- data/lib/ur/sab_search.rb +59 -0
- metadata +93 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'rsolr-ext'
|
|
2
|
+
require File.dirname(__FILE__) + '/sab'
|
|
3
|
+
|
|
4
|
+
module UR
|
|
5
|
+
class SabSearch
|
|
6
|
+
# Setup
|
|
7
|
+
if !defined?(SEARCH_SERVICE_URL)
|
|
8
|
+
SEARCH_SERVICE_URL = 'http://services.ur.se/search'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
attr_reader :solr, :sab, :subjects
|
|
12
|
+
|
|
13
|
+
def initialize(sab_code)
|
|
14
|
+
solr = RSolr.connect :url => SEARCH_SERVICE_URL
|
|
15
|
+
@sab = UR::Sab.new(sab_code) unless sab_code.nil?
|
|
16
|
+
|
|
17
|
+
response = solr.find({
|
|
18
|
+
:indent => 'on',
|
|
19
|
+
:qt => 'sab',
|
|
20
|
+
'facet.mincount' => 1,
|
|
21
|
+
'facet.limit' => -1,
|
|
22
|
+
'facet.prefix' => sab_code,
|
|
23
|
+
:q => '*:*',
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
# Expose the Solr response
|
|
27
|
+
@solr = response
|
|
28
|
+
|
|
29
|
+
facet_counts = Hash[*response['facet_counts']['facet_fields']['sab_subjects']]
|
|
30
|
+
|
|
31
|
+
sorted_subjects = facet_counts.keys.sort { |l,r| r <=> l }
|
|
32
|
+
reduced_facet_counts = {}
|
|
33
|
+
|
|
34
|
+
sorted_subjects.each_index do |j|
|
|
35
|
+
current_code = sorted_subjects[j]
|
|
36
|
+
next_code = sorted_subjects[j + 1]
|
|
37
|
+
count = facet_counts[current_code]
|
|
38
|
+
|
|
39
|
+
if !next_code.nil? && current_code.match(next_code)
|
|
40
|
+
if facet_counts[next_code] != count
|
|
41
|
+
reduced_facet_counts[current_code] = count
|
|
42
|
+
end
|
|
43
|
+
else
|
|
44
|
+
reduced_facet_counts[current_code] = count
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
@subjects = reduced_facet_counts.map { |code, count|
|
|
49
|
+
if (@sab.nil? && code.length == 1) ||
|
|
50
|
+
(!@sab.nil? && code.length < @sab.code.length+2) ||
|
|
51
|
+
(!@sab.nil? && code.match(/#{@sab.code}\.\d$/)) ||
|
|
52
|
+
(!@sab.nil? && code.match(/#{@sab.code}\:\w{1,2}$/))
|
|
53
|
+
sab = UR::Sab.new(code, count)
|
|
54
|
+
sab if sab.text
|
|
55
|
+
end
|
|
56
|
+
}.compact.sort { |l,r| l.code <=> r.code }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ur-sab
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 1
|
|
8
|
+
version: "0.1"
|
|
9
|
+
platform: ruby
|
|
10
|
+
authors:
|
|
11
|
+
- Peter Hellberg
|
|
12
|
+
autorequire:
|
|
13
|
+
bindir: bin
|
|
14
|
+
cert_chain: []
|
|
15
|
+
|
|
16
|
+
date: 2010-05-10 00:00:00 +02:00
|
|
17
|
+
default_executable:
|
|
18
|
+
dependencies:
|
|
19
|
+
- !ruby/object:Gem::Dependency
|
|
20
|
+
name: rsolr
|
|
21
|
+
prerelease: false
|
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
segments:
|
|
27
|
+
- 0
|
|
28
|
+
- 12
|
|
29
|
+
- 1
|
|
30
|
+
version: 0.12.1
|
|
31
|
+
type: :runtime
|
|
32
|
+
version_requirements: *id001
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: rsolr-ext
|
|
35
|
+
prerelease: false
|
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
segments:
|
|
41
|
+
- 0
|
|
42
|
+
- 12
|
|
43
|
+
- 0
|
|
44
|
+
version: 0.12.0
|
|
45
|
+
type: :runtime
|
|
46
|
+
version_requirements: *id002
|
|
47
|
+
description: Translates SAB codes to Swedish subject
|
|
48
|
+
email: peter@c7.se
|
|
49
|
+
executables: []
|
|
50
|
+
|
|
51
|
+
extensions: []
|
|
52
|
+
|
|
53
|
+
extra_rdoc_files: []
|
|
54
|
+
|
|
55
|
+
files:
|
|
56
|
+
- README.markdown
|
|
57
|
+
- MIT-LICENSE
|
|
58
|
+
- lib/ur-sab.rb
|
|
59
|
+
- lib/ur/sab.rb
|
|
60
|
+
- lib/ur/sab_codes.rb
|
|
61
|
+
- lib/ur/sab_search.rb
|
|
62
|
+
has_rdoc: true
|
|
63
|
+
homepage: http://github.com/c7/ur-sab
|
|
64
|
+
licenses:
|
|
65
|
+
- MIT-LICENSE
|
|
66
|
+
post_install_message:
|
|
67
|
+
rdoc_options: []
|
|
68
|
+
|
|
69
|
+
require_paths:
|
|
70
|
+
- lib
|
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
segments:
|
|
76
|
+
- 0
|
|
77
|
+
version: "0"
|
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
segments:
|
|
83
|
+
- 0
|
|
84
|
+
version: "0"
|
|
85
|
+
requirements: []
|
|
86
|
+
|
|
87
|
+
rubyforge_project: ur-sab
|
|
88
|
+
rubygems_version: 1.3.6
|
|
89
|
+
signing_key:
|
|
90
|
+
specification_version: 3
|
|
91
|
+
summary: Naive translation of SAB codes
|
|
92
|
+
test_files: []
|
|
93
|
+
|