Skip to content

Commit

Permalink
Merge branch 'master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Dec 5, 2023
2 parents a199eff + c20e1d3 commit 564c605
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 88 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ end
group :development do
gem 'rubocop', require: false
end

# NCBO gems (can be from a local dev path or from rubygems/git)
gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development'
gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'master'
gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'master'
2 changes: 1 addition & 1 deletion lib/ontologies_linked_data/models/ontology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OntologyAnalyticsError < StandardError; end

attribute :acl, enforce: [:list, :user]

attribute :viewOf, enforce: [:ontology]
attribute :viewOf, enforce: [:ontology], onUpdate: :update_submissions_has_part
attribute :views, :inverse => { on: :ontology, attribute: :viewOf }
attribute :ontologyType, enforce: [:ontology_type], default: lambda { |record| LinkedData::Models::OntologyType.find("ONTOLOGY").include(:code).first }

Expand Down
33 changes: 16 additions & 17 deletions lib/ontologies_linked_data/serializers/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.serialize(obj, options = {})
end

# Add the type
hash["@type"] = type(current_cls, hashed_obj) if hash["@id"]
hash["@type"] = type(current_cls, hashed_obj) if hash["@id"]

# Generate links
# NOTE: If this logic changes, also change in xml.rb
Expand All @@ -39,8 +39,8 @@ def self.serialize(obj, options = {})
end
elsif (hashed_obj.instance_of?(LinkedData::Models::ExternalClass) || hashed_obj.instance_of?(LinkedData::Models::InterportalClass)) && !current_cls.embedded?
# Add context for ExternalClass
context_hash = {"@vocab" => Goo.vocabulary.to_s, "prefLabel" => "http://data.bioontology.org/metadata/skosprefLabel"}
context = {"@context" => context_hash}
context_hash = { "@vocab" => Goo.vocabulary.to_s, "prefLabel" => "http://data.bioontology.org/metadata/skosprefLabel" }
context = { "@context" => context_hash }
hash.merge!(context)
end
hash['@context']['@language'] = result_lang if hash['@context']
Expand Down Expand Up @@ -103,17 +103,17 @@ def self.generate_context(object, serialized_attrs = [], options = {})

if linked_model && linked_model.ancestors.include?(Goo::Base::Resource) && !embedded?(object, attr)
# linked object
predicate = {"@id" => linked_model.type_uri.to_s, "@type" => "@id"}
predicate = { "@id" => linked_model.type_uri.to_s, "@type" => "@id" }
else
# use the original predicate property if set
predicate_attr = current_cls.model_settings[:attributes][attr][:property] || attr
predicate_attr = current_cls.model_settings[:attributes][attr][:property] || attr
# predicate with custom namespace
# if the namespace can be resolved by the namespaces added in Goo then it will be resolved.
predicate = "#{Goo.vocabulary(current_cls.model_settings[:attributes][attr][:namespace])&.to_s}#{predicate_attr}"
end
hash[attr] = predicate unless predicate.nil?
end
context = {"@context" => hash}
context = { "@context" => hash }
CONTEXTS[object.hash] = context
context = remove_unused_attrs(context, serialized_attrs) unless options[:params] && options[:params]["full_context"].eql?("true")
context
Expand All @@ -126,12 +126,12 @@ def self.generate_links_context(object)
links.each do |link|
links_context[link.type] = link.type_uri.to_s
end
return {"@context" => links_context}
return { "@context" => links_context }
end

def self.remove_unused_attrs(context, serialized_attrs = [])
new_context = context["@context"].reject {|k,v| !serialized_attrs.include?(k) && !k.to_s.start_with?("@")}
{"@context" => new_context}
new_context = context["@context"].reject { |k, v| !serialized_attrs.include?(k) && !k.to_s.start_with?("@") }
{ "@context" => new_context }
end

def self.embedded?(object, attribute)
Expand All @@ -148,20 +148,19 @@ def self.generate_context?(options)
params = options[:params]
params.nil? ||
(params["no_context"].nil? ||
!params["no_context"].eql?("true")) &&
(params["display_context"].nil? ||
!params["display_context"].eql?("false"))
!params["no_context"].eql?("true")) &&
(params["display_context"].nil? ||
!params["display_context"].eql?("false"))
end

def self.generate_links?(options)
params = options[:params]
params.nil? ||
(params["no_links"].nil? ||
!params["no_links"].eql?("true")) &&
(params["display_links"].nil? ||
!params["display_links"].eql?("false"))
!params["no_links"].eql?("true")) &&
(params["display_links"].nil? ||
!params["display_links"].eql?("false"))
end
end
end
end

end
136 changes: 68 additions & 68 deletions test/models/test_ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,26 @@ def test_skos_ontology

sub = LinkedData::Models::OntologySubmission.where(ontology: [acronym: "SKOS-TEST"],
submissionId: 987)
.include(:version)
.first
.include(:version)
.first
assert sub.roots.map { |x| x.id.to_s}.sort == ["http://www.ebi.ac.uk/efo/EFO_0000311",
"http://www.ebi.ac.uk/efo/EFO_0001444",
"http://www.ifomis.org/bfo/1.1/snap#Disposition",
"http://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:37577",
"http://www.ebi.ac.uk/efo/EFO_0000635",
"http://www.ebi.ac.uk/efo/EFO_0000324"].sort
"http://www.ebi.ac.uk/efo/EFO_0001444",
"http://www.ifomis.org/bfo/1.1/snap#Disposition",
"http://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:37577",
"http://www.ebi.ac.uk/efo/EFO_0000635",
"http://www.ebi.ac.uk/efo/EFO_0000324"].sort
roots = sub.roots
LinkedData::Models::Class.in(sub).models(roots).include(:children).all
roots.each do |root|
q_broader = <<-eos
q_broader = <<-eos
SELECT ?children WHERE {
?children #{RDF::SKOS[:broader].to_ntriples} #{root.id.to_ntriples} }
eos
children_query = []
Goo.sparql_query_client.query(q_broader).each_solution do |sol|
children_query << sol[:children].to_s
end
assert root.children.map { |x| x.id.to_s }.sort == children_query.sort
children_query = []
Goo.sparql_query_client.query(q_broader).each_solution do |sol|
children_query << sol[:children].to_s
end
assert root.children.map { |x| x.id.to_s }.sort == children_query.sort
end
end

Expand All @@ -149,11 +149,11 @@ def test_multiple_syn_multiple_predicate
#test for version info
sub = LinkedData::Models::OntologySubmission.where(ontology: [acronym: "HP-TEST"],
submissionId: 55)
.include(:version)
.first
.include(:version)
.first

paging = LinkedData::Models::Class.in(sub).page(1,100)
.include(:unmapped)
.include(:unmapped)
found = false

begin
Expand Down Expand Up @@ -222,42 +222,42 @@ def test_obo_part_of
#strict comparison to be sure the merge with the tree_view branch goes fine

LinkedData::Models::Class.where.in(sub).include(:prefLabel,:synonym,:notation).each do |cls|
assert_instance_of String,cls.prefLabel
if cls.notation.nil?
assert false,"notation empty"
end
assert_instance_of String,cls.notation
assert cls.notation[-6..-1] == cls.id.to_s[-6..-1]
#NCBO-1007 - hasNarrowSynonym
if cls.id.to_s["CL_0000003"]
assert cls.synonym[0] == "cell in vivo"
end
#NCBO-1007 - hasBroadSynonym
if cls.id.to_s["CL_0000137"]
assert cls.synonym[0] == "bone cell"
end
#NCBO-1007 - hasRelatedSynonym
if cls.id.to_s["TAO_0000223"]
assert cls.synonym.length == 6
end
assert_instance_of String,cls.prefLabel
if cls.notation.nil?
assert false,"notation empty"
end
assert_instance_of String,cls.notation
assert cls.notation[-6..-1] == cls.id.to_s[-6..-1]
#NCBO-1007 - hasNarrowSynonym
if cls.id.to_s["CL_0000003"]
assert cls.synonym[0] == "cell in vivo"
end
#NCBO-1007 - hasBroadSynonym
if cls.id.to_s["CL_0000137"]
assert cls.synonym[0] == "bone cell"
end
#NCBO-1007 - hasRelatedSynonym
if cls.id.to_s["TAO_0000223"]
assert cls.synonym.length == 6
end
end

# This is testing that treeView is used to traverse the hierarchy
sub.bring(:hasOntologyLanguage)
assert sub.hasOntologyLanguage.tree_property == Goo.vocabulary(:metadata)[:treeView]

bm = LinkedData::Models::Class
.find(RDF::URI.new("http://purl.obolibrary.org/obo/GO_0070977"))
.in(sub)
.include(:prefLabel,:children,:parents)
.first
.find(RDF::URI.new("http://purl.obolibrary.org/obo/GO_0070977"))
.in(sub)
.include(:prefLabel,:children,:parents)
.first
assert bm.children.first.id == RDF::URI.new("http://purl.obolibrary.org/obo/GO_0043931")
assert_equal 2, bm.parents.length
roots = sub.roots
assert roots.map { |x| x.id.to_s }.sort ==
["http://purl.obolibrary.org/obo/PATO_0000001",
"http://purl.obolibrary.org/obo/CARO_0000000",
"http://purl.obolibrary.org/obo/GO_0008150"].sort
["http://purl.obolibrary.org/obo/PATO_0000001",
"http://purl.obolibrary.org/obo/CARO_0000000",
"http://purl.obolibrary.org/obo/GO_0008150"].sort
end

def test_submission_parse_subfolders_zip
Expand All @@ -280,14 +280,14 @@ def test_submission_parse
# This one has some nasty looking IRIS with slashes in the anchor
unless ENV["BP_SKIP_HEAVY_TESTS"] == "1"
submission_parse("MCCLTEST", "MCCLS TEST",
"./test/data/ontology_files/CellLine_OWL_BioPortal_v1.0.owl", 11,
"./test/data/ontology_files/CellLine_OWL_BioPortal_v1.0.owl", 11,
process_rdf: true, index_search: true,
run_metrics: false, reasoning: true)

sub = LinkedData::Models::OntologySubmission.where(ontology: [acronym: "MCCLTEST"],
submissionId: 11)
.include(:version)
.first
.include(:version)
.first
assert sub.version == "3.0"
end

Expand All @@ -300,8 +300,8 @@ def test_submission_parse

sub = LinkedData::Models::OntologySubmission.where(ontology: [acronym: "ONTOMATEST"],
submissionId: 15)
.include(:version)
.first
.include(:version)
.first
assert sub.version["Version 1.1"]
assert sub.version["Date: 11-2011"]
end
Expand Down Expand Up @@ -361,16 +361,16 @@ def test_process_submission_archive
assert latest_sub.archived?

assert File.file?(File.join(latest_sub.data_folder, 'labels.ttl')),
%-Missing ontology submission file: 'labels.ttl'-
%-Missing ontology submission file: 'labels.ttl'-

assert File.file?(File.join(latest_sub.data_folder, 'owlapi.xrdf')),
%-Missing ontology submission file: 'owlapi.xrdf'-
%-Missing ontology submission file: 'owlapi.xrdf'-

assert File.file?(latest_sub.csv_path),
%-Missing ontology submission file: '#{latest_sub.csv_path}'-
%-Missing ontology submission file: '#{latest_sub.csv_path}'-

assert File.file?(latest_sub.parsing_log_path),
%-Missing ontology submission file: '#{latest_sub.parsing_log_path}'-
%-Missing ontology submission file: '#{latest_sub.parsing_log_path}'-

# Process one prior to latest submission. Some files should be deleted.
old_sub = sorted_submissions.last
Expand All @@ -379,19 +379,19 @@ def test_process_submission_archive
assert old_sub.archived?

assert_equal false, File.file?(File.join(old_sub.data_folder, 'labels.ttl')),
%-File deletion failed for 'labels.ttl'-
%-File deletion failed for 'labels.ttl'-

assert_equal false, File.file?(File.join(old_sub.data_folder, 'mappings.ttl')),
%-File deletion failed for 'mappings.ttl'-
%-File deletion failed for 'mappings.ttl'-

assert_equal false, File.file?(File.join(old_sub.data_folder, 'obsolete.ttl')),
%-File deletion failed for 'obsolete.ttl'-
%-File deletion failed for 'obsolete.ttl'-

assert_equal false, File.file?(File.join(old_sub.data_folder, 'owlapi.xrdf')),
%-File deletion failed for 'owlapi.xrdf'-
%-File deletion failed for 'owlapi.xrdf'-

assert_equal false, File.file?(old_sub.csv_path),
%-File deletion failed for '#{old_sub.csv_path}'-
%-File deletion failed for '#{old_sub.csv_path}'-

assert_equal false, File.file?(old_sub.parsing_log_path),
%-File deletion failed for '#{old_sub.parsing_log_path}'-
Expand Down Expand Up @@ -606,10 +606,10 @@ def test_download_ontology_file
server_url = 'http://localhost:' + server_port.to_s
server_thread = Thread.new do
Rack::Server.start(
app: lambda do |e|
[200, {'Content-Type' => 'text/plain'}, ['test file']]
end,
Port: server_port
app: lambda do |e|
[200, {'Content-Type' => 'text/plain'}, ['test file']]
end,
Port: server_port
)
end
Thread.pass
Expand Down Expand Up @@ -767,7 +767,7 @@ def test_submission_root_classes
acr = "CSTPROPS"
init_test_ontology_msotest acr
os = LinkedData::Models::OntologySubmission.where(ontology: [ acronym: acr ], submissionId: 1)
.include(LinkedData::Models::OntologySubmission.attributes).all
.include(LinkedData::Models::OntologySubmission.attributes).all
assert(os.length == 1)
os = os[0]
roots = os.roots
Expand Down Expand Up @@ -851,8 +851,8 @@ def test_submission_parse_sbo
end
assert sub.ready?({status: [:uploaded, :rdf, :rdf_labels]})
page_classes = LinkedData::Models::Class.in(sub)
.page(1,1000)
.include(:prefLabel, :synonym).all
.page(1,1000)
.include(:prefLabel, :synonym).all
page_classes.each do |c|
if c.id.to_s == "http://purl.obolibrary.org/obo/SBO_0000004"
assert c.prefLabel == "modelling framework"
Expand Down Expand Up @@ -913,7 +913,7 @@ def test_submission_parse_cno
sub.submissionStatus.select { |x| x.id.to_s["ERROR"] }.length == 0

LinkedData::Models::Class.where.in(sub)
.include(:prefLabel, :notation, :prefixIRI).each do |cls|
.include(:prefLabel, :notation, :prefixIRI).each do |cls|
assert !cls.notation.nil? || !cls.prefixIRI.nil?
assert !cls.id.to_s.start_with?(":")
end
Expand Down Expand Up @@ -1000,9 +1000,9 @@ def test_submission_parse_aero
assert count_headers > 2

page_classes = LinkedData::Models::Class.in(sub)
.page(1,1000)
.read_only
.include(:prefLabel, :synonym, :definition).all
.page(1,1000)
.read_only
.include(:prefLabel, :synonym, :definition).all
page_classes.each do |c|
if c.id.to_s == "http://purl.obolibrary.org/obo/AERO_0000040"
assert c.prefLabel == "shaking finding"
Expand All @@ -1022,7 +1022,7 @@ def test_submission_parse_aero

#for indexing in search
paging = LinkedData::Models::Class.in(sub).page(1,100)
.include(:unmapped)
.include(:unmapped)
page = nil
defs = 0
syns = 0
Expand Down Expand Up @@ -1175,4 +1175,4 @@ def test_submission_delete_remove_files
sub.delete
assert !Dir.exist?(data_folder)
end
end
end

0 comments on commit 564c605

Please sign in to comment.