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
Expand context when the value is an URI and expasion was requested in the config #204
Conversation
@@ -68,7 +68,7 @@ def add_group(group_id, group_map) | |||
return if groups.key? group_id | |||
i18n_key = Qa::LinkedData::Config::Helper.fetch(group_map, :group_label_i18n, nil) | |||
default = Qa::LinkedData::Config::Helper.fetch(group_map, :group_label_default, nil) | |||
return groups[group_id] = I18n.t(i18n_key, default) if i18n_key.present? | |||
return groups[group_id] = I18n.t(i18n_key, default: default) if i18n_key.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BUGFIX: passing default incorrectly to i18n
6c97a5d
to
0c6de05
Compare
def drillable? | ||
@drillable | ||
end | ||
|
||
def group? | ||
group_id.present? | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
READABILITY: Just moved group?
up so all the ? methods are together. No code change.
output.present? ? output['property'].uniq : nil | ||
rescue | ||
'PARSE ERROR' | ||
ldpath_evaluate(basic_program, graph, subject_uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY: Moved the ldpath evaluate process to a private method so it can be shared by multiple methods.
@@ -21,7 +21,7 @@ class << self | |||
def map_context(graph:, context_map:, subject_uri:) | |||
context = [] | |||
context_map.properties.each do |property_map| | |||
values = property_map.values(graph, subject_uri) | |||
values = values(property_map, graph, subject_uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RUBOCOP: Extracted to a private method to appease rubocop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elrayle you may be sad later on when you try and find values. It is not a very distinct name. Is it really expanded_values
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed by renaming method values
to property_values
.
context = context_mapper_service.map_context(graph: graph, context_map: context_map, subject_uri: subject) if context_map.present? | ||
value_map[:context] = context | ||
value_map | ||
map_context(graph, sort_key, context_map, value_map, subject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RUBOCOP: Extracted to a private method to appease rubocop.
end | ||
search_matches << values unless sort_key.present? && values[sort_key].blank? | ||
search_matches << values if result_subject? values, sort_key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY: Extracted to a private method so the check for sort_key can happen here and in the context mapping code.
|
||
def map_context(graph, sort_key, context_map, value_map, subject) | ||
return value_map if context_map.blank? | ||
return value_map unless result_subject? value_map, sort_key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PERFORMANCE: Added this check because we shouldn't take the time to map context if the current subject isn't an actual search result.
allow(I18n).to receive(:t).with('qa.linked_data.authority.locnames_ld4l_cache.dates', 'default_Dates').and_return('Dates') | ||
allow(I18n).to receive(:t).with('qa.linked_data.authority.locnames_ld4l_cache.authoritative_label', 'default_Authoritative Label').and_return('Authoritative Label') | ||
allow(I18n).to receive(:t).with('qa.linked_data.authority.locnames_ld4l_cache.birth_date', 'default_Birth').and_return('Birth') | ||
allow(I18n).to receive(:t).with('qa.linked_data.authority.locnames_ld4l_cache.death_date', 'default_Death').and_return('Death') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEADCODE: These weren't needed for the tests to pass.
@@ -75,6 +71,10 @@ | |||
describe '#group_label' do | |||
context 'when map defines group_label_i18n key' do | |||
context 'and i18n translation is defined in locales' do | |||
before do | |||
allow(I18n).to receive(:t).with('qa.linked_data.authority.locnames_ld4l_cache.dates', default: 'default_Dates').and_return('Dates') | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
READABILITY: Moved closer to test.
output = program.evaluate subject_uri, graph | ||
output.present? ? output['property'].uniq : nil | ||
rescue | ||
'PARSE ERROR' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elrayle I know this is not new code, but where does the string show up to the user? I'm wondering if it should be logged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cam156 Are you asking about the 'PARSE ERROR' string? This is a stop gap from the ldpath gem failing to parse some ldpaths. So it would show up here...
{
group: "Hierarchy",
property: "Narrower",
values: [ 'PARSE ERROR' ],
selectable: true,
drillable: true
},
Not ideal. Better is perhaps logging and returning nothing for the property that wouldn't parse or values: ['']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elrayle I was just wondering if it was something people would notice. Rescuing errors and silently handling them is something I have done and regretted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With 2nd commit, reworked the results so that the error is in a separate field in the hash...
{
group: "Hierarchy",
property: "Narrower",
values: [],
selectable: true,
drillable: true,
error: "LDPATH PARSE ERROR (See log for more information)"
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elrayle A couple small suggestions, but nothing blocking
@@ -21,7 +21,7 @@ class << self | |||
def map_context(graph:, context_map:, subject_uri:) | |||
context = [] | |||
context_map.properties.each do |property_map| | |||
values = property_map.values(graph, subject_uri) | |||
values = values(property_map, graph, subject_uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elrayle you may be sad later on when you try and find values. It is not a very distinct name. Is it really expanded_values
?
0c6de05
to
0df08a6
Compare
end | ||
|
||
def ldpath_evaluate(program, graph, subject_uri) | ||
return PARSE_ERROR_VALUE if program.blank? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elrayle Hate to cause issues, but did you mean nil? Is the empty string a valid value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With 2nd commit, now returns an empty array when an error occurs. The value on error is set in ContextMapperService using the ContextPropertyMap::VALUE_ON_ERROR constant.
property_info = {} | ||
property_info["group"] = context_map.group_label(property_map.group_id) if property_map.group? | ||
property_info["property"] = property_map.label | ||
property_info["values"] = values | ||
property_info["selectable"] = property_map.selectable? | ||
property_info["drillable"] = property_map.drillable? | ||
property_info["error"] = error if error.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Adds:
Fixes:
Examples:
Regular context (from previous PR)
Expanding URI values in context (with this PR)