-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor how TIMDEX records are nomalized #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,142 @@ | ||
# Transforms a TIMDEX result into a normalized record. | ||
class NormalizeTimdexRecord | ||
def initialize(record, query) | ||
@record = record | ||
@query = query | ||
end | ||
|
||
def normalize | ||
{ | ||
# Core fields | ||
'title' => title, | ||
'creators' => creators, | ||
'source' => source, | ||
'year' => year, | ||
'format' => format, | ||
'links' => links, | ||
'citation' => citation, | ||
'identifier' => identifier, | ||
'summary' => summary, | ||
'publisher' => publisher, | ||
'location' => location, | ||
'subjects' => subjects, | ||
# TIMDEX-specific fields | ||
'content_type' => content_type, | ||
'dates' => dates, | ||
'contributors' => contributors, | ||
'highlight' => highlight, | ||
'source_link' => source_link | ||
} | ||
end | ||
|
||
private | ||
|
||
def title | ||
@record['title'] || 'Unknown title' | ||
end | ||
|
||
def creators | ||
return [] unless @record['contributors'] | ||
|
||
# Convert TIMDEX contributors to Primo-style creators format | ||
@record['contributors'] | ||
.select { |c| %w[Creator Author].include?(c['kind']) } | ||
.map { |creator| { 'value' => creator['value'], 'link' => nil } } | ||
end | ||
|
||
def source | ||
return 'Unknown source' unless @record['source'] | ||
|
||
@record['source'] | ||
end | ||
|
||
def year | ||
# Extract year from dates | ||
return nil unless @record['dates'] | ||
|
||
pub_date = @record['dates'].find { |date| date['kind'] == 'Publication date' } | ||
return pub_date['value']&.match(/\d{4}/)&.to_s if pub_date | ||
|
||
# Fallback to any date with a year | ||
@record['dates'].each do |date| | ||
year_match = date['value']&.match(/\d{4}/) | ||
return year_match.to_s if year_match | ||
end | ||
end | ||
|
||
def format | ||
return '' unless @record['contentType'] | ||
|
||
@record['contentType'].map { |type| type['value'] }.join(' ; ') | ||
end | ||
|
||
def links | ||
links = [] | ||
|
||
# Add source link if available | ||
if @record['sourceLink'] | ||
links << { | ||
'kind' => 'full record', | ||
'url' => @record['sourceLink'], | ||
'text' => 'View full record' | ||
} | ||
end | ||
|
||
links | ||
end | ||
|
||
def citation | ||
@record['citation'] || nil | ||
end | ||
|
||
def summary | ||
return nil unless @record['summary'] | ||
|
||
@record['summary'].is_a?(Array) ? @record['summary'].join(' ') : @record['summary'] | ||
end | ||
|
||
def publisher | ||
# Extract from contributors or other fields | ||
return nil unless @record['contributors'] | ||
|
||
publisher = @record['contributors'].find { |c| c['kind'] == 'Publisher' } | ||
publisher&.dig('value') | ||
end | ||
|
||
def location | ||
return nil unless @record['locations'] | ||
|
||
@record['locations'].map { |loc| loc['value'] }.compact.join('; ') | ||
end | ||
|
||
def subjects | ||
return [] unless @record['subjects'] | ||
|
||
@record['subjects'].map { |subject| subject['value'] } | ||
end | ||
|
||
def identifier | ||
@record['timdexRecordId'] | ||
end | ||
|
||
# TIMDEX-specific methods | ||
def content_type | ||
@record['contentType'] | ||
end | ||
|
||
def dates | ||
@record['dates'] | ||
end | ||
|
||
def contributors | ||
@record['contributors'] | ||
end | ||
|
||
def highlight | ||
@record['highlight'] | ||
end | ||
|
||
def source_link | ||
@record['sourceLink'] | ||
end | ||
end |
This file contains hidden or 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,15 @@ | ||
# Batch normalization for TIMDEX API results | ||
class NormalizeTimdexResults | ||
def initialize(results, query) | ||
@results = results | ||
@query = query | ||
end | ||
|
||
def normalize | ||
return [] unless @results.is_a?(Array) | ||
|
||
@results.filter_map do |doc| | ||
NormalizeTimdexRecord.new(doc, @query).normalize | ||
end | ||
end | ||
end |
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,34 +1,38 @@ | ||
<li class="result"> | ||
<div class="result-content"> | ||
<h3 class="record-title"> | ||
<span class="sr">Title: </span><%= link_to(result_geo['title'], record_path(result_geo['timdexRecordId'])) %> | ||
<span class="sr">Title: </span><%= link_to(result_geo['title'], record_path(result_geo['identifier'])) %> | ||
</h3> | ||
|
||
<div class="data-info"> | ||
<%= render partial: 'shared/geo_data_info', locals: { metadata: result_geo } %> | ||
jazairi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</div> | ||
|
||
<% if result_geo['contributors'] %> | ||
<% if result_geo['creators'].present? || result_geo['contributors'].present? %> | ||
<span class="sr">Contributors: </span> | ||
<ul class="list-inline truncate-list contributors"> | ||
<%= render partial: 'shared/contributors', locals: { contributors: result_geo['contributors'] } %> | ||
<!-- Use normalized creators if available, otherwise fall back to raw contributors --> | ||
<% contributors = result_geo['creators'].present? ? result_geo['creators'] : result_geo['contributors'] %> | ||
<% if contributors %> | ||
<%= render partial: 'shared/contributors', locals: { contributors: contributors } %> | ||
<% end %> | ||
</ul> | ||
<% end %> | ||
|
||
<% if result_geo['summary'] %> | ||
<% if result_geo['summary'].present? %> | ||
<p class="result-summary truncate-list"> | ||
<span class="sr">Summary: </span><%= result_geo['summary'].join(' ') %> | ||
<span class="sr">Summary: </span><%= result_geo['summary'] %> | ||
</p> | ||
<% end %> | ||
|
||
<% if result_geo['highlight'] %> | ||
<div class="result-highlights"> | ||
<%= render partial: 'search/highlights', locals: { result: result_geo } %> | ||
<%= render partial: 'search/highlights', locals: { result: { 'highlight' => result_geo['highlight'] } } %> | ||
</div> | ||
<% end %> | ||
|
||
<div class="result-record"> | ||
<%= view_record(result_geo['timdexRecordId']) %> | ||
<%= view_record(result_geo['identifier']) %> | ||
</div> | ||
</div> | ||
</li> |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.