Module: Repo::MetadataJsonld

Extended by:
ActiveSupport::Concern
Defined in:
lib/repo/metadata_jsonld.rb

Instance Method Summary collapse

Instance Method Details

#conforms_toObject



129
130
131
132
133
134
# File 'lib/repo/metadata_jsonld.rb', line 129

def conforms_to
  {
    "@id": 'https://bioschemas.org/profiles/Study/0.3-DRAFT',
    "@type": 'CreativeWork'
  }
end

#data_catalog_contributorsObject



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/repo/metadata_jsonld.rb', line 107

def data_catalog_contributors
  an = json_ld_person('0000-0002-1692-6778', 'An', 'Nguyen')
  chia_lin = json_ld_person('0000-0002-9772-0455', 'Chia-Lin', 'Lin')
  felix = json_ld_person('0000-0002-5035-7978', 'Felix', 'Bach')
  nicole = json_ld_person('0000-0001-9513-2468', 'Nicole', 'Jung')
  pei_chi = json_ld_person('0000-0002-9976-4507', 'Pei-Chi', 'Huang')
  pierre = json_ld_person('0000-0002-0487-3947', 'Pierre', 'Tremouilhac')
  stefan = json_ld_person('0000-0003-4845-3191', 'Stefan', 'Braese')
  yu_chieh = json_ld_person('0000-0002-4261-9886', 'Yu-Chieh', 'Huang')

  arr = [an, chia_lin, felix, nicole, pei_chi, pierre, stefan, yu_chieh]
  arr
end

#data_catalog_keywords(pub = self) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/repo/metadata_jsonld.rb', line 90

def data_catalog_keywords(pub = self)
  sio = json_ld_defined_term_set('Semanticscience Integrated Ontology', 'https://raw.githubusercontent.com/micheldumontier/semanticscience/master/ontology/sio/release/sio-release.owl')
  ncit = json_ld_defined_term_set('NCI Thesaurus OBO Edition', 'http://purl.obolibrary.org/obo/ncit/releases/2022-08-19/ncit.owl')
  chmo = json_ld_defined_term_set('Chemical Methods Ontology', 'http://purl.obolibrary.org/obo/chmo/releases/2022-04-19/chmo.owl')

  sample = json_ld_defined_term('sample', nil, 'http://semanticscience.org/resource/SIO_001050', sio, 'SIO:001050')
  reaction = json_ld_defined_term('chemical reaction', nil, 'http://semanticscience.org/resource/SIO_010345', sio, 'SIO:010345')
  analytical_chemistry = json_ld_defined_term('Analytical Chemistry',['Chemistry, Analytical'], 'http://purl.obolibrary.org/obo/NCIT_C16415', ncit, 'NCIT:C16415')

#    nmr = json_ld_defined_term('nuclear magnetic resonance spectroscopy', ['NMR', 'NMR spectroscopy', 'nuclear magnetic resonance (NMR) spectroscopy'], 'http://purl.obolibrary.org/obo/CHMO_0000591', chmo, 'CHMO:0000591')
#    ms = json_ld_defined_term('mass spectrometry', ['MS'], 'http://purl.obolibrary.org/obo/CHMO_0000470', chmo, 'CHMO:0000470')
#    ir = json_ld_defined_term('infrared absorption spectroscopy',['infrared (IR) spectroscopy, IR, infra-red absorption spectroscopy, IR spectroscopy, IR absorption spectroscopy, infrared spectroscopy'], 'http://purl.obolibrary.org/obo/CHMO_0000630', chmo, 'CHMO:0000630')

  arr = [sample, reaction, analytical_chemistry]
  arr
end

#data_catalog_providerObject



121
122
123
124
125
126
127
# File 'lib/repo/metadata_jsonld.rb', line 121

def data_catalog_provider
  {
    "@type": 'Organization',
    "name": 'Karlsruhe Institute of Technology (KIT)',
    "url": 'https://www.kit.edu/'
  }
end

#json_ldObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/repo/metadata_jsonld.rb', line 8

def json_ld
  return {} if state != 'completed'

  if element_type == 'Sample'
    json_ld_sample_root
  elsif element_type == 'Reaction'
    json_ld_reaction
  elsif element_type == 'Container'
    json_ld_container
  end
end

#json_ld_affiliation(aff_id, taggable_data) ⇒ Object



322
323
324
325
326
327
# File 'lib/repo/metadata_jsonld.rb', line 322

def json_ld_affiliation(aff_id, taggable_data)
  json = {}
  json['@type'] = 'Organization'
  json['name'] = taggable_data['affiliations'][aff_id.to_s]
  json
end

#json_ld_analysis(pub = self, root = true) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/repo/metadata_jsonld.rb', line 234

def json_ld_analysis(pub = self, root = true)
  json = {}
  json['@context'] = 'https://schema.org'
  json['@type'] = 'Dataset'
  json['@id'] = "https://doi.org/#{pub.doi.full_doi}"
  json['identifier'] = "CRD-#{pub.id}"
  json['url'] = "https://www.chemotion-repository.net/inchikey/#{pub.doi.suffix}"
  json['publisher'] = json_ld_publisher
  json['license'] = pub.rights_data[:rightsURI]
  json['name'] = pub.element.['kind'] || '' if pub&.element&..present?
  json['creator'] = json_ld_authors(pub.taggable_data)
  json['author'] = json['creator']
  json['description'] = json_ld_analysis_description(pub)
  json['includedInDataCatalog'] = json_ld_data_catalog(pub) if root == true
  json
end

#json_ld_analysis_description(pub) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
# File 'lib/repo/metadata_jsonld.rb', line 251

def json_ld_analysis_description(pub)
  #xml_data = Nokogiri::XML(metadata_xml)
  #desc = xml_data.search('description')&.text&.strip
  #desc
  element = pub.element
  kind = 'dataset for ' + (element.['kind'] || '')&.split('|').pop + '\n'
  desc = element.['description'] || '' + '\n'
  content = REXML::Text.new(Nokogiri::HTML( Chemotion::QuillToHtml.new.convert(element.['content'] || '')).text, false, nil, false).to_s

  kind + desc + content
end

#json_ld_authors(taggable_data) ⇒ Object



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/repo/metadata_jsonld.rb', line 293

def json_ld_authors(taggable_data)
  creators = taggable_data["creators"] || []
  arr = []
  creators.each do |author|
    json = {}
    json['@type'] = 'Person'
    json['name'] = author['name']
    json['identifier'] = author['ORCID'] if author['ORCID'].present?
    json['familyName'] = author["familyName"]
    json['givenName'] = author["givenName"]
    json['affiliation'] = json_ld_affiliation(author['affiliationIds']&.first, taggable_data)
    arr.push(json)
  end
  arr
end

#json_ld_citation(lit, id) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/repo/metadata_jsonld.rb', line 272

def json_ld_citation(lit, id)
  json = {}
  json['@type'] = 'CreativeWork'
  bib = lit[:refs] && lit[:refs]['bibtex']
  bb = DataCite::LiteraturePaser.parse_bibtex!(bib, id)
  bb = DataCite::LiteraturePaser.(bb, lit[:doi], id) unless bb.class == BibTeX::Entry
  dc_lit = DataCite::LiteraturePaser.report_hash(lit, bb) if bb.class == BibTeX::Entry
  json['name'] = dc_lit[:title] unless dc_lit.blank?
  json['author'] = dc_lit[:author] unless dc_lit.blank?
  json['url'] = dc_lit[:url] unless dc_lit.blank?
  json
end

#json_ld_citations(literatures, id) ⇒ Object



264
265
266
267
268
269
270
# File 'lib/repo/metadata_jsonld.rb', line 264

def json_ld_citations(literatures, id)
  json = []
  literatures.each do |lit|
    json.push(json_ld_citation(lit, id))
  end
  json
end

#json_ld_containerObject



220
221
222
# File 'lib/repo/metadata_jsonld.rb', line 220

def json_ld_container
  json_ld_analysis(self, true)
end

#json_ld_contributor(contributor) ⇒ Object



309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/repo/metadata_jsonld.rb', line 309

def json_ld_contributor(contributor)
  return {} unless contributor.present?

  json = {}
  json['@type'] = 'Person'
  json['name'] = contributor['name']
  json['identifier'] = contributor['ORCID'] if contributor['ORCID'].present?
  json['familyName'] = contributor["familyName"]
  json['givenName'] = contributor["givenName"]
  # json['affiliation'] = json_ld_affiliation(author['affiliationIds']&.first)
  json
end

#json_ld_data_catalog(pub = self) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/repo/metadata_jsonld.rb', line 45

def json_ld_data_catalog(pub = self)
  json = {}
  json['@context'] = 'https://schema.org'
  json['@type'] = 'DataCatalog'
  json['@id'] = 'https://www.chemotion-repository.net'
  json['description'] = 'Repository for samples, reactions and related research data.'
  json['keywords'] = data_catalog_keywords(pub)
  json['name'] = 'Chemotion Repository'
  json['provider'] = data_catalog_provider
  json['url'] = 'https://www.chemotion-repository.net'
  json['license'] = 'https://www.gnu.org/licenses/agpl-3.0.en.html'
  json['contributor'] = data_catalog_contributors
  json['isAccessibleForFree'] = true
  # json['measurementTechnique'] = ['https://ontobee.org/ontology/CHMO?iri=http://purl.obolibrary.org/obo/CHMO_0000591', 'https://ontobee.org/ontology/CHMO?iri=http://purl.obolibrary.org/obo/CHMO_0000470', 'http://purl.obolibrary.org/obo/CHMO_0000630', 'https://ontobee.org/ontology/CHMO?iri=http://purl.obolibrary.org/obo/OBI_0000011']
  json
end

#json_ld_defined_term(name, alternate_name, url, defined_term_set, id) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/repo/metadata_jsonld.rb', line 70

def json_ld_defined_term(name, alternate_name, url, defined_term_set, id)
  json = {}
  json['@type'] = 'DefinedTerm'
  json['name'] = name
  json['alternateName'] = alternate_name
  json['url'] = url
  json['inDefinedTermSet'] = defined_term_set
  json['@id'] = id
  json
end

#json_ld_defined_term_set(name, url) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/repo/metadata_jsonld.rb', line 62

def json_ld_defined_term_set(name,url)
  json = {}
  json['@type'] = 'DefinedTermSet'
  json['name'] = name
  json['url'] = url
  json
end

#json_ld_description(desc) ⇒ Object



212
213
214
215
216
217
218
# File 'lib/repo/metadata_jsonld.rb', line 212

def json_ld_description(desc)
  REXML::Text.new(Nokogiri::HTML( Chemotion::QuillToHtml.new.convert(desc.to_json)).text, false, nil, false).to_s
  #persit_datacite_metadata_xml! unless metadata_xml.present?
  #xml_data = Nokogiri::XML(metadata_xml)
  #desc = xml_data.search('description')&.text&.strip
  #desc
end

#json_ld_embargoObject



184
185
186
187
188
189
190
# File 'lib/repo/metadata_jsonld.rb', line 184

def json_ld_embargo
  json = {}
  json['@context'] = 'https://schema.org'
  json['@type'] = 'Study'
  # json['startDate'] = embargo_start_date&.strftime('%Y-%m-%d')
  json
end

#json_ld_lab_protocolObject



192
193
194
195
196
197
198
# File 'lib/repo/metadata_jsonld.rb', line 192

def json_ld_lab_protocol
  json = {}
  json['@context'] = 'https://schema.org'
  json['@type'] = 'LabProtocol'
  json['@id'] = "https://doi.org/#{doi.full_doi}"
  json
end

#json_ld_moelcule_entity(pub = self) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/repo/metadata_jsonld.rb', line 337

def json_ld_moelcule_entity(pub = self)
  mol = pub.element.molecule
  json = {}
  json['@type'] = 'MolecularEntity'
  json['smiles'] = mol.cano_smiles
  json['inChIKey'] = mol.inchikey
  json['inChI'] = mol.inchistring
  json['name'] = pub.element.molecule_name&.name
  json['molecularFormula'] = mol.sum_formular
  json['molecularWeight'] = json_ld_molecular_weight(mol)
  json['iupacName'] = mol.iupac_name
  json
end

#json_ld_molecular_weight(mol) ⇒ Object



329
330
331
332
333
334
335
# File 'lib/repo/metadata_jsonld.rb', line 329

def json_ld_molecular_weight(mol)
  json ={}
  json['@type'] = 'QuantitativeValue'
  json['value'] = mol.molecular_weight
  json['unitCode'] = 'g/mol'
  json
end

#json_ld_person(id, given_name, family_name) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/repo/metadata_jsonld.rb', line 81

def json_ld_person(id, given_name, family_name)
  json = {}
  json['@type'] = 'Person'
  json['givenName'] = given_name
  json['familyName'] = family_name
  json['@id'] = id
  json
end

#json_ld_publisherObject



285
286
287
288
289
290
# File 'lib/repo/metadata_jsonld.rb', line 285

def json_ld_publisher
  json = {}
  json['@type'] = 'Organization'
  json['name'] = 'chemotion-repository'
  json
end

#json_ld_reactionObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/repo/metadata_jsonld.rb', line 160

def json_ld_reaction
  json = {}
  json['@context'] = 'https://schema.org'
  json['@type'] = 'Study'
  json['@id'] = "https://doi.org/#{doi.full_doi}"
  json['identifier'] = "CRR-#{id}"
  json['url'] = "https://www.chemotion-repository.net/inchikey/#{doi.suffix}"
  json['additionalType'] = 'Reaction'
  json['name'] = element.rinchi_short_key
  json['creator'] = json_ld_authors(taggable_data)
  json['author'] = json['creator']

  json['description'] = json_ld_description(element.description)
  json['license'] = rights_data[:rightsURI]
  json['datePublished'] = published_at&.strftime('%Y-%m-%d')
  json['dateCreated'] = created_at&.strftime('%Y-%m-%d')
  json['publisher'] = json_ld_publisher
  json['provider'] = json_ld_publisher
  json['keywords'] = 'chemical reaction: structures conditions'
  json['citation'] = json_ld_citations(element.literatures, element.id)
  json['subjectOf'] = json_ld_reaction_has_part
  json
end

#json_ld_reaction_has_partObject



200
201
202
203
204
205
206
207
# File 'lib/repo/metadata_jsonld.rb', line 200

def json_ld_reaction_has_part
  json = []
  children&.each do |pub|
    json.push(json_ld_sample(pub)) if pub.element_type == 'Sample'
    json.push(json_ld_analysis(pub, false)) if pub.element_type == 'Container'
  end
  json
end

#json_ld_reaction_has_part_productObject



209
210
# File 'lib/repo/metadata_jsonld.rb', line 209

def json_ld_reaction_has_part_product
end

#json_ld_sample(pub = self) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/repo/metadata_jsonld.rb', line 136

def json_ld_sample(pub = self)
  # metadata_xml
  json = {}
  json['@context'] = 'https://schema.org'
  json['@type'] = 'ChemicalSubstance'
  json['@id'] = "https://doi.org/#{pub.doi.full_doi}"
  json['identifier'] = "CRS-#{pub.id}"
  json['url'] = "https://www.chemotion-repository.net/inchikey/#{pub.doi.suffix}"
  json['name'] = pub.element.molecule_name&.name
  json['alternateName'] = pub.element.molecule.inchistring
  # json['image'] = element.sample_svg_file
  json['image'] = 'https://www.chemotion-repository.net/images/samples/' + pub.element.sample_svg_file  if pub&.element&.sample_svg_file.present?
  json['description'] = json_ld_description(pub.element.description)
  #json['author'] = json_ld_authors(pub.taggable_data)
  json['hasBioChemEntityPart'] = json_ld_moelcule_entity(pub)
  json['subjectOf'] = json_ld_subjectOf(pub)
  #json_object = JSON.parse(json)
  #JSON.pretty_generate(json_object)
  json
  # formatted_json = JSON.pretty_generate(json)
  # formatted_json
end

#json_ld_sample_root(pub = self) ⇒ Object



20
21
22
23
24
# File 'lib/repo/metadata_jsonld.rb', line 20

def json_ld_sample_root(pub = self)
  json = json_ld_study
  json['about'] = [json_ld_sample]
  json
end

#json_ld_study(pub = self) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/repo/metadata_jsonld.rb', line 26

def json_ld_study(pub = self)
  json = {}
  json['@context'] = 'https://schema.org'
  json['@type'] = 'Study'
  json['@id'] = "https://doi.org/#{doi.full_doi}"
  json['dct:conformsTo'] = {
    "@id": 'https://bioschemas.org/profiles/Study/0.3-DRAFT',
    "@type": 'CreativeWork'
  }
  json['publisher'] = json_ld_publisher
  json['dateCreated'] = pub.published_at&.strftime('%Y-%m-%d')
  json['datePublished'] = pub.published_at&.strftime('%Y-%m-%d')
  json['author'] = json_ld_authors(pub.taggable_data)
  json['contributor'] = json_ld_contributor(pub.taggable_data["contributors"])
  json['citation'] = json_ld_citations(pub.element.literatures, pub.element.id)
  json['includedInDataCatalog'] = json_ld_data_catalog(pub)
  json
end

#json_ld_subjectOf(pub = self) ⇒ Object



225
226
227
228
229
230
231
232
# File 'lib/repo/metadata_jsonld.rb', line 225

def json_ld_subjectOf(pub = self)
  arr = []
  # arr.push(json_ld_creative_work(pub))
  pub.children&.each do |ana|
    arr.push(json_ld_analysis(ana, false))
  end
  arr
end