-
Notifications
You must be signed in to change notification settings - Fork 2
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 #749 from sul-dlss/647-refactor-name-extraction
Refactor name extraction to introduce role mapping
- Loading branch information
Showing
7 changed files
with
126 additions
and
1 deletion.
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
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
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,12 @@ | ||
Artist: فنان | ||
Author: مؤلف | ||
Calligrapher: خطاط | ||
Copyist: الناسخ | ||
Creator: المنشئ | ||
Former owner: مالك سابق | ||
Former repository: المستودع السابق | ||
Illuminator: المنور | ||
Illustrator: المصور | ||
Painter: دهان | ||
Patron: نمط | ||
Scribe: كاتب |
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,14 @@ | ||
artist: Artist | ||
author: Author | ||
calligrapher: Calligrapher | ||
copyist: Copyist | ||
copyist.: Copyist | ||
cre: Creator | ||
creator: Creator | ||
former owner.: Former owner | ||
former repository: Former repository | ||
illuminator: Illuminator | ||
illustrator: Illustrator | ||
painter (artist): Painter | ||
patron: Patron | ||
scribe.: Scribe |
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,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'macros/mods' | ||
require 'macros/language_extraction' | ||
|
||
RSpec.describe Macros::Mods do | ||
subject(:indexer) do | ||
Traject::Indexer.new.tap do |indexer| | ||
indexer.instance_eval do | ||
extend Macros::Mods | ||
extend Macros::LanguageExtraction | ||
end | ||
end | ||
end | ||
|
||
describe '#extract_name' do | ||
let(:record) do | ||
<<~XML | ||
<mods:mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:mods="http://www.loc.gov/mods/v3" | ||
xmlns:sets="http://hul.harvard.edu/ois/xml/ns/sets" | ||
xmlns:xlink="http://www.w3.org/1999/xlink" | ||
xmlns:marc="http://www.loc.gov/MARC21/slim" | ||
xmlns:HarvardDRS="http://hul.harvard.edu/ois/xml/ns/HarvardDRS" | ||
xmlns:librarycloud="http://hul.harvard.edu/ois/xml/ns/librarycloud" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd" version="3.6"> | ||
<mods:name> | ||
<mods:namePart>Doe, John</mods:namePart> | ||
<mods:role> | ||
<mods:roleTerm type="text">copyist.</mods:roleTerm> | ||
</mods:role> | ||
</mods:name> | ||
</mods> | ||
XML | ||
end | ||
let(:ng_rec) { Nokogiri::XML.parse(record) } | ||
|
||
context 'when contributor role matches the search' do | ||
before do | ||
indexer.instance_eval do | ||
to_field 'cho_contributor', extract_name('//*/mods:name[1][mods:role/mods:roleTerm/', role: 'copyist.') | ||
end | ||
end | ||
|
||
it 'returns values with a mapped role' do | ||
expect(indexer.map_record(ng_rec)).to eq({ 'cho_contributor' => ['Doe, John (Copyist)'] }) | ||
end | ||
end | ||
|
||
context 'when contributor role does not match the search' do | ||
before do | ||
indexer.instance_eval do | ||
to_field 'cho_contributor', extract_name('//*/mods:name[1][mods:role/mods:roleTerm/', role: 'scribe.') | ||
end | ||
end | ||
|
||
it 'returns an empty hash' do | ||
expect(indexer.map_record(ng_rec)).to eq({}) | ||
end | ||
end | ||
|
||
context 'when role is excluded from the search' do | ||
before do | ||
indexer.instance_eval do | ||
to_field 'cho_contributor', extract_name('//*/mods:name[1][mods:role/mods:roleTerm/', exclude: true) | ||
end | ||
end | ||
|
||
it 'returns values without role included' do | ||
expect(indexer.map_record(ng_rec)).to eq({ 'cho_contributor' => ['Doe, John'] }) | ||
end | ||
end | ||
end | ||
end |