Skip to content

Commit

Permalink
handle being able to get additional details about the properties in t…
Browse files Browse the repository at this point in the history
…he fair data station TTL #2134
  • Loading branch information
stuzart committed Feb 4, 2025
1 parent f2ee651 commit 56bd616
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
40 changes: 32 additions & 8 deletions lib/seek/fair_data_station/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def description
end

def annotations
@_cached_annotations ||= query_annotations
@annotations ||= query_annotations
end

def additional_metadata_annotations
Expand All @@ -51,6 +51,30 @@ def find_annotation_value(property)
end&.[](1)
end

# get more details about an annotation from the given property uri
def annotation_details(property)
result = { 'property_id' => property }

query = RDF::Query.new do
pattern [RDF::Resource.new(property), RDF::RDFS.label, :label]
pattern [RDF::Resource.new(property), RDF::Vocab::SCHEMA.description, :description]
pattern [RDF::URI.new(property), RDF::Vocab::SCHEMA.valuePattern, :pattern]
pattern [RDF::URI.new(property), RDF::Vocab::SCHEMA.valueRequired, :required]
end
solution = query.execute(graph).first
result['label'] = solution[:label].value
result['description'] = solution[:description].value
result['pattern'] = solution[:pattern].value
result['required'] = solution[:required].true?
result
end

def additional_metadata_annotation_details
additional_metadata_annotations.collect do |annotation|
annotation_details(annotation[0])
end
end

def pp_annotations
annotations.sort_by { |a| a[0] }.each do |pair|
pp "#{pair[0]} -> #{pair[1]}"
Expand Down Expand Up @@ -115,17 +139,17 @@ def populate_seek_extended_metadata_for_property(extended_metadata_type, data, p
else
linked_attributes = extended_metadata_type.attributes_with_linked_extended_metadata_type
linked_attributes.each do |linked_attribute|
result = populate_seek_extended_metadata_for_property(linked_attribute.linked_extended_metadata_type, {},
property_id, value)
next if result.empty?

result = populate_seek_extended_metadata_for_property(linked_attribute.linked_extended_metadata_type, { }, property_id, value)
unless result.empty?
data[linked_attribute.accessor_name] ||= {}
data[linked_attribute.accessor_name].merge!(result)
break
end
data[linked_attribute.accessor_name] ||= {}
data[linked_attribute.accessor_name].merge!(result)
break
end
end

return data
data
end

def query_annotations
Expand Down
28 changes: 28 additions & 0 deletions test/unit/fair_data_station/fair_data_station_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,32 @@ class FairDataStationReaderTest < ActiveSupport::TestCase
assert_equal 0, obs_unit.datasets.count
assert_equal 0, sample.datasets.count
end

test 'get annotation details' do
path = "#{Rails.root}/test/fixtures/files/fair_data_station/seek-fair-data-station-test-case.ttl"
inv = Seek::FairDataStation::Reader.new.parse_graph(path).first

det = inv.annotation_details('http://fairbydesign.nl/ontology/date_of_birth')
assert_equal 'date of birth', det['label']
assert_equal 'Date of birth of subject the sample was derived from.', det['description']
assert_equal 'http://fairbydesign.nl/ontology/date_of_birth', det['property_id']
assert_equal '.+', det['pattern']
assert_equal false, det['required']

det = inv.annotation_details('http://gbol.life/0.1/scientificName')
assert_equal 'scientific name', det['label']
assert_equal 'Name of the organism', det['description']
assert_equal 'http://gbol.life/0.1/scientificName', det['property_id']
assert_equal '.*', det['pattern']
assert_equal true, det['required']
end

test 'get all additional_metadata_annotation_details' do
path = "#{Rails.root}/test/fixtures/files/fair_data_station/seek-fair-data-station-test-case.ttl"
inv = Seek::FairDataStation::Reader.new.parse_graph(path).first
study = inv.studies.first
details = study.additional_metadata_annotation_details
assert_equal 3, details.count
assert_equal ["end date of study", "experimental site name", "start date of study"], details.collect { |d| d['label'] }.sort
end
end

0 comments on commit 56bd616

Please sign in to comment.