-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from hathitrust/DEV-838-full-marc
DEV-838: Full MARC record output
- Loading branch information
Showing
6 changed files
with
138 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<description> | ||
<eprints xmlns="http://www.openarchives.org/OAI/1.1/eprints" xsi:schemaLocation="http://www.openarchives.org/OAI/1.1/eprints http://www.openarchives.org/OAI/1.1/eprints.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<content> | ||
<URL>https://www.hathitrust.org/member-libraries/resources-for-librarians/data-resources/oai-feed/</URL> | ||
<text>The Open Archives Initiative Protocol for Metadata Harvesting (OAI-PMH) is a protocol used in libraries and archives for the automated delivery of structured bibliographic metadata. You can use this option to retrieve metadata in MARC21 or unqualified Dublin Core formats in XML structure. The OAI feed allows you to access new and updated records and (for the full set of records) discover if any have been deleted. For best practices related to OAI, and a list of potential harvesters, see https://www.ideals.illinois.edu/items/50369.</text> | ||
</content> | ||
<metadataPolicy> | ||
<URL>https://www.hathitrust.org/the-collection/terms-conditions/metadata-sharing-and-use-policy/#bibliographic-metadata-sharing-policy</URL> | ||
<text>Metadata is provided under the terms of the HathiTrust Bibliographic Metadata Sharing Policy. See details at the above URL.</text> | ||
</metadataPolicy> | ||
<dataPolicy> | ||
<URL>https://www.hathitrust.org/the-collection/search-access/access-use-policy/</URL> | ||
<text>HathiTrust is a collaborative library initiative. Users are encouraged to cite and link to digital content and are free to do so without asking for permission. Depending on the source of the digitized work, licenses or other contractual terms may restrict further distribution or other uses. For volume-specific information, please consult the <dc:rights> element (oai_dc) or 856$r (marc21). You need to make your own assessment of the copyright or other legal concerns related to uses beyond those provided by HathiTrust for particular works. | ||
|
||
The possible Access and Use statements that apply to each book are listed at the URL above.</text> | ||
</dataPolicy> | ||
</eprints> | ||
</description> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require "marc" | ||
require "oai" | ||
|
||
module OAISolr | ||
class Marc21Full | ||
ZEPHIR_FIELDS = %w[DAT CAT CID HOL FMT].to_set | ||
|
||
def prefix | ||
"marc21_full" | ||
end | ||
|
||
def schema | ||
"http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" | ||
end | ||
|
||
def namespace | ||
"http://www.loc.gov/MARC21/slim" | ||
end | ||
|
||
def encode _, record | ||
record.marc_record.tap do |r| | ||
r.fields.reject! { |f| ZEPHIR_FIELDS.include?(f.tag) } | ||
end.to_xml_string(fast_but_unsafe: true, include_namespace: true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require "spec_helper" | ||
require "oai_solr/record" | ||
require "oai_solr/marc21_full" | ||
require "json" | ||
require "nokogiri" | ||
|
||
RSpec.describe OAISolr::Marc21Full do | ||
shared_examples_for "full marc record" do |file| | ||
let(:sdoc) { JSON.parse(File.read("spec/data/#{file}")) } | ||
let(:oai_record) { OAISolr::Record.new(sdoc) } | ||
let(:full_marc_xml) { described_class.new.encode(nil, oai_record) } | ||
let(:full_marc_record) { MARC::XMLReader.new(StringIO.new(full_marc_xml)).first } | ||
let(:slim_schema) do | ||
Nokogiri::XML::Schema(File.open(File.dirname(__FILE__) + "/schemas/MARC21slim.xsd")) | ||
end | ||
|
||
describe "#encode" do | ||
it "provides valid marc for #{file}" do | ||
parsed = Nokogiri::XML::Document.parse(full_marc_xml) | ||
expect(slim_schema.valid?(parsed)).to be true | ||
end | ||
|
||
it "has 974s for #{file}" do | ||
orig = oai_record.marc_record | ||
expect(orig.fields("974").count).to be > 0 | ||
expect(orig.fields("974").count).to eq(full_marc_record.fields("974").count) | ||
end | ||
|
||
it "has an 008 for #{file}" do | ||
expect(full_marc_record["008"]).not_to be(nil) | ||
end | ||
|
||
it "does not have special zephir fields" do | ||
%w[CID DAT CAT FMT HOL].each do |zephir_field| | ||
expect(full_marc_record[zephir_field]).to be nil | ||
end | ||
end | ||
|
||
it "has a title field" do | ||
expect(full_marc_record["245"].count).to be > 0 | ||
end | ||
|
||
it "has a subject field" do | ||
expect(full_marc_record["650"].count).to be > 0 | ||
end | ||
|
||
# true for the two sample records below, not necessarily | ||
# always these indicators! | ||
it "has indicators for title field" do | ||
f = full_marc_record["245"] | ||
expect(f.indicator1).to eq("1") | ||
expect(f.indicator2).to eq("0") | ||
end | ||
end | ||
end | ||
|
||
it_behaves_like "full marc record", "000004150.json" | ||
it_behaves_like "full marc record", "000007599.json" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters