🐛 Preserve URI values in Bulkrax subject parsing - #122
Conversation
Bulkrax's ApplicationMatcher#parse_subject lowercases the entire value then capitalizes the first character. This turns "http://id.loc.gov/..." into "Http://id.loc.gov/...", breaking every downstream check that pattern-matches on the URI scheme, including UtkUriLabelIndexing. Decorate parse_subject to return URIs verbatim while still applying sentence-casing to plain text subjects. The regex guards on http(s):// which covers all URI schemes in UTK's controlled vocabulary fields. Ref: - #73 Assisted by: Claude Opus 4.6
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, matches the stated expected behavior, and includes direct and integration-level spec coverage for the regression.
Pull request overview
This PR fixes Bulkrax subject parsing so URI values (e.g., http://id.loc.gov/...) are preserved verbatim rather than being sentence-cased into an invalid URI scheme (Http://...). This prevents downstream URI-detection logic (e.g., checks that rely on http:// / https://) from breaking while keeping sentence-casing behavior for plain-text subjects.
Changes:
- Add a
Bulkrax::ApplicationMatcherdecorator that returnshttp(s)://subjects unchanged (aside from whitespace stripping), delegating to Bulkrax’s original behavior for plain text. - Add RSpec coverage validating URI preservation, whitespace stripping, plain-text sentence-casing, blank handling, and integration through
#result.
File summaries
| File | Description |
|---|---|
| app/matchers/bulkrax/application_matcher_decorator.rb | Prepends an override of parse_subject to preserve http(s):// URIs verbatim while retaining Bulkrax’s original behavior for non-URI values. |
| spec/matchers/bulkrax/application_matcher_decorator_spec.rb | Adds specs ensuring URI values aren’t capitalized and verifying behavior for plain text, whitespace, blanks, and the full matcher pipeline. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
6f5ecfc to
90c916b
Compare
Downcase the entire URI instead of returning it verbatim so that capitalized schemes from either Bulkrax's sentence-casing or from the CSV itself (Http://, HTTP://) are normalized to lowercase, which UriLabelResolver requires to resolve labels. Assisted by: Claude Opus 4.6
90c916b to
7bb2b37
Compare
laritakr
left a comment
There was a problem hiding this comment.
Do we have a followup ticket to get Bulkrax updated so we can get this cleaned up? I'd anticipate more work coming too.
I'll make a general placeholder ticket to update Bulkrax: #133 Here is the equivalent PR this is decorating: samvera/bulkrax#1214 |
Story
Refs
🐛 Preserve URI values in Bulkrax subject parsing
440ebd2
Bulkrax's ApplicationMatcher#parse_subject lowercases the entire
value then capitalizes the first character. This turns
"http://id.loc.gov/..." into "Http://id.loc.gov/...", breaking
every downstream check that pattern-matches on the URI scheme,
including UtkUriLabelIndexing.
Decorate parse_subject to return URIs verbatim while still applying
sentence-casing to plain text subjects. The regex guards on
http(s):// which covers all URI schemes in UTK's controlled
vocabulary fields.
Expected Behavior Before Changes
Bulkrax CSV import of a subject URI like
http://id.loc.gov/authorities/subjects/sh85101348storesHttp://id.loc.gov/authorities/subjects/sh85101348in parsed metadata. The capitalized scheme breaks URI detection in UtkUriLabelIndexing and any other code pattern-matching onhttp://.Expected Behavior After Changes
URI values in subject fields are preserved verbatim through Bulkrax's parsing pipeline. Plain text subjects still receive sentence-casing ("photography" becomes "Photography").
Screenshots / Video
No UI change. Data parsing fix verified by specs.
Notes
ApplicationMatcher#parse_subject(line 69-73 ofapplication_matcher.rbin Bulkrax 9.5.1), which was written assuming subjects are plain text, not URIsImporter#field_mappingis blank in the DB, soImporter#mappingfalls back todefault_field_mappingwhich auto-setsparsed: truefor any field with aparse_*method, ignoring UTK's custom mappings that omit theparsedflagcontribute back🤖 Generated with Claude Code
https://claude.ai/code/session_017ShYMAGZMpZ5mFuqmAuckf