This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsemantic_types.rb
91 lines (81 loc) · 3 KB
/
semantic_types.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#############################################################
# !!!! This script gets required at the end of ontolgies.rb #
#############################################################
require_relative 'settings'
require_relative 'helpers/rest_helper'
require_relative 'helpers/ontology_helper'
LDModels =LinkedData::Models
sty_acr = "STY"
submissionId = 1
ontologyFile = "./data/umls_semantictypes.ttl"
sty = LDModels::Ontology.find(sty_acr).include(LDModels::Ontology.attributes).first
sty.bring(:submissions) if sty
if sty && sty.submissions.length > 0
puts "Semantic Types already in the system - skipping parsing"
ont_sub = sty.latest_submission
classes = LinkedData::Models::Class.in(ont_sub).include(:prefLabel)
.read_only.to_a
puts "Backend STY contains #{classes.length} classes"
if classes.length < 100
raise ArgumentError,
"Something might be wrong STY Ontology - " +
"only #{classes.length} classes"
end
else
umls = LDModels::OntologyFormat.find("UMLS").first
if umls.nil?
raise ArgumentError,
"UMLS format not found - unable to parse STY ont."
end
user = LDModels::User.find("msalvadores").first
if user.nil?
raise ArgumentError,
"User for STY not found - unable to parse STY ont."
end
ont = sty
if ont.nil?
ont = LDModels::Ontology.new(
acronym: sty_acr,
name: "Semantic Types Ontology", administeredBy: [user]).save
end
contact = LDModels::Contact.where(name: "bioportal",
email: "[email protected]")
.first
if contact.nil?
contact = LDModels::Contact.new(
name: "bioportal",
email: "[email protected]")
contact.save
end
ont_submision = LDModels::OntologySubmission.new(
submissionId: submissionId)
ont_submision.contact = [contact]
ont_submision.hasOntologyLanguage = umls
ont_submision.ontology = ont
ont_submision.submissionStatus =
[LDModels::SubmissionStatus.where(:code => "UPLOADED").first]
uploadFilePath = LDModels::OntologySubmission.copy_file_repository(
sty_acr,
submissionId,
ontologyFile)
ont_submision.uploadFilePath = uploadFilePath
ont_submision.released = DateTime.now
ont_submision.save
FileUtils.mkdir_p("./logs")
log_file = File.open("./logs/parsing_#{sty_acr}.log", "w")
logger = Logger.new(log_file)
logger.level = Logger::DEBUG
ont_submision.process_submission(logger,
process_rdf: true, index_search: true,
run_metrics: true, reasoning: true)
classes = LinkedData::Models::Class.in(ont_submision)
.include(:prefLabel)
.read_only.to_a
puts "STY parsed with #{classes.length} classes"
log_file.close()
if classes.length < 100
raise ArgumentError,
"Something might be wrong with STY Ontology - " +
"only #{classes.length} classes"
end
end #if sty