Skip to content

Commit

Permalink
update solution mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
haddadzineddine committed Jun 20, 2023
1 parent 8af1d47 commit 5b7c78f
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lib/goo/sparql/mixins/solution_lang_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ def enrich_models(models_by_id)

objects_by_lang.each do |id, predicates|
model = models_by_id[id]
predicates.each do |predicate, values|
if @attributes_to_translate.any? { |attr| predicate.eql?(attr) }
save_model_values(model, values, predicate, unmapped)
end
predicates.each do |predicate, values|

if values.values.all? { |v| v.all? { |x| literal?(x) && x.plain?} }
save_model_values(model, values, predicate, unmapped)

end
end
end
end
Expand Down Expand Up @@ -100,7 +102,6 @@ def language_match?(language)

def store_objects_by_lang(id, predicate, object, language)
# store objects in this format: [id][predicate][language] = [objects]

return if requested_lang.is_a?(Array) && !requested_lang.include?(language)

language_key = language.downcase
Expand All @@ -123,6 +124,7 @@ def get_model_attribute_value(model, predicate)


def add_unmapped_to_model(model, predicate, value)

if model.respond_to? :klass # struct
model[:unmapped] ||= {}
model[:unmapped][predicate] ||= []
Expand All @@ -133,16 +135,10 @@ def add_unmapped_to_model(model, predicate, value)
end

def save_model_values(model, values, predicate, unmapped)
if unmapped
add_unmapped_to_model(model, predicate, values)
else

if !list_attributes?(predicate)
values = values.map { |k, v| [k, v.first] }.to_h
end
add_unmapped_to_model(model, predicate, values) if unmapped
values = values.map { |k, v| [k, v.first] }.to_h unless list_attributes?(predicate)

model.send("#{predicate}=", values, on_load: true)
end
model.send("#{predicate}=", values, on_load: true)
end

def unmapped_get(model, predicate)
Expand Down

0 comments on commit 5b7c78f

Please sign in to comment.