Skip to content

Commit

Permalink
Merge pull request #915 from ElixirTeSS/edam-synonyms
Browse files Browse the repository at this point in the history
Synonyms for EDAM terms
  • Loading branch information
fbacall authored Feb 13, 2024
2 parents 79d36c7 + 992e410 commit 2e75ee5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
19 changes: 19 additions & 0 deletions app/models/concerns/has_edam_terms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module HasEdamTerms
extend ActiveSupport::Concern

def scientific_topics_and_synonyms
edam_term_names_and_synonyms(scientific_topics)
end

def operations_and_synonyms
edam_term_names_and_synonyms(operations)
end

private

def edam_term_names_and_synonyms(terms)
terms.map do |term|
[term.preferred_label] + term.has_exact_synonym + term.has_narrow_synonym
end.flatten.uniq
end
end
11 changes: 9 additions & 2 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Event < ApplicationRecord
include HasFriendlyId
include FuzzyDictionaryMatch
include WithTimezone
include HasEdamTerms

before_validation :fix_keywords, on: :create, if: :scraper_record
before_validation :presence_default
Expand All @@ -40,6 +41,12 @@ class Event < ApplicationRecord
text :content_provider do
content_provider.title unless content_provider.nil?
end
text :scientific_topics do
scientific_topics_and_synonyms
end
text :operations do
operations_and_synonyms
end
# sort title
string :sort_title do
title.downcase.gsub(/^(an?|the) /, '')
Expand Down Expand Up @@ -70,10 +77,10 @@ class Event < ApplicationRecord
associated_nodes.pluck(:name)
end
string :scientific_topics, multiple: true do
scientific_topic_names
scientific_topics_and_synonyms
end
string :operations, multiple: true do
operation_names
operations_and_synonyms
end
string :target_audience, multiple: true
boolean :online do
Expand Down
11 changes: 9 additions & 2 deletions app/models/material.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Material < ApplicationRecord
include IdentifiersDotOrg
include HasFriendlyId
include HasDifficultyLevel
include HasEdamTerms

if TeSS::Config.solr_enabled
# :nocov:
Expand All @@ -32,6 +33,12 @@ class Material < ApplicationRecord
text :content_provider do
self.content_provider.try(:title)
end
text :scientific_topics do
scientific_topics_and_synonyms
end
text :operations do
operations_and_synonyms
end
# sort title
string :sort_title do
title.downcase.gsub(/^(an?|the) /, '')
Expand All @@ -40,10 +47,10 @@ class Material < ApplicationRecord
string :title
string :authors, :multiple => true
string :scientific_topics, :multiple => true do
self.scientific_topic_names
scientific_topics_and_synonyms
end
string :operations, :multiple => true do
self.operation_names
operations_and_synonyms
end
string :target_audience, :multiple => true
string :keywords, :multiple => true
Expand Down
6 changes: 5 additions & 1 deletion app/models/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Workflow < ApplicationRecord
include HasFriendlyId
include CurationQueue
include HasDifficultyLevel
include HasEdamTerms

if TeSS::Config.solr_enabled
# :nocov:
Expand All @@ -28,9 +29,12 @@ class Workflow < ApplicationRecord
node_index('description')
end
text :authors
text :scientific_topics do
scientific_topics_and_synonyms
end
string :authors, :multiple => true
string :scientific_topics, :multiple => true do
self.scientific_topic_names
scientific_topics_and_synonyms
end
text :target_audience
string :target_audience, :multiple => true
Expand Down
17 changes: 17 additions & 0 deletions test/models/event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,21 @@ class EventTest < ActiveSupport::TestCase
refute @event.valid?
end
end

test 'scientific_topics_and_synonyms' do
@event.scientific_topic_names = ['Data governance']
@event.save!
assert_equal ['Data governance', 'Data stewardship'], @event.reload.scientific_topics_and_synonyms

@event.scientific_topic_names = ['Data governance', 'Data stewardship']
@event.save!
assert_equal ['Data governance', 'Data stewardship'], @event.reload.scientific_topics_and_synonyms
end

test 'operations_and_synonyms' do
@event.operation_names = ['Fold recognition', 'Fold prediction']
@event.save!
assert_equal ['Fold recognition', 'Domain prediction', 'Fold prediction', 'Protein domain prediction',
'Protein fold prediction', 'Protein fold recognition'], @event.reload.operations_and_synonyms
end
end

0 comments on commit 2e75ee5

Please sign in to comment.