Skip to content

Commit

Permalink
handle the merging of the same ontology from different portals
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Sep 3, 2024
1 parent 4cae3d6 commit 1da912f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ GEM
zeitwerk (2.6.18)

PLATFORMS
x86_64-linux
x86_64-linux-musl

DEPENDENCIES
Expand Down
8 changes: 2 additions & 6 deletions app/components/ontology_browse_card_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class OntologyBrowseCardComponent < ViewComponent::Base
include OntologiesHelper
include ApplicationHelper, OntologiesHelper, FederationHelper

def initialize(ontology: nil, onto_link: nil, text_color: nil, bg_light_color: nil, portal_name: nil)
super
Expand All @@ -17,11 +17,7 @@ def ontology
end

def external_ontology?
!@portal_name.blank?
end

def external_portal_name
@portal_name
!internal_ontology?(@ontology[:id]) || (Array(@ontology[:sources]).size > 1)
end

def onto_link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
= ontology[:name]+" ("+ontology[:acronym]+")"
= private_ontology_icon(ontology[:private])
- if external_ontology?
= render Display::InfoTooltipComponent.new(text: "Federated ontology from #{onto_link}", icon: 'external-link.svg')
= render Display::InfoTooltipComponent.new(text: "Federated ontology from #{ontology[:sources].map{|x| link_to(x,x)}.join(', ')}", icon: 'external-link.svg')
- if session[:user]&.admin?
- ontology_status = status_string(ontology)
= render Display::InfoTooltipComponent.new(text: ontology_status, icon: submission_status_icons(ontology_status))
Expand All @@ -18,7 +18,7 @@
= t('components.show_more')


- unless ontology[:fairScore].nil? || ontology[:acronym] == 'AGROVOC'
- unless ontology[:fairScore].nil? || ontology[:fairScore].zero? || ontology[:acronym] == 'AGROVOC'
.browse-fair
%p.browse-fair-title
= t('components.fair_score')
Expand All @@ -45,7 +45,7 @@
link: "#{onto_link}?p=notes" )


.d-flex.align-items-baseline.mt-1
.d-flex.w-100.mt-1.flex-wrap
- if ontology[:creationDate]
%span.mr-1
= render ChipButtonComponent.new(type: "clickable", style: style_bg) do
Expand Down Expand Up @@ -74,13 +74,17 @@
= render ChipButtonComponent.new(type: "clickable", text: t('components.view'), style: style_bg)

- if external_ontology?
%div.mx-1{title: content_tag(:div, "Source #{external_portal_name}"), data:{controller: 'tooltip', 'tooltip-interactive-value': 'true'}}
= render ChipButtonComponent.new(type: "clickable" , style: style_bg) do
%span.d-inline
%span.mr-1
= inline_svg 'logo-white.svg', width: "20", height: "20"
%span
= external_portal_name
- ontology[:sources].each do |id|
- config = ontology_portal_config(id)&.last || internal_portal_config(id) || {}
- unless config.blank?
%div.mx-1{title: content_tag(:div, "Source #{config[:name]}"), data:{controller: 'tooltip', 'tooltip-interactive-value': 'true'}}
= render ChipButtonComponent.new(type: "clickable" , style: style_bg) do
= link_to ontoportal_ui_link(id), target: '_top' do
%span.d-inline
%span.mr-1
= inline_svg 'logo-white.svg', width: "20", height: "20"
%span
= config[:name]

- if session[:user]&.admin?
%div.mx-1{title: content_tag(:div, debug(ontology), style: 'height: 300px; overflow: scroll'), data:{controller: 'tooltip', 'tooltip-interactive-value': 'true'}}
Expand Down
30 changes: 25 additions & 5 deletions app/controllers/concerns/submission_filter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module SubmissionFilter
extend ActiveSupport::Concern

include FederationHelper

BROWSE_ATTRIBUTES = ['ontology', 'submissionStatus', 'description', 'pullLocation', 'creationDate',
'contact', 'released', 'naturalLanguage', 'hasOntologyLanguage',
'hasFormalityLevel', 'isOfType', 'deprecated', 'status', 'metrics']
Expand Down Expand Up @@ -43,7 +45,10 @@ def submissions_paginate_filter(params)
groups: request_params[:group], categories: request_params[:hasDomain],
formats: request_params[:hasOntologyLanguage] }

submissions = filter_using_data(@ontologies, **params)
submissions = filter_submissions(@ontologies, **params)

submissions = merge_by_acronym(submissions)


submissions = sort_submission_by(submissions, @sort_by, @search)

Expand All @@ -60,10 +65,25 @@ def ontologies_filter_url(filters, page: 1, count: false)

private

def filter_using_data(ontologies, query:, status:, show_views:, private_only:, languages:, page_size:, formality_level:, is_of_type:, groups:, categories:, formats:)
def merge_by_acronym(submissions)
merged_submissions = []
submissions.group_by { |x| x[:ontology]&.acronym }.each do |acronym, ontologies|
if ontologies.size.eql?(1)
ontology = ontologies.first
else
ontology = ontologies.select { |x| helpers.internal_ontology?(x[:id]) }.first || ontologies.first
end

ontology[:sources] = ontologies.map { |x| x[:id] }
merged_submissions << ontology
end
merged_submissions
end

def filter_submissions(ontologies, query:, status:, show_views:, private_only:, languages:, page_size:, formality_level:, is_of_type:, groups:, categories:, formats:)
submissions = LinkedData::Client::Models::OntologySubmission.all(include: BROWSE_ATTRIBUTES.join(','), also_include_views: true, display_links: false, display_context: false)

submissions = submissions.map { |x| x[:ontology] ? [x[:ontology][:id], x] : nil}.compact.to_h
submissions = submissions.map { |x| x[:ontology] ? [x[:ontology][:id], x] : nil }.compact.to_h

submissions = ontologies.map { |ont| ontology_hash(ont, submissions) }

Expand Down Expand Up @@ -111,7 +131,7 @@ def paginate_submissions(all_submissions, page, size)
end

def sort_submission_by(submissions, sort_by, query = nil)
return submissions.sort_by { |x| x[:rank] ? -x[:rank] : 0} unless query.blank?
return submissions.sort_by { |x| x[:rank] ? -x[:rank] : 0 } unless query.blank?

if sort_by.eql?('visits')
submissions = submissions.sort_by { |x| -(x[:popularity] || 0) }
Expand Down Expand Up @@ -221,7 +241,7 @@ def ontology_hash(ont, submissions)

o[:note_count] = ont.notes&.length || 0
o[:project_count] = ont.projects&.length || 0
o[:popularity] = @analytics[ont.id.to_s] || 0
o[:popularity] = @analytics[ont.id.split('/').last.to_s] || 0
o[:rank] = sub ? sub[:rank] : 0

o
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def resolve_namespaces
def ontologies_analytics
begin
data = LinkedData::Client::Analytics.last_month.onts
data.map{|x| [x[:ont].to_s, x[:views]]}.to_h
data.map{|x| [x[:ont].split('/').last.to_s, x[:views]]}.to_h
rescue StandardError
{}
end
Expand Down

0 comments on commit 1da912f

Please sign in to comment.