openphar 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/README.adoc +221 -0
  3. data/lib/openphar/cli/main.rb +137 -0
  4. data/lib/openphar/cli.rb +11 -0
  5. data/lib/openphar/core/slug_generator.rb +107 -0
  6. data/lib/openphar/core.rb +11 -0
  7. data/lib/openphar/errors/configuration_error.rb +8 -0
  8. data/lib/openphar/errors/monograph_not_found_error.rb +15 -0
  9. data/lib/openphar/errors/parse_error.rb +18 -0
  10. data/lib/openphar/errors/unknown_format_error.rb +8 -0
  11. data/lib/openphar/errors/unknown_publisher_error.rb +8 -0
  12. data/lib/openphar/errors/unknown_type_error.rb +8 -0
  13. data/lib/openphar/errors/validation_error.rb +15 -0
  14. data/lib/openphar/errors.rb +17 -0
  15. data/lib/openphar/exporters/coverage_validator.rb +265 -0
  16. data/lib/openphar/exporters/neo4j/model_registry.rb +130 -0
  17. data/lib/openphar/exporters/neo4j/node_builder.rb +84 -0
  18. data/lib/openphar/exporters/neo4j/property_mapper.rb +154 -0
  19. data/lib/openphar/exporters/neo4j/relationship_builder.rb +87 -0
  20. data/lib/openphar/exporters/neo4j.rb +16 -0
  21. data/lib/openphar/exporters/neo4j_exporter.rb +199 -0
  22. data/lib/openphar/exporters.rb +15 -0
  23. data/lib/openphar/linkers/chp/cross_edition_linker.rb +101 -0
  24. data/lib/openphar/linkers/chp.rb +11 -0
  25. data/lib/openphar/linkers/cross_publisher_linker.rb +295 -0
  26. data/lib/openphar/linkers/herbapedia_linker.rb +125 -0
  27. data/lib/openphar/linkers.rb +13 -0
  28. data/lib/openphar/migrators/chp/classifier.rb +86 -0
  29. data/lib/openphar/migrators/chp.rb +15 -0
  30. data/lib/openphar/migrators/chp_migrator.rb +130 -0
  31. data/lib/openphar/migrators/jp_migrator.rb +345 -0
  32. data/lib/openphar/migrators/phint_migrator.rb +426 -0
  33. data/lib/openphar/migrators.rb +15 -0
  34. data/lib/openphar/models/ahp.rb +25 -0
  35. data/lib/openphar/models/amino_acid_monograph.rb +28 -0
  36. data/lib/openphar/models/api.rb +29 -0
  37. data/lib/openphar/models/assay_specification.rb +19 -0
  38. data/lib/openphar/models/base_entity.rb +221 -0
  39. data/lib/openphar/models/biological_substance_monograph.rb +31 -0
  40. data/lib/openphar/models/chemical_drug_monograph.rb +39 -0
  41. data/lib/openphar/models/chp/biologic.rb +28 -0
  42. data/lib/openphar/models/chp/chemical_preparation.rb +28 -0
  43. data/lib/openphar/models/chp/chemical_substance.rb +28 -0
  44. data/lib/openphar/models/chp/general_chapter.rb +30 -0
  45. data/lib/openphar/models/chp/monograph.rb +116 -0
  46. data/lib/openphar/models/chp/section.rb +37 -0
  47. data/lib/openphar/models/chp/tcm_crude_drug.rb +28 -0
  48. data/lib/openphar/models/chp/tcm_extract.rb +29 -0
  49. data/lib/openphar/models/chp/tcm_formulation.rb +28 -0
  50. data/lib/openphar/models/chp.rb +33 -0
  51. data/lib/openphar/models/crude_drug_monograph.rb +31 -0
  52. data/lib/openphar/models/edition.rb +41 -0
  53. data/lib/openphar/models/formulation_monograph.rb +31 -0
  54. data/lib/openphar/models/hkcmms.rb +26 -0
  55. data/lib/openphar/models/identification_specification.rb +19 -0
  56. data/lib/openphar/models/jp/kampo_formula.rb +94 -0
  57. data/lib/openphar/models/jp.rb +21 -0
  58. data/lib/openphar/models/limit.rb +54 -0
  59. data/lib/openphar/models/mineral_substance_monograph.rb +28 -0
  60. data/lib/openphar/models/monograph.rb +58 -0
  61. data/lib/openphar/models/ph_int/buffer_solution.rb +38 -0
  62. data/lib/openphar/models/ph_int/dosage_form_monograph.rb +43 -0
  63. data/lib/openphar/models/ph_int/radiopharmaceutical_monograph.rb +52 -0
  64. data/lib/openphar/models/ph_int/reagent.rb +50 -0
  65. data/lib/openphar/models/ph_int/reference_substance.rb +50 -0
  66. data/lib/openphar/models/ph_int/test_method.rb +50 -0
  67. data/lib/openphar/models/ph_int/test_solution.rb +39 -0
  68. data/lib/openphar/models/ph_int/volumetric_solution.rb +38 -0
  69. data/lib/openphar/models/ph_int.rb +37 -0
  70. data/lib/openphar/models/physical_specification.rb +17 -0
  71. data/lib/openphar/models/publisher.rb +98 -0
  72. data/lib/openphar/models/purity_specification.rb +16 -0
  73. data/lib/openphar/models/supplement.rb +31 -0
  74. data/lib/openphar/models/test_specification.rb +29 -0
  75. data/lib/openphar/models/thp.rb +24 -0
  76. data/lib/openphar/models/vitamin_monograph.rb +28 -0
  77. data/lib/openphar/models.rb +58 -0
  78. data/lib/openphar/monograph_merger.rb +374 -0
  79. data/lib/openphar/parsers/base_monograph_parser.rb +108 -0
  80. data/lib/openphar/parsers/jp_html_parser.rb +92 -0
  81. data/lib/openphar/parsers/jp_html_parser_base.rb +113 -0
  82. data/lib/openphar/parsers/jp_ja_html_parser.rb +220 -0
  83. data/lib/openphar/parsers/phint_json_parser.rb +332 -0
  84. data/lib/openphar/parsers.rb +21 -0
  85. data/lib/openphar/registry/publisher_registry.rb +46 -0
  86. data/lib/openphar/registry/type_registry.rb +147 -0
  87. data/lib/openphar/registry.rb +24 -0
  88. data/lib/openphar/repositories/monograph_repository.rb +350 -0
  89. data/lib/openphar/repositories.rb +11 -0
  90. data/lib/openphar/transformers/jsonld_transformer.rb +106 -0
  91. data/lib/openphar/transformers.rb +11 -0
  92. data/lib/openphar/version.rb +5 -0
  93. data/lib/openphar.rb +119 -0
  94. data/ontology/bibliographic/edition.ttl +267 -0
  95. data/ontology/context/chp.jsonld +69 -0
  96. data/ontology/context/crude-drugs.jsonld +56 -0
  97. data/ontology/context/pharmacopoeia.jsonld +631 -0
  98. data/ontology/core/identification.ttl +456 -0
  99. data/ontology/core/pharmacopoeia.ttl +3427 -0
  100. data/ontology/core/substance-form.ttl +302 -0
  101. data/ontology/core/unit.ttl +493 -0
  102. data/ontology/publisher/chp/extensions.ttl +186 -0
  103. data/ontology/publisher/phint/extensions.ttl +327 -0
  104. data/ontology/quality/test-method.ttl +610 -0
  105. data/shapes/chp/monograph.ttl +153 -0
  106. data/shapes/edition-shapes.ttl +230 -0
  107. data/shapes/monograph-shapes.ttl +1324 -0
  108. metadata +319 -0
@@ -0,0 +1,153 @@
1
+ # Open Pharmacopoeia - SHACL shapes for Chinese Pharmacopoeia monographs.
2
+ #
3
+ # These shapes document the structural contract every ChP monograph must
4
+ # satisfy. They can also be used by a SHACL processor to validate JSON-LD
5
+ # output produced by ChP::JsonLD::Exporter.
6
+ #
7
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
8
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
9
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
10
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
11
+ @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
12
+ @prefix op: <https://www.openphar.org/ontology/core/> .
13
+ @prefix chp: <https://www.openphar.org/ontology/publisher/chp/> .
14
+
15
+ # =============================================================================
16
+ # BASE SHAPE — applies to every ChP monograph regardless of type
17
+ # =============================================================================
18
+
19
+ chp:MonographShape
20
+ a sh:NodeShape ;
21
+ sh:targetClass chp:Monograph ;
22
+ sh:property [
23
+ sh:path chp:entryId ;
24
+ sh:datatype xsd:integer ;
25
+ sh:minCount 1 ;
26
+ sh:maxCount 1 ;
27
+ sh:severity sh:Violation ;
28
+ sh:message "ChP monograph must have exactly one chp:entryId."@en ;
29
+ ] ;
30
+ sh:property [
31
+ sh:path chp:bookId ;
32
+ sh:datatype xsd:integer ;
33
+ sh:minCount 1 ;
34
+ sh:maxCount 1 ;
35
+ sh:severity sh:Violation ;
36
+ sh:message "ChP monograph must have exactly one chp:bookId in 1..4."@en ;
37
+ ] ;
38
+ sh:property [
39
+ sh:path chp:bookId ;
40
+ sh:in ( 1 2 3 4 ) ;
41
+ sh:severity sh:Violation ;
42
+ ] ;
43
+ sh:property [
44
+ sh:path dct:title ;
45
+ sh:datatype xsd:string ;
46
+ sh:minCount 1 ;
47
+ sh:maxCount 1 ;
48
+ sh:severity sh:Violation ;
49
+ sh:message "ChP monograph must have a title."@en ;
50
+ ] ;
51
+ sh:property [
52
+ sh:path op:publisher ;
53
+ sh:hasValue "ChP" ;
54
+ sh:severity sh:Violation ;
55
+ ] ;
56
+ sh:property [
57
+ sh:path op:belongsToEdition ;
58
+ sh:nodeKind sh:IRI ;
59
+ sh:minCount 1 ;
60
+ sh:severity sh:Violation ;
61
+ ] ;
62
+ sh:property [
63
+ sh:path chp:directoryTitle ;
64
+ sh:datatype xsd:string ;
65
+ sh:maxCount 1 ;
66
+ sh:severity sh:Warning ;
67
+ ] ;
68
+ sh:property [
69
+ sh:path chp:pinyinTitle ;
70
+ sh:datatype xsd:string ;
71
+ sh:maxCount 1 ;
72
+ sh:severity sh:Warning ;
73
+ ] ;
74
+ sh:property [
75
+ sh:path chp:htmlContent ;
76
+ sh:datatype xsd:string ;
77
+ sh:severity sh:Info ;
78
+ ] .
79
+
80
+ # =============================================================================
81
+ # TYPE-SPECIFIC SHAPES
82
+ # =============================================================================
83
+
84
+ chp:TcmCrudeDrugShape
85
+ a sh:NodeShape ;
86
+ sh:targetClass chp:TcmCrudeDrug ;
87
+ sh:property [
88
+ sh:path chp:bookId ;
89
+ sh:hasValue 1 ;
90
+ sh:severity sh:Violation ;
91
+ sh:message "TcmCrudeDrug must be in Vol I (bookId=1)."@en ;
92
+ ] ;
93
+ sh:property [
94
+ sh:path chp:eTitle ;
95
+ sh:datatype xsd:string ;
96
+ sh:minCount 1 ;
97
+ sh:severity sh:Warning ;
98
+ sh:message "TCM crude drugs should carry a Latin botanical/zoological name."@en ;
99
+ ] .
100
+
101
+ chp:TcmExtractShape
102
+ a sh:NodeShape ;
103
+ sh:targetClass chp:TcmExtract ;
104
+ sh:property [
105
+ sh:path chp:bookId ;
106
+ sh:hasValue 1 ;
107
+ sh:severity sh:Violation ;
108
+ ] .
109
+
110
+ chp:TcmFormulationShape
111
+ a sh:NodeShape ;
112
+ sh:targetClass chp:TcmFormulation ;
113
+ sh:property [
114
+ sh:path chp:bookId ;
115
+ sh:hasValue 1 ;
116
+ sh:severity sh:Violation ;
117
+ ] .
118
+
119
+ chp:ChemicalSubstanceShape
120
+ a sh:NodeShape ;
121
+ sh:targetClass chp:ChemicalSubstance ;
122
+ sh:property [
123
+ sh:path chp:bookId ;
124
+ sh:hasValue 2 ;
125
+ sh:severity sh:Violation ;
126
+ ] .
127
+
128
+ chp:ChemicalPreparationShape
129
+ a sh:NodeShape ;
130
+ sh:targetClass chp:ChemicalPreparation ;
131
+ sh:property [
132
+ sh:path chp:bookId ;
133
+ sh:hasValue 2 ;
134
+ sh:severity sh:Violation ;
135
+ ] .
136
+
137
+ chp:BiologicShape
138
+ a sh:NodeShape ;
139
+ sh:targetClass chp:Biologic ;
140
+ sh:property [
141
+ sh:path chp:bookId ;
142
+ sh:hasValue 3 ;
143
+ sh:severity sh:Violation ;
144
+ ] .
145
+
146
+ chp:GeneralChapterShape
147
+ a sh:NodeShape ;
148
+ sh:targetClass chp:GeneralChapter ;
149
+ sh:property [
150
+ sh:path chp:bookId ;
151
+ sh:hasValue 4 ;
152
+ sh:severity sh:Violation ;
153
+ ] .
@@ -0,0 +1,230 @@
1
+ # Open Pharmacopoeia - SHACL Shapes for Edition Validation
2
+ #
3
+ # This file defines SHACL shapes for validating pharmacopoeia edition data.
4
+ # Ensures that all required properties are present and have correct types.
5
+
6
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
7
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
8
+ @prefix owl: <http://www.w3.org/2002/07/owl#> .
9
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
10
+ @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
11
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
12
+ @prefix op: <https://www.openphar.org/ontology/core/> .
13
+ @prefix bib: <https://www.openphar.org/ontology/bibliographic/> .
14
+ @prefix shape: <https://www.openphar.org/shapes/> .
15
+
16
+ <https://www.openphar.org/shapes/edition-shapes>
17
+ a owl:Ontology ;
18
+ rdfs:label "Open Pharmacopoeia Edition Shapes"@en ;
19
+ rdfs:comment "SHACL shapes for validating pharmacopoeia editions and supplements."@en ;
20
+ owl:imports <https://www.openphar.org/ontology/bibliographic/edition> ;
21
+ sh:declare [
22
+ sh:prefix "bib" ;
23
+ sh:namespace "https://www.openphar.org/ontology/bibliographic/"^^xsd:anyURI
24
+ ] , [
25
+ sh:prefix "op" ;
26
+ sh:namespace "https://www.openphar.org/ontology/core/"^^xsd:anyURI
27
+ ] .
28
+
29
+ # =============================================================================
30
+ # EDITION SHAPE
31
+ # =============================================================================
32
+
33
+ shape:EditionShape
34
+ a sh:NodeShape ;
35
+ sh:targetClass bib:Edition ;
36
+
37
+ # Required properties
38
+ sh:property [
39
+ sh:path bib:editionNumber ;
40
+ sh:datatype xsd:string ;
41
+ sh:minCount 1 ;
42
+ sh:maxCount 1 ;
43
+ sh:message "An edition must have exactly one edition number."@en
44
+ ] ;
45
+
46
+ sh:property [
47
+ sh:path bib:hasPublisher ;
48
+ sh:class op:Publisher ;
49
+ sh:minCount 1 ;
50
+ sh:maxCount 1 ;
51
+ sh:message "An edition must have exactly one publisher."@en
52
+ ] ;
53
+
54
+ sh:property [
55
+ sh:path skos:prefLabel ;
56
+ sh:datatype rdf:langString ;
57
+ sh:minCount 1 ;
58
+ sh:message "An edition must have at least one preferred label."@en
59
+ ] ;
60
+
61
+ # Optional but recommended properties
62
+ sh:property [
63
+ sh:path bib:publicationDate ;
64
+ sh:datatype xsd:date ;
65
+ sh:maxCount 1 ;
66
+ sh:severity sh:Warning ;
67
+ sh:message "An edition should have a publication date."@en
68
+ ] ;
69
+
70
+ sh:property [
71
+ sh:path bib:effectiveDate ;
72
+ sh:datatype xsd:date ;
73
+ sh:maxCount 1 ;
74
+ sh:severity sh:Warning ;
75
+ sh:message "An edition should have an effective date."@en
76
+ ] ;
77
+
78
+ sh:property [
79
+ sh:path bib:editionUrl ;
80
+ sh:datatype xsd:anyURI ;
81
+ sh:maxCount 1 ;
82
+ sh:severity sh:Info ;
83
+ sh:message "An edition may have an official URL."@en
84
+ ] ;
85
+
86
+ sh:property [
87
+ sh:path bib:monographCount ;
88
+ sh:datatype xsd:integer ;
89
+ sh:maxCount 1 ;
90
+ sh:severity sh:Info ;
91
+ sh:message "An edition may have a monograph count."@en
92
+ ] ;
93
+
94
+ # Supplements
95
+ sh:property [
96
+ sh:path bib:hasSupplement ;
97
+ sh:class bib:Supplement ;
98
+ sh:node shape:SupplementShape ;
99
+ sh:severity sh:Info ;
100
+ sh:message "An edition may have supplements."@en
101
+ ] .
102
+
103
+ # =============================================================================
104
+ # SUPPLEMENT SHAPE
105
+ # =============================================================================
106
+
107
+ shape:SupplementShape
108
+ a sh:NodeShape ;
109
+ sh:targetClass bib:Supplement ;
110
+
111
+ # Required properties
112
+ sh:property [
113
+ sh:path bib:supplementNumber ;
114
+ sh:datatype xsd:string ;
115
+ sh:minCount 1 ;
116
+ sh:maxCount 1 ;
117
+ sh:message "A supplement must have exactly one supplement number."@en
118
+ ] ;
119
+
120
+ sh:property [
121
+ sh:path bib:supplementTo ;
122
+ sh:class bib:Edition ;
123
+ sh:minCount 1 ;
124
+ sh:maxCount 1 ;
125
+ sh:message "A supplement must belong to exactly one edition."@en
126
+ ] ;
127
+
128
+ # Optional but recommended properties
129
+ sh:property [
130
+ sh:path bib:supplementPublicationDate ;
131
+ sh:datatype xsd:date ;
132
+ sh:maxCount 1 ;
133
+ sh:severity sh:Warning ;
134
+ sh:message "A supplement should have a publication date."@en
135
+ ] ;
136
+
137
+ sh:property [
138
+ sh:path bib:supplementEffectiveDate ;
139
+ sh:datatype xsd:date ;
140
+ sh:maxCount 1 ;
141
+ sh:severity sh:Warning ;
142
+ sh:message "A supplement should have an effective date."@en
143
+ ] ;
144
+
145
+ # Monograph changes
146
+ sh:property [
147
+ sh:path bib:addsMonograph ;
148
+ sh:class op:PharmacopoeiaMonograph ;
149
+ sh:severity sh:Info ;
150
+ sh:message "A supplement may add monographs."@en
151
+ ] ;
152
+
153
+ sh:property [
154
+ sh:path bib:revisesMonograph ;
155
+ sh:class op:PharmacopoeiaMonograph ;
156
+ sh:severity sh:Info ;
157
+ sh:message "A supplement may revise monographs."@en
158
+ ] ;
159
+
160
+ sh:property [
161
+ sh:path bib:deletesMonograph ;
162
+ sh:class op:PharmacopoeiaMonograph ;
163
+ sh:severity sh:Info ;
164
+ sh:message "A supplement may delete monographs."@en
165
+ ] .
166
+
167
+ # =============================================================================
168
+ # VERSION HISTORY SHAPE
169
+ # =============================================================================
170
+
171
+ shape:VersionHistoryShape
172
+ a sh:NodeShape ;
173
+ sh:targetClass bib:VersionHistory ;
174
+
175
+ sh:property [
176
+ sh:path bib:versionFor ;
177
+ sh:class op:PharmacopoeiaMonograph ;
178
+ sh:minCount 1 ;
179
+ sh:maxCount 1 ;
180
+ sh:message "A version history must be for exactly one monograph."@en
181
+ ] ;
182
+
183
+ sh:property [
184
+ sh:path bib:hasVersion ;
185
+ sh:class bib:MonographVersion ;
186
+ sh:minCount 1 ;
187
+ sh:node shape:MonographVersionShape ;
188
+ sh:message "A version history must have at least one version entry."@en
189
+ ] .
190
+
191
+ # =============================================================================
192
+ # MONOGRAPH VERSION SHAPE
193
+ # =============================================================================
194
+
195
+ shape:MonographVersionShape
196
+ a sh:NodeShape ;
197
+ sh:targetClass bib:MonographVersion ;
198
+
199
+ sh:property [
200
+ sh:path bib:inEdition ;
201
+ sh:class bib:Edition ;
202
+ sh:minCount 1 ;
203
+ sh:maxCount 1 ;
204
+ sh:message "A monograph version must be in exactly one edition or supplement."@en
205
+ ] ;
206
+
207
+ sh:property [
208
+ sh:path bib:changeType ;
209
+ sh:class bib:ChangeType ;
210
+ sh:minCount 1 ;
211
+ sh:maxCount 1 ;
212
+ sh:message "A monograph version must have exactly one change type."@en
213
+ ] .
214
+
215
+ # =============================================================================
216
+ # MONOGRAPH WITH EDITION LINKING SHAPE
217
+ # =============================================================================
218
+
219
+ shape:MonographWithEditionShape
220
+ a sh:NodeShape ;
221
+ sh:targetClass op:PharmacopoeiaMonograph ;
222
+
223
+ sh:property [
224
+ sh:path op:belongsToEdition ;
225
+ sh:class bib:Edition ;
226
+ sh:minCount 1 ;
227
+ sh:maxCount 1 ;
228
+ sh:severity sh:Warning ;
229
+ sh:message "A monograph should belong to an edition."@en
230
+ ] .