enju_loc 0.1.0.pre1
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +38 -0
- data/app/assets/javascripts/loc_search.js +2 -0
- data/app/assets/stylesheets/loc_search.css +4 -0
- data/app/controllers/loc_search_controller.rb +49 -0
- data/app/helpers/loc_search_helper.rb +18 -0
- data/app/models/loc_search.rb +97 -0
- data/app/views/loc_search/index.html.erb +49 -0
- data/config/locales/en.yml +13 -0
- data/config/locales/ja.yml +11 -0
- data/config/routes.rb +3 -0
- data/lib/enju_loc.rb +21 -0
- data/lib/enju_loc/engine.rb +7 -0
- data/lib/enju_loc/loc_search.rb +537 -0
- data/lib/enju_loc/version.rb +3 -0
- data/lib/tasks/enju_loc_tasks.rake +4 -0
- data/spec/cassette_library/LocSearch/_ModsRecord/should_parse_MODS_metadata.yml +111 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_create_a_valid_manifestation.yml +113 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_create_lcsh_subjects_only.yml +66 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_create_multiple_series_statements.yml +69 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_distinguish_title_information_with_subject.yml +67 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_a_manifestation_that_has_invalid_classification.yml +81 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_another_serial.yml +85 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_audio_book.yml +91 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_e-resource.yml +73 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_note_fields.yml +72 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_publication_year.yml +78 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_serial.yml +70 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_video_publication.yml +204 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_parse_title_information_properly.yml +80 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_support_name_and_title_subjects.yml +77 -0
- data/spec/cassette_library/LocSearch/_search/should_return_a_search_result.yml +353 -0
- data/spec/cassette_library/LocSearchController/GET_index/should_get_index.yml +353 -0
- data/spec/cassette_library/LocSearchController/GET_index/should_get_index_with_page_parameter.yml +415 -0
- data/spec/cassette_library/LocSearchController/POST_create/should_create_a_bibliographic_record_if_lccn_is_set.yml +140 -0
- data/spec/cassette_library/LocSearchController/POST_create/should_not_create_a_bibliographic_record_if_lccn_is_not_set.yml +38 -0
- data/spec/controllers/loc_search_controller_spec.rb +44 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/setting.rb +4 -0
- data/spec/dummy/app/models/user.rb +8 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +47 -0
- data/spec/dummy/config/application.yml +38 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/devise.rb +207 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/001_create_agents.rb +50 -0
- data/spec/dummy/db/migrate/002_devise_create_users.rb +46 -0
- data/spec/dummy/db/migrate/005_create_manifestations.rb +44 -0
- data/spec/dummy/db/migrate/006_create_items.rb +21 -0
- data/spec/dummy/db/migrate/012_create_owns.rb +12 -0
- data/spec/dummy/db/migrate/015_create_creates.rb +12 -0
- data/spec/dummy/db/migrate/029_create_subjects.rb +27 -0
- data/spec/dummy/db/migrate/041_create_roles.rb +13 -0
- data/spec/dummy/db/migrate/047_create_produces.rb +12 -0
- data/spec/dummy/db/migrate/059_create_libraries.rb +28 -0
- data/spec/dummy/db/migrate/069_create_shelves.rb +15 -0
- data/spec/dummy/db/migrate/073_create_carrier_types.rb +11 -0
- data/spec/dummy/db/migrate/077_create_user_groups.rb +12 -0
- data/spec/dummy/db/migrate/080_create_library_groups.rb +17 -0
- data/spec/dummy/db/migrate/112_create_frequencies.rb +12 -0
- data/spec/dummy/db/migrate/117_create_form_of_works.rb +12 -0
- data/spec/dummy/db/migrate/120_create_baskets.rb +12 -0
- data/spec/dummy/db/migrate/124_create_bookstores.rb +17 -0
- data/spec/dummy/db/migrate/125_create_donates.rb +12 -0
- data/spec/dummy/db/migrate/130_create_request_status_types.rb +12 -0
- data/spec/dummy/db/migrate/131_create_request_types.rb +12 -0
- data/spec/dummy/db/migrate/142_create_classifications.rb +19 -0
- data/spec/dummy/db/migrate/144_create_classification_types.rb +16 -0
- data/spec/dummy/db/migrate/145_create_subject_heading_types.rb +16 -0
- data/spec/dummy/db/migrate/146_create_subject_types.rb +16 -0
- data/spec/dummy/db/migrate/20080830154109_create_realizes.rb +13 -0
- data/spec/dummy/db/migrate/20080830172106_create_exemplifies.rb +13 -0
- data/spec/dummy/db/migrate/20080905191442_create_agent_types.rb +12 -0
- data/spec/dummy/db/migrate/20081006090811_create_subscriptions.rb +17 -0
- data/spec/dummy/db/migrate/20081006093246_create_subscribes.rb +14 -0
- data/spec/dummy/db/migrate/20081023092436_create_search_engines.rb +17 -0
- data/spec/dummy/db/migrate/20081025083323_create_countries.rb +28 -0
- data/spec/dummy/db/migrate/20081025083905_create_languages.rb +23 -0
- data/spec/dummy/db/migrate/20081027150907_create_picture_files.rb +15 -0
- data/spec/dummy/db/migrate/20081028083142_create_agent_import_files.rb +20 -0
- data/spec/dummy/db/migrate/20081028083208_create_resource_import_files.rb +20 -0
- data/spec/dummy/db/migrate/20090705133942_add_attachments_picture_to_picture_file.rb +15 -0
- data/spec/dummy/db/migrate/20090705212043_add_attachments_attachment_to_manifestation.rb +15 -0
- data/spec/dummy/db/migrate/20090719201843_create_extents.rb +12 -0
- data/spec/dummy/db/migrate/20090720091106_create_medium_of_performances.rb +12 -0
- data/spec/dummy/db/migrate/20090720091429_create_content_types.rb +12 -0
- data/spec/dummy/db/migrate/20090812151902_create_agent_relationship_types.rb +12 -0
- data/spec/dummy/db/migrate/20091012101112_add_dcndl_schema.rb +27 -0
- data/spec/dummy/db/migrate/20091025080447_create_licenses.rb +12 -0
- data/spec/dummy/db/migrate/20091202124834_create_versions.rb +18 -0
- data/spec/dummy/db/migrate/20091214131723_create_series_statements.rb +13 -0
- data/spec/dummy/db/migrate/20100129142347_create_import_requests.rb +14 -0
- data/spec/dummy/db/migrate/20100211105551_add_admin_networks_to_library_group.rb +9 -0
- data/spec/dummy/db/migrate/20100223121519_rename_series_statement_title_to_original_title.rb +13 -0
- data/spec/dummy/db/migrate/20100314190054_add_opening_hour_to_library.rb +9 -0
- data/spec/dummy/db/migrate/20100321235924_add_series_statement_identifier_to_series_statement.rb +10 -0
- data/spec/dummy/db/migrate/20100525124311_create_manifestation_relationships.rb +13 -0
- data/spec/dummy/db/migrate/20100606065209_create_user_has_roles.rb +12 -0
- data/spec/dummy/db/migrate/20100606073747_create_agent_relationships.rb +13 -0
- data/spec/dummy/db/migrate/20100607044753_create_manifestation_relationship_types.rb +12 -0
- data/spec/dummy/db/migrate/20100814091104_add_position_to_agent_relationship.rb +11 -0
- data/spec/dummy/db/migrate/20100925043847_create_resource_import_results.rb +15 -0
- data/spec/dummy/db/migrate/20100925074559_create_agent_import_results.rb +11 -0
- data/spec/dummy/db/migrate/20101212070145_add_acquired_at_to_item.rb +9 -0
- data/spec/dummy/db/migrate/20110222073537_add_url_to_library_group.rb +9 -0
- data/spec/dummy/db/migrate/20110301035123_add_pub_date_to_manifestation.rb +9 -0
- data/spec/dummy/db/migrate/20110301121550_add_birth_date_and_death_date_to_agent.rb +11 -0
- data/spec/dummy/db/migrate/20110318183304_add_valid_period_for_new_user_to_user_group.rb +11 -0
- data/spec/dummy/db/migrate/20110603184217_add_edit_mode_to_resource_import_file.rb +9 -0
- data/spec/dummy/db/migrate/20110619064807_add_edition_string_to_manifestation.rb +9 -0
- data/spec/dummy/db/migrate/20110620173525_add_bookstore_id_to_item.rb +11 -0
- data/spec/dummy/db/migrate/20110627034940_create_series_statement_merge_lists.rb +9 -0
- data/spec/dummy/db/migrate/20110627035057_create_series_statement_merges.rb +12 -0
- data/spec/dummy/db/migrate/20110913120629_add_lft_and_rgt_to_classification.rb +11 -0
- data/spec/dummy/db/migrate/20110916091020_add_volume_number_to_manifestation.rb +13 -0
- data/spec/dummy/db/migrate/20110916103953_add_manifestaiton_id_to_series_statement.rb +10 -0
- data/spec/dummy/db/migrate/20110918162329_add_note_to_series_statement.rb +9 -0
- data/spec/dummy/db/migrate/20111124110059_create_create_types.rb +12 -0
- data/spec/dummy/db/migrate/20111124110319_create_realize_types.rb +12 -0
- data/spec/dummy/db/migrate/20111124110355_create_produce_types.rb +12 -0
- data/spec/dummy/db/migrate/20111124112131_add_create_type_to_create.rb +7 -0
- data/spec/dummy/db/migrate/20120105074911_add_isil_to_library.rb +5 -0
- data/spec/dummy/db/migrate/20120125152919_add_title_subseries_transcription_to_series_statement.rb +6 -0
- data/spec/dummy/db/migrate/20120129014038_create_budget_types.rb +12 -0
- data/spec/dummy/db/migrate/20120129020544_add_budget_type_id_to_item.rb +6 -0
- data/spec/dummy/db/migrate/20120319120638_add_content_type_id_to_manifestation.rb +6 -0
- data/spec/dummy/db/migrate/20120319173203_create_accepts.rb +14 -0
- data/spec/dummy/db/migrate/20120406020752_add_url_to_subject.rb +5 -0
- data/spec/dummy/db/migrate/20120410104851_add_year_of_publication_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20120413072700_add_picture_meta_to_picture_file.rb +5 -0
- data/spec/dummy/db/migrate/20120413100352_add_fingerprint_to_picture_file.rb +5 -0
- data/spec/dummy/db/migrate/20120413161340_add_fingerprint_to_resource_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20120413161403_add_fingerprint_to_agent_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20120413170705_add_error_message_to_resource_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20120413170720_add_error_message_to_agent_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20120415164821_add_attachment_meta_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20120418081407_add_month_of_publication_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20120510140958_add_closed_to_shelf.rb +5 -0
- data/spec/dummy/db/migrate/20120511072422_add_agent_identifier_to_agent.rb +6 -0
- data/spec/dummy/db/migrate/20120602141129_add_edit_mode_to_agent_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20121116031206_add_fulltext_content_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20121116033446_add_doi_to_manifestation.rb +6 -0
- data/spec/dummy/db/migrate/20130221154434_add_additional_attributes_to_user.rb +16 -0
- data/spec/dummy/db/migrate/20130412083556_add_latitude_and_longitude_to_library.rb +6 -0
- data/spec/dummy/db/migrate/20130421093852_add_periodical_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20130421155019_add_creator_string_to_series_statement.rb +7 -0
- data/spec/dummy/db/migrate/20130421164124_add_series_master_to_series_statement.rb +5 -0
- data/spec/dummy/db/migrate/20130429020822_add_root_manifestation_id_to_series_statement.rb +6 -0
- data/spec/dummy/db/migrate/20130504133816_add_manifestation_id_to_subject.rb +6 -0
- data/spec/dummy/db/migrate/20130504143515_add_manifestation_id_to_classification.rb +6 -0
- data/spec/dummy/db/migrate/20130504195916_add_subject_heading_type_id_to_subject.rb +5 -0
- data/spec/dummy/db/migrate/20130506175303_create_identifier_types.rb +12 -0
- data/spec/dummy/db/migrate/20130506175834_create_identifiers.rb +15 -0
- data/spec/dummy/db/migrate/20130509185724_add_statement_of_responsibility_to_manifestation.rb +5 -0
- data/spec/dummy/db/migrate/20140110122216_create_user_import_files.rb +18 -0
- data/spec/dummy/db/migrate/20140110131010_create_user_import_results.rb +11 -0
- data/spec/dummy/db/migrate/20140122054321_create_profiles.rb +20 -0
- data/spec/dummy/db/migrate/20140519170214_create_resource_import_file_transitions.rb +14 -0
- data/spec/dummy/db/migrate/20140519171220_create_import_request_transitions.rb +14 -0
- data/spec/dummy/db/migrate/20140524020735_create_agent_import_file_transitions.rb +14 -0
- data/spec/dummy/db/migrate/20140524074813_create_user_import_file_transitions.rb +14 -0
- data/spec/dummy/db/migrate/20140610123439_drop_email_unique_constraint_enju_leaf_rc10.rb +11 -0
- data/spec/dummy/db/migrate/20140614065404_create_resource_export_files.rb +11 -0
- data/spec/dummy/db/migrate/20140614141500_create_resource_export_file_transitions.rb +14 -0
- data/spec/dummy/db/migrate/20140628072217_add_user_encoding_to_user_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20140628073524_add_user_encoding_to_agent_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20140628073535_add_user_encoding_to_resource_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20140709113413_create_user_export_files.rb +11 -0
- data/spec/dummy/db/migrate/20140709113905_create_user_export_file_transitions.rb +14 -0
- data/spec/dummy/db/migrate/20140720140916_add_binding_item_identifier_to_item.rb +8 -0
- data/spec/dummy/db/migrate/20140720170714_add_default_library_id_to_user_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20140720170735_add_default_user_group_id_to_user_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20140721151416_add_default_shelf_id_to_resource_import_file.rb +5 -0
- data/spec/dummy/db/migrate/20140802082007_add_manifestation_id_to_item.rb +6 -0
- data/spec/dummy/db/migrate/20140811031145_add_expired_at_to_profile.rb +5 -0
- data/spec/dummy/db/migrate/20140813182425_add_publication_place_to_manifestation.rb +5 -0
- data/spec/dummy/db/schema.rb +1008 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +2139 -0
- data/spec/dummy/log/test.log +21513 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/fixtures/agent_types.yml +35 -0
- data/spec/fixtures/carrier_types.yml +51 -0
- data/spec/fixtures/classification_types.yml +13 -0
- data/spec/fixtures/content_types.yml +19 -0
- data/spec/fixtures/countries.yml +2059 -0
- data/spec/fixtures/frequencies.yml +76 -0
- data/spec/fixtures/identifier_types.yml +36 -0
- data/spec/fixtures/languages.yml +1901 -0
- data/spec/fixtures/roles.yml +35 -0
- data/spec/fixtures/subject_heading_types.yml +39 -0
- data/spec/fixtures/subject_types.yml +42 -0
- data/spec/fixtures/user_has_roles.yml +41 -0
- data/spec/fixtures/users.yml +51 -0
- data/spec/models/loc_search_spec.rb +195 -0
- data/spec/rails_helper.rb +43 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/support/controller_macros.rb +25 -0
- data/spec/support/devise.rb +4 -0
- metadata +615 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 161a209a154952a583d5b7097b1d0095da0799dd
|
4
|
+
data.tar.gz: 28c269f6d80449a75cafc7222fc7e9d0dbab9d47
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5f0159d182e91d36adafde8eacd5cba7a9f3a030e16f786d1863372c4dc2c05fb613ecf7f87c11d77a74a898bd4fe5ff0d93c1ee5ea244f10c8ccc44b0f6fec8
|
7
|
+
data.tar.gz: 9f510d2b528a306917ccedd6d824bffa495b0c1529ac4a14e0a3b26a7fd813c66ee30532f59a04594404373e2ed6e8c0b9b50e3948fbf290c24acacee6cf792c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'EnjuLoc'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rspec/core'
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
|
33
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
34
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
task :default => :spec
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class LocSearchController < ApplicationController
|
2
|
+
before_filter :authenticate_user!
|
3
|
+
before_filter :check_librarian
|
4
|
+
|
5
|
+
def index
|
6
|
+
if params[:page].to_i <= 0
|
7
|
+
page = 1
|
8
|
+
else
|
9
|
+
page = params[:page].to_i
|
10
|
+
end
|
11
|
+
@query = params[ :query ].to_s.strip
|
12
|
+
books = LocSearch.search( @query, { :page => page } )
|
13
|
+
@books = Kaminari.paginate_array(
|
14
|
+
books[:items],
|
15
|
+
:total_count => books[ :total_entries ],
|
16
|
+
:page => page
|
17
|
+
).page( page ).per( 10 )
|
18
|
+
respond_to do |format|
|
19
|
+
format.html
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create
|
24
|
+
begin
|
25
|
+
@manifestation = LocSearch.import_from_sru_response(params[:book][:lccn])
|
26
|
+
rescue EnjuLoc::RecordNotFound
|
27
|
+
end
|
28
|
+
respond_to do |format|
|
29
|
+
if @manifestation.try(:save)
|
30
|
+
flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.manifestation'))
|
31
|
+
format.html { redirect_to manifestation_url(@manifestation) }
|
32
|
+
else
|
33
|
+
if @manifestation and not @manifestation.valid?
|
34
|
+
flash[:notice] = @manifestation.errors.messages
|
35
|
+
else
|
36
|
+
flash[:notice] = t('enju_loc.record_not_found')
|
37
|
+
end
|
38
|
+
format.html { redirect_to loc_search_index_url }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def check_librarian
|
45
|
+
unless current_user.try(:has_role?, 'Librarian')
|
46
|
+
access_denied
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module LocSearchHelper
|
2
|
+
def link_to_import_from_loc(lccn)
|
3
|
+
if lccn.blank?
|
4
|
+
t('enju_loc.not_available')
|
5
|
+
else
|
6
|
+
identifier_type = IdentifierType.where(:name => 'lccn').first
|
7
|
+
if identifier_type
|
8
|
+
manifestation = Identifier.where(:body => lccn, :identifier_type_id => identifier_type
|
9
|
+
.id).first.try(:manifestation)
|
10
|
+
end
|
11
|
+
unless manifestation
|
12
|
+
link_to t('enju_loc.add'), loc_search_index_path(:book => {:lccn => lccn}), :method => :post
|
13
|
+
else
|
14
|
+
link_to t('enju_loc.already_exists'), manifestation
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
class LocSearch
|
2
|
+
def initialize( node )
|
3
|
+
@node = node
|
4
|
+
end
|
5
|
+
class ModsRecord < LocSearch
|
6
|
+
MODS_NS = { "mods" => "http://www.loc.gov/mods/v3" }
|
7
|
+
def title
|
8
|
+
title = @node.xpath( './/mods:titleInfo/mods:title', MODS_NS ).first.content
|
9
|
+
subtitle = @node.xpath( './/mods:titleInfo/mods:subTitle', MODS_NS ).first
|
10
|
+
title += " : #{ subtitle.content }" if subtitle
|
11
|
+
title
|
12
|
+
end
|
13
|
+
def lccn
|
14
|
+
@node.xpath( './/mods:mods/mods:identifier[@type="lccn"]', MODS_NS ).first.try( :content )
|
15
|
+
end
|
16
|
+
def creator
|
17
|
+
statement_of_responsibility = @node.at('.//mods:note[@type="statement of responsibility"]',MODS_NS).try(:content)
|
18
|
+
if statement_of_responsibility
|
19
|
+
statement_of_responsibility
|
20
|
+
else
|
21
|
+
names = @node.xpath( './/mods:name', MODS_NS )
|
22
|
+
creator = names.map do |name|
|
23
|
+
name.xpath( './/mods:namePart', MODS_NS ).map do |part|
|
24
|
+
if part.content
|
25
|
+
part.content
|
26
|
+
else
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end.compact.join( ", " )
|
30
|
+
end.join( " ; " )
|
31
|
+
creator
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def publisher
|
35
|
+
names = @node.xpath( './/mods:publisher', MODS_NS ).map do |e|
|
36
|
+
e.content
|
37
|
+
end.join( ", " )
|
38
|
+
end
|
39
|
+
def pubyear
|
40
|
+
@node.xpath( './/mods:dateIssued', MODS_NS ).first.try(:content)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class DCRecord < LocSearch
|
45
|
+
DC_NS = { "dc" => "http://purl.org/dc/elements/1.1/" }
|
46
|
+
def title
|
47
|
+
title = @node.xpath( './/dc:title', DC_NS ).first.content
|
48
|
+
end
|
49
|
+
def lccn
|
50
|
+
@node.xpath( './/dc:identifier[@type="lccn"]', DC_NS ).first.content
|
51
|
+
end
|
52
|
+
def creator
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# http://www.loc.gov/z3950/lcserver.html
|
57
|
+
LOC_SRU_BASEURL = "http://lx2.loc.gov:210/LCDB"
|
58
|
+
def self.make_sru_request_uri( query, options = {} )
|
59
|
+
if options[ :page ]
|
60
|
+
page = options[ :page ].to_i
|
61
|
+
options[ :startRecord ] = ( page - 1 ) * 10 + 1
|
62
|
+
options.delete :page
|
63
|
+
end
|
64
|
+
options = { :maximumRecords => 10, :recordSchema => :mods }.merge( options )
|
65
|
+
options = options.merge( { :query => query, :version => "1.1", :operation => "searchRetrieve" } )
|
66
|
+
params = options.map do |k, v|
|
67
|
+
"#{ URI.escape( k.to_s ) }=#{ URI.escape( v.to_s ) }"
|
68
|
+
end.join( '&' )
|
69
|
+
uri = "#{ LOC_SRU_BASEURL }?#{ params }"
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.search( query, options = {} )
|
73
|
+
if query and not query.empty?
|
74
|
+
doc = nil
|
75
|
+
results = {}
|
76
|
+
url = make_sru_request_uri( query, options )
|
77
|
+
doc = Nokogiri::XML( open(url) )
|
78
|
+
items = doc.search( '//zs:record' ).map{|e| ModsRecord.new e }
|
79
|
+
@results = { :items => items,
|
80
|
+
:total_entries => doc.xpath( '//zs:numberOfRecords' ).first.try(:content).to_i }
|
81
|
+
else
|
82
|
+
{ :items => [], :total_entries => 0 }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.import_from_sru_response( lccn )
|
87
|
+
identifier = Identifier.where(:body => lccn, :identifier_type_id => IdentifierType.where(:name => 'lccn').first_or_create.id).first
|
88
|
+
return if identifier
|
89
|
+
url = make_sru_request_uri( "bath.lccn=#{ lccn }" )
|
90
|
+
response = Nokogiri::XML( open(url) ).at( '//zs:recordData', {"zs"=>"http://www.loc.gov/zing/srw/"} )
|
91
|
+
return unless response.try( :content )
|
92
|
+
doc = Nokogiri::XML::Document.new
|
93
|
+
doc << response.at( "//mods:mods", { "mods" => "http://www.loc.gov/mods/v3" } )
|
94
|
+
Manifestation.import_record_from_loc( doc )
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<div id="content_detail" class="ui-corner-all ui-widget-content">
|
2
|
+
<h1 class="title"><%= t('enju_loc.import_from_loc_search') %></h1>
|
3
|
+
<div id="content_list">
|
4
|
+
<p id="notice"><%= notice %></p>
|
5
|
+
<%= form_for :loc_search, :url => loc_search_index_path, :html => {:method => 'get'} do -%>
|
6
|
+
<p>
|
7
|
+
<%= label_tag :search_form_top, t('page.search_term') -%>:
|
8
|
+
<%= search_field_tag 'query', h(@query), {:id => 'search_form_top', :class => 'search_form'} -%>
|
9
|
+
<%= submit_tag t('page.search') -%>
|
10
|
+
</p>
|
11
|
+
<%- end -%>
|
12
|
+
<% if @query.present? %>
|
13
|
+
<p><%= t('enju_loc.number_of_search_results', :count => @books.total_count) %></p>
|
14
|
+
<table class="table table-striped index">
|
15
|
+
<tr>
|
16
|
+
<th></th>
|
17
|
+
<th><%= t('activerecord.attributes.manifestation.original_title') %></th>
|
18
|
+
</tr>
|
19
|
+
<% @books.each do |book| -%>
|
20
|
+
<tr class="line<%= cycle("0", "1") -%>">
|
21
|
+
<td>
|
22
|
+
<%= link_to_import_from_loc(book.lccn) %>
|
23
|
+
</td>
|
24
|
+
<td>
|
25
|
+
<strong><%= link_to_unless( book.lccn.blank?, book.title, "http://lccn.loc.gov/#{ book.lccn }" ) do book.title end %></strong><br />
|
26
|
+
<%=h book.creator -%><br />
|
27
|
+
<%=h book.publisher -%>,
|
28
|
+
<%=h book.pubyear -%>
|
29
|
+
</td>
|
30
|
+
</tr>
|
31
|
+
<% end -%>
|
32
|
+
</table>
|
33
|
+
<br />
|
34
|
+
<%= paginate(@books) %>
|
35
|
+
|
36
|
+
<% else %>
|
37
|
+
<%= javascript_tag("$('#search_form_top').focus()") -%>
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
</div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="submenu" class="ui-corner-all ui-widget-content">
|
44
|
+
<% if defined?(EnjuNdl) %>
|
45
|
+
<ul>
|
46
|
+
<li><%= link_to t('enju_ndl.import_from_ndl_search'), ndl_books_path( :query => @query ) %></li>
|
47
|
+
</ul>
|
48
|
+
<% end %>
|
49
|
+
</div>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
en:
|
2
|
+
enju_loc:
|
3
|
+
import_from_loc_search: Import from LoC Search
|
4
|
+
record_not_found: Record not found.
|
5
|
+
not_available: Not available
|
6
|
+
add: Add
|
7
|
+
already_exists: Already exists
|
8
|
+
number_of_search_results:
|
9
|
+
one: "1 record found."
|
10
|
+
other: "%{count} records found."
|
11
|
+
activerecord:
|
12
|
+
models:
|
13
|
+
loc_search: LoC Catalog Search
|
data/config/routes.rb
ADDED
data/lib/enju_loc.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "enju_loc/engine"
|
2
|
+
require "enju_loc/loc_search"
|
3
|
+
|
4
|
+
module EnjuLoc
|
5
|
+
module ActsAsMethods
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def enju_loc_search
|
12
|
+
include EnjuLoc::LocSearch
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class RecordNotFound < StandardError; end
|
18
|
+
class InvalidIsbn < StandardError; end
|
19
|
+
end
|
20
|
+
|
21
|
+
ActiveRecord::Base.send :include, EnjuLoc::ActsAsMethods
|
@@ -0,0 +1,537 @@
|
|
1
|
+
module EnjuLoc
|
2
|
+
module LocSearch
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def loc_search(query, options = {})
|
9
|
+
options = {}.merge(options)
|
10
|
+
doc = nil
|
11
|
+
results = {}
|
12
|
+
startrecord = options[:idx].to_i
|
13
|
+
if startrecord == 0
|
14
|
+
startrecord = 1
|
15
|
+
end
|
16
|
+
url = LOC_SRU_BASEURL + "?operation=searchRetrieve&version=1.1&=query=#{ URI.escape(query) }"
|
17
|
+
cont = open( url ){|io| io.read }
|
18
|
+
parser = LibXML::XML::Parser.string( cont )
|
19
|
+
doc = parser.parse
|
20
|
+
end
|
21
|
+
|
22
|
+
def import_record_from_loc_isbn(options)
|
23
|
+
#if options[:isbn]
|
24
|
+
lisbn = Lisbn.new(options[:isbn])
|
25
|
+
raise EnjuLoc::InvalidIsbn unless lisbn.valid?
|
26
|
+
#end
|
27
|
+
|
28
|
+
manifestation = Manifestation.find_by_isbn(lisbn.isbn)
|
29
|
+
return manifestation.first if manifestation.present?
|
30
|
+
|
31
|
+
doc = return_xml(lisbn.isbn)
|
32
|
+
raise EnjuLoc::RecordNotFound unless doc
|
33
|
+
import_record_from_loc(doc)
|
34
|
+
end
|
35
|
+
|
36
|
+
NS = {"mods"=>"http://www.loc.gov/mods/v3"}
|
37
|
+
def import_record_from_loc( doc )
|
38
|
+
record_identifier = doc.at( '//mods:recordInfo/mods:recordIdentifier', NS ).try(:content)
|
39
|
+
loc_identifier = Identifier.where(:body => record_identifier, :identifier_type_id => IdentifierType.where(:name => 'loc_identifier').first_or_create.id).first
|
40
|
+
return loc_identifier.manifestation if loc_identifier
|
41
|
+
|
42
|
+
publishers = []
|
43
|
+
doc.xpath('//mods:publisher',NS).each do |publisher|
|
44
|
+
publishers << {
|
45
|
+
:full_name => publisher.content,
|
46
|
+
#:agent_identifier => publisher.attributes["about"].try(:content)
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
creators = get_creators(doc)
|
51
|
+
|
52
|
+
# title
|
53
|
+
titles = get_titles(doc)
|
54
|
+
|
55
|
+
# date of publication
|
56
|
+
date = get_date_of_publication(doc)
|
57
|
+
|
58
|
+
language = Language.where(:iso_639_2 => get_language(doc)).first
|
59
|
+
if language
|
60
|
+
language_id = language.id
|
61
|
+
else
|
62
|
+
language_id = 1
|
63
|
+
end
|
64
|
+
|
65
|
+
isbn = Lisbn.new(doc.at('/mods:mods/mods:identifier[@type="isbn"]',NS).try(:content).to_s).try(:isbn)
|
66
|
+
lccn = StdNum::LCCN.normalize(doc.at('/mods:mods/mods:identifier[@type="lccn"]',NS).try(:content).to_s)
|
67
|
+
issn = StdNum::ISSN.normalize(doc.at('/mods:mods/mods:identifier[@type="issn"]',NS).try(:content).to_s)
|
68
|
+
issn_l = StdNum::ISSN.normalize(doc.at('/mods:mods/mods:identifier[@type="issn-l"]',NS).try(:content).to_s)
|
69
|
+
|
70
|
+
types = get_carrier_and_content_types( doc )
|
71
|
+
content_type = types[ :content_type ]
|
72
|
+
carrier_type = types[ :carrier_type ]
|
73
|
+
|
74
|
+
record_identifier = doc.at('//mods:recordInfo/mods:recordIdentifier',NS).try(:content)
|
75
|
+
description = doc.xpath('//mods:abstract',NS).collect(&:content).join("\n")
|
76
|
+
edition_string = doc.at('//mods:edition',NS).try(:content)
|
77
|
+
extent = get_extent(doc)
|
78
|
+
note = get_note(doc)
|
79
|
+
frequency = get_frequency(doc)
|
80
|
+
issuance = doc.at('//mods:issuance',NS).try(:content)
|
81
|
+
is_serial = true if issuance == "serial"
|
82
|
+
statement_of_responsibility = get_statement_of_responsibility(doc)
|
83
|
+
access_address = get_access_address(doc)
|
84
|
+
publication_place = get_publication_place(doc)
|
85
|
+
|
86
|
+
manifestation = nil
|
87
|
+
Agent.transaction do
|
88
|
+
creator_agents = Agent.import_agents(creators)
|
89
|
+
publisher_agents = Agent.import_agents(publishers)
|
90
|
+
|
91
|
+
manifestation = Manifestation.new(
|
92
|
+
:manifestation_identifier => record_identifier,
|
93
|
+
:original_title => titles[:original_title],
|
94
|
+
:title_alternative => titles[:title_alternative],
|
95
|
+
:language_id => language_id,
|
96
|
+
:pub_date => date,
|
97
|
+
:description => description,
|
98
|
+
:edition_string => edition_string,
|
99
|
+
:statement_of_responsibility => statement_of_responsibility,
|
100
|
+
:start_page => extent[:start_page],
|
101
|
+
:end_page => extent[:end_page],
|
102
|
+
:height => extent[:height],
|
103
|
+
:access_address => access_address,
|
104
|
+
:note => note,
|
105
|
+
:publication_place => publication_place,
|
106
|
+
:periodical => is_serial,
|
107
|
+
)
|
108
|
+
identifier = {}
|
109
|
+
if isbn
|
110
|
+
identifier[:isbn] = Identifier.new(:body => isbn)
|
111
|
+
identifier[:isbn].identifier_type = IdentifierType.where(:name => 'isbn').first_or_create
|
112
|
+
end
|
113
|
+
if loc_identifier
|
114
|
+
identifier[:loc_identifier] = Identifier.new(:body => loc_identifier)
|
115
|
+
identifier[:loc_identifier].identifier_type = IdentifierType.where(:name => 'loc_identifier').first_or_create
|
116
|
+
end
|
117
|
+
if lccn
|
118
|
+
identifier[:lccn] = Identifier.new(:body => lccn)
|
119
|
+
identifier[:lccn].identifier_type = IdentifierType.where(:name => 'lccn').first_or_create
|
120
|
+
end
|
121
|
+
if issn
|
122
|
+
identifier[:issn] = Identifier.new(:body => issn)
|
123
|
+
identifier[:issn].identifier_type = IdentifierType.where(:name => 'issn').first_or_create
|
124
|
+
end
|
125
|
+
if issn_l
|
126
|
+
identifier[:issn_l] = Identifier.new(:body => issn_l)
|
127
|
+
identifier[:issn_l].identifier_type = IdentifierType.where(:name => 'issn_l').first_or_create
|
128
|
+
end
|
129
|
+
manifestation.carrier_type = carrier_type if carrier_type
|
130
|
+
manifestation.manifestation_content_type = content_type if content_type
|
131
|
+
manifestation.frequency = frequency if frequency
|
132
|
+
if manifestation.save
|
133
|
+
identifier.each do |k, v|
|
134
|
+
manifestation.identifiers << v if v.valid?
|
135
|
+
end
|
136
|
+
manifestation.publishers << publisher_agents
|
137
|
+
manifestation.creators << creator_agents
|
138
|
+
create_subject_related_elements(doc, manifestation)
|
139
|
+
create_series_statement(doc, manifestation)
|
140
|
+
if is_serial
|
141
|
+
create_series_master(doc, manifestation)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
return manifestation
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
def create_subject_related_elements(doc, manifestation)
|
150
|
+
subjects = get_subjects(doc)
|
151
|
+
classifications = get_classifications(doc)
|
152
|
+
if defined?(EnjuSubject)
|
153
|
+
subject_heading_type = SubjectHeadingType.where(:name => 'lcsh').first_or_create
|
154
|
+
subjects.each do |term|
|
155
|
+
subject = Subject.where(:term => term[:term]).first
|
156
|
+
unless subject
|
157
|
+
subject = Subject.new(term)
|
158
|
+
subject.subject_heading_type = subject_heading_type
|
159
|
+
subject.subject_type = SubjectType.where(:name => 'concept').first_or_create
|
160
|
+
end
|
161
|
+
manifestation.subjects << subject
|
162
|
+
end
|
163
|
+
if classifications
|
164
|
+
classification_type = ClassificationType.where(:name => 'ddc').first_or_create
|
165
|
+
classifications.each do |ddc|
|
166
|
+
classification = Classification.where(:category => ddc).first
|
167
|
+
unless classification
|
168
|
+
classification = Classification.new(:category => ddc)
|
169
|
+
classification.classification_type = classification_type
|
170
|
+
end
|
171
|
+
manifestation.classifications << classification if classification.valid?
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def create_series_statement(doc, manifestation)
|
178
|
+
doc.xpath('//mods:relatedItem[@type="series"]/mods:titleInfo/mods:title',NS).each do |series|
|
179
|
+
series_title = title = series.try(:content)
|
180
|
+
if title
|
181
|
+
series_title = title.split(';')[0].strip
|
182
|
+
end
|
183
|
+
if series_title
|
184
|
+
series_statement = SeriesStatement.where(:original_title => series_title).first_or_create
|
185
|
+
if series_statement.try(:save)
|
186
|
+
manifestation.series_statements << series_statement
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def create_series_master(doc, manifestation)
|
193
|
+
titles = get_titles(doc)
|
194
|
+
series_statement = SeriesStatement.new(
|
195
|
+
:original_title => titles[:original_title],
|
196
|
+
:title_alternative => titles[:title_alternative],
|
197
|
+
:series_master => true,
|
198
|
+
)
|
199
|
+
if series_statement.try(:save)
|
200
|
+
manifestation.series_statements << series_statement
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def get_titles(doc)
|
205
|
+
original_title = ""
|
206
|
+
title_alternatives = []
|
207
|
+
doc.xpath('//mods:mods/mods:titleInfo',NS).each do |e|
|
208
|
+
type = e.attributes["type"].try(:content)
|
209
|
+
case type
|
210
|
+
when "alternative", "translated", "abbreviated", "uniform"
|
211
|
+
title_alternatives << e.at('./mods:title',NS).content
|
212
|
+
else
|
213
|
+
nonsort = e.at('./mods:nonSort',NS).try(:content)
|
214
|
+
original_title << nonsort if nonsort
|
215
|
+
original_title << e.at('./mods:title',NS).try(:content)
|
216
|
+
subtitle = e.at('./mods:subTitle',NS).try(:content)
|
217
|
+
original_title << " : #{ subtitle }" if subtitle
|
218
|
+
partnumber = e.at('./mods:partNumber',NS).try(:content)
|
219
|
+
partname = e.at('./mods:partName',NS).try(:content)
|
220
|
+
partname = [ partnumber, partname ].compact.join( ": " )
|
221
|
+
original_title << ". #{ partname }" unless partname.blank?
|
222
|
+
end
|
223
|
+
end
|
224
|
+
{ :original_title => original_title, :title_alternative => title_alternatives.join( " ; " ) }
|
225
|
+
end
|
226
|
+
|
227
|
+
def get_language(doc)
|
228
|
+
language = doc.at('//mods:language/mods:languageTerm[@authority="iso639-2b"]',NS).try(:content)
|
229
|
+
end
|
230
|
+
|
231
|
+
def get_access_address(doc)
|
232
|
+
access_address = nil
|
233
|
+
url = doc.at('//mods:location/mods:url',NS)
|
234
|
+
if url
|
235
|
+
usage = url.attributes["usage"].try(:content)
|
236
|
+
case usage
|
237
|
+
when "primary display", "primary"
|
238
|
+
access_address = url.try(:content)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
access_address
|
242
|
+
end
|
243
|
+
|
244
|
+
def get_publication_place(doc)
|
245
|
+
place = doc.at('//mods:originInfo/mods:place/mods:placeTerm[@type="text"]',NS).try(:content)
|
246
|
+
end
|
247
|
+
|
248
|
+
def get_extent(doc)
|
249
|
+
extent = doc.at('//mods:extent',NS).try(:content)
|
250
|
+
value = {:start_page => nil, :end_page => nil, :height => nil}
|
251
|
+
if extent
|
252
|
+
extent = extent.split(';')
|
253
|
+
page = extent[0].try(:strip)
|
254
|
+
if page =~ /(\d+)\s*(p|page)/
|
255
|
+
value[:start_page] = 1
|
256
|
+
value[:end_page] = $1.dup.to_i
|
257
|
+
end
|
258
|
+
height = extent[1].try(:strip)
|
259
|
+
if height =~ /(\d+)\s*cm/
|
260
|
+
value[:height] = $1.dup.to_i
|
261
|
+
end
|
262
|
+
end
|
263
|
+
value
|
264
|
+
end
|
265
|
+
|
266
|
+
def get_statement_of_responsibility(doc)
|
267
|
+
note = doc.at('//mods:note[@type="statement of responsibility"]',NS).try(:content)
|
268
|
+
if note
|
269
|
+
note
|
270
|
+
else
|
271
|
+
doc.xpath('/mods:mods/mods:name',NS).map do |n|
|
272
|
+
n.at('./mods:namePart',NS).try(:content)
|
273
|
+
end.join( "; " )
|
274
|
+
end
|
275
|
+
end
|
276
|
+
def get_note(doc)
|
277
|
+
notes = []
|
278
|
+
doc.xpath('//mods:note',NS).each do |note|
|
279
|
+
type = note.attributes['type'].try(:content)
|
280
|
+
next if type == "statement of responsibility"
|
281
|
+
note_s = note.try( :content )
|
282
|
+
notes << note_s unless note_s.blank?
|
283
|
+
end
|
284
|
+
if notes.empty?
|
285
|
+
nil
|
286
|
+
else
|
287
|
+
notes.join( ";\n" )
|
288
|
+
end
|
289
|
+
end
|
290
|
+
def get_date_of_publication(doc)
|
291
|
+
dates = []
|
292
|
+
doc.xpath('//mods:dateIssued',NS).each do |pub_date|
|
293
|
+
pub_date = pub_date.content.sub( /\A[cp]/, '' )
|
294
|
+
next unless pub_date =~ /^\d+(-\d\d?){0,2}$/
|
295
|
+
date = pub_date.split('-')
|
296
|
+
if date[0] and date[1]
|
297
|
+
dates << sprintf("%04d-%02d", date[0], date[1])
|
298
|
+
else
|
299
|
+
dates << pub_date
|
300
|
+
end
|
301
|
+
end
|
302
|
+
dates.compact.first
|
303
|
+
end
|
304
|
+
|
305
|
+
# derived from marcfrequency: http://www.loc.gov/standards/valuelist/marcfrequency.html
|
306
|
+
MARCFREQUENCY = [
|
307
|
+
"Continuously updated",
|
308
|
+
"Daily",
|
309
|
+
"Semiweekly",
|
310
|
+
"Three times a week",
|
311
|
+
"Weekly",
|
312
|
+
"Biweekly",
|
313
|
+
"Three times a month",
|
314
|
+
"Semimonthly",
|
315
|
+
"Monthly",
|
316
|
+
"Bimonthly",
|
317
|
+
"Quarterly",
|
318
|
+
"Three times a year",
|
319
|
+
"Semiannual",
|
320
|
+
"Annual",
|
321
|
+
"Biennial",
|
322
|
+
"Triennial",
|
323
|
+
"Completely irregular",
|
324
|
+
]
|
325
|
+
def get_frequency(doc)
|
326
|
+
frequencies = []
|
327
|
+
doc.xpath('//mods:frequency',NS).each do |freq|
|
328
|
+
frequency = freq.try(:content)
|
329
|
+
MARCFREQUENCY.each do |freq_regex|
|
330
|
+
if /\A(#{freq_regex})/ =~ frequency
|
331
|
+
frequency_name = freq_regex.downcase.gsub( /\s+/, "_" )
|
332
|
+
frequencies << Frequency.where( :name => frequency_name ).first
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
frequencies.compact.first
|
337
|
+
end
|
338
|
+
|
339
|
+
def get_creators(doc)
|
340
|
+
creators = []
|
341
|
+
doc.xpath('/mods:mods/mods:name',NS).each do |creator|
|
342
|
+
creators << {
|
343
|
+
:full_name => creator.xpath('./mods:namePart',NS).collect(&:content).join( ", " ),
|
344
|
+
}
|
345
|
+
end
|
346
|
+
creators.uniq
|
347
|
+
end
|
348
|
+
|
349
|
+
# TODO:only LCSH-based parsing...
|
350
|
+
def get_subjects(doc)
|
351
|
+
subjects = []
|
352
|
+
doc.xpath('//mods:subject[@authority="lcsh"]',NS).each do |s|
|
353
|
+
subject = []
|
354
|
+
s.xpath('./*',NS).each do |subelement|
|
355
|
+
type = subelement.name
|
356
|
+
case subelement.name
|
357
|
+
when "topic", "geographic", "genre", "temporal"
|
358
|
+
subject << { :type => type , :term => subelement.try(:content) }
|
359
|
+
when "titleInfo"
|
360
|
+
subject << { :type => type, :term => subelement.at('./mods:title',NS).try(:content) }
|
361
|
+
when "name"
|
362
|
+
name = subelement.xpath('./mods:namePart',NS).map{|e| e.try(:content) }.join( ", " )
|
363
|
+
subject << { :type => type, :term => name }
|
364
|
+
end
|
365
|
+
end
|
366
|
+
next if subject.compact.empty?
|
367
|
+
if subject.size > 1 and subject[0][:type] == "name" and subject[1][:type] == "titleInfo"
|
368
|
+
subject[0..1] = { :term => subject[0..1].map{|e|e[:term]}.join( ". " ) }
|
369
|
+
end
|
370
|
+
subjects << {
|
371
|
+
:term => subject.map{|e|e[:term]}.compact.join( "--" )
|
372
|
+
}
|
373
|
+
end
|
374
|
+
subjects
|
375
|
+
end
|
376
|
+
|
377
|
+
# TODO:support only DDC.
|
378
|
+
def get_classifications(doc)
|
379
|
+
classifications = []
|
380
|
+
doc.xpath('//mods:classification[@authority="ddc"]',NS).each do|c|
|
381
|
+
ddc = c.content
|
382
|
+
if ddc
|
383
|
+
classifications << ddc.split(/[^\d\.]/).first.try(:strip)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
classifications.compact
|
387
|
+
end
|
388
|
+
|
389
|
+
def get_carrier_and_content_types(doc)
|
390
|
+
carrier_type = content_type = nil
|
391
|
+
doc.xpath('//mods:form',NS).each do |e|
|
392
|
+
authority = e.attributes['authority'].try(:content)
|
393
|
+
case authority
|
394
|
+
when "gmd"
|
395
|
+
case e.content
|
396
|
+
when "electronic resource"
|
397
|
+
carrier_type = CarrierType.where(:name => 'file').first
|
398
|
+
when "videorecording"
|
399
|
+
content_type = ContentType.where(:name => 'video').first
|
400
|
+
#TODO: Enju needs more specific mappings...
|
401
|
+
when "art original"
|
402
|
+
when "microscope slides"
|
403
|
+
when "art reproduction"
|
404
|
+
when "model"
|
405
|
+
when "chart"
|
406
|
+
when "motion picture"
|
407
|
+
when "diorama"
|
408
|
+
when "picture"
|
409
|
+
when "realia"
|
410
|
+
when "filmstrip"
|
411
|
+
when "slide"
|
412
|
+
when "flash card"
|
413
|
+
when "sound recording"
|
414
|
+
when "game"
|
415
|
+
when "technical drawing"
|
416
|
+
when "graphic"
|
417
|
+
when "toy"
|
418
|
+
when "kit"
|
419
|
+
when "transparency"
|
420
|
+
when "microform"
|
421
|
+
end
|
422
|
+
when "marcsmd" # cf.http://www.loc.gov/standards/valuelist/marcsmd.html
|
423
|
+
case e.content
|
424
|
+
when "text", "braille", "large print", "regular print", "text in looseleaf binder"
|
425
|
+
carrier_type = CarrierType.where(:name => 'print').first
|
426
|
+
content_type = ContentType.where(:name => 'text').first
|
427
|
+
when "videorecording", "videocartridge", "videocassette", "videodisc", "videoreel"
|
428
|
+
content_type = ContentType.where(:name => 'video').first
|
429
|
+
when "electronic resource", "chip cartridge", "computer optical disc cartridge", "magnetic disk", "magneto-optical disc", "optical disc", "remote", "tape cartridge", "tape cassette", "tape reel"
|
430
|
+
carrier_type = CarrierType.where(:name => 'file').first
|
431
|
+
when "motion picture", "film cartridge", "film cassette", "film reel"
|
432
|
+
content_type = ContentType.where(:name => 'video').first
|
433
|
+
when "sound recording", "cylinder", "roll ", "sound cartridge", "sound cassette ", "sound disc ", "sound-tape reel", "sound-track film ", "wire recording"
|
434
|
+
conrent_type = ContentType.where(:name => 'audio').first
|
435
|
+
#when "nonprojected graphic", "chart", "collage", "drawing", "flash card", "painting", "photomechanical print", "photonegative", "photoprint", "picture", "print", "technical drawing", "projected graphic", "filmslip", "filmstrip cartridge", "filmstrip roll", "other filmstrip type ", "slide", "transparency"
|
436
|
+
# content_type = ContentType.where(:name => 'image').first
|
437
|
+
#TODO: Enju needs more specific mappings...
|
438
|
+
when "globe"
|
439
|
+
when "celestial globe"
|
440
|
+
when "earth moon globe"
|
441
|
+
when "planetary or lunar globe"
|
442
|
+
when "terrestrial globe"
|
443
|
+
when "map"
|
444
|
+
when "atlas"
|
445
|
+
when "diagram"
|
446
|
+
when "map"
|
447
|
+
when "model"
|
448
|
+
when "profile "
|
449
|
+
when "remote-sensing image"
|
450
|
+
when "section"
|
451
|
+
when "view"
|
452
|
+
when "microform"
|
453
|
+
when "aperture card"
|
454
|
+
when "microfiche"
|
455
|
+
when "microfiche cassette"
|
456
|
+
when "microfilm cartridge"
|
457
|
+
when "microfilm cassette"
|
458
|
+
when "microfilm reel"
|
459
|
+
when "microopaque"
|
460
|
+
when "tactile material"
|
461
|
+
when "braille"
|
462
|
+
when "combination"
|
463
|
+
when "moon"
|
464
|
+
when "tactile, with no writing system"
|
465
|
+
end
|
466
|
+
when "marcform" # cf. http://www.loc.gov/standards/valuelist/marcform.html
|
467
|
+
case e.content
|
468
|
+
when "print", "large print"
|
469
|
+
carrier_type = CarrierType.where(:name => 'print').first
|
470
|
+
content_type = ContentType.where(:name => 'text').first
|
471
|
+
when "electronic"
|
472
|
+
carrier_type = CarrierType.where(:name => 'file').first
|
473
|
+
#TODO: Enju needs more specific mappings...
|
474
|
+
when "microfiche"
|
475
|
+
when "braille"
|
476
|
+
when "microfilm"
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|
480
|
+
doc.xpath('//mods:genre',NS).each do |e|
|
481
|
+
authority = e.attributes['authority'].try(:content)
|
482
|
+
case authority
|
483
|
+
when "rdacontent"
|
484
|
+
case e.content
|
485
|
+
when "computer dataset", "computer program"
|
486
|
+
content_type = ContentType.where(:name => 'file').first
|
487
|
+
when "sounds", "spoken word"
|
488
|
+
content_type = ContentType.where(:name => 'audio').first
|
489
|
+
when "text"
|
490
|
+
content_type = ContentType.where(:name => 'text').first
|
491
|
+
when "two-dimensional moving image"
|
492
|
+
content_type = ContentType.where(:name => 'video').first
|
493
|
+
#TODO: Enju needs more specific mappings...
|
494
|
+
when "cartographic dataset"
|
495
|
+
when "cartographic image"
|
496
|
+
when "cartographic moving image"
|
497
|
+
when "cartographic tactile image"
|
498
|
+
when "cartographic tactile three-dimensional form"
|
499
|
+
when "cartographic three-dimensional form"
|
500
|
+
when "notated movement"
|
501
|
+
when "notated music"
|
502
|
+
when "performed music"
|
503
|
+
when "still image"
|
504
|
+
when "tactile image"
|
505
|
+
when "tactile notated music"
|
506
|
+
when "tactile notated movement"
|
507
|
+
when "tactile text"
|
508
|
+
when "tactile three-dimensional form"
|
509
|
+
when "three-dimensional form"
|
510
|
+
when "three-dimensional moving image"
|
511
|
+
when "other"
|
512
|
+
when "unspecified"
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|
516
|
+
type = doc.at('//mods:typeOfResource',NS).try(:content)
|
517
|
+
case type
|
518
|
+
when "text"
|
519
|
+
content_type = ContentType.where(:name => 'text').first
|
520
|
+
when "sound recording", "sound recording-musical", "sound recording-nonmusical"
|
521
|
+
content_type = ContentType.where(:name => 'audio').first
|
522
|
+
when "moving image"
|
523
|
+
content_type = ContentType.where(:name => 'video').first
|
524
|
+
when "software, multimedia"
|
525
|
+
carrier_type = ContentType.where(:name => 'file').first
|
526
|
+
#TODO: Enju needs more specific mappings...
|
527
|
+
when "cartographic "
|
528
|
+
when "notated music"
|
529
|
+
when "still image"
|
530
|
+
when "three dimensional object"
|
531
|
+
when "mixed material"
|
532
|
+
end
|
533
|
+
{ :carrier_type => carrier_type, :content_type => content_type }
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|
537
|
+
end
|