expressir 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/macos.yml +38 -0
- data/.github/workflows/ubuntu.yml +56 -0
- data/.github/workflows/windows.yml +40 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +508 -0
- data/Gemfile +4 -0
- data/README.adoc +147 -0
- data/Rakefile +6 -0
- data/bin/console +12 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/docs/development.md +90 -0
- data/exe/expressir +20 -0
- data/expressir.gemspec +35 -0
- data/lib/expressir.rb +21 -0
- data/lib/expressir/cli.rb +27 -0
- data/lib/expressir/cli/ui.rb +36 -0
- data/lib/expressir/config.rb +23 -0
- data/lib/expressir/express.rb +12 -0
- data/lib/expressir/express/aggregate_dimension.rb +38 -0
- data/lib/expressir/express/attribute.rb +15 -0
- data/lib/expressir/express/comment.rb +7 -0
- data/lib/expressir/express/defined_type.rb +36 -0
- data/lib/expressir/express/derived.rb +65 -0
- data/lib/expressir/express/derived_aggregate.rb +43 -0
- data/lib/expressir/express/entity.rb +137 -0
- data/lib/expressir/express/explicit.rb +70 -0
- data/lib/expressir/express/explicit_aggregate.rb +46 -0
- data/lib/expressir/express/explicit_or_derived.rb +16 -0
- data/lib/expressir/express/global_rule.rb +44 -0
- data/lib/expressir/express/interface_specification.rb +51 -0
- data/lib/expressir/express/interfaced_item.rb +38 -0
- data/lib/expressir/express/inverse.rb +46 -0
- data/lib/expressir/express/inverse_aggregate.rb +37 -0
- data/lib/expressir/express/model_element.rb +7 -0
- data/lib/expressir/express/named_type.rb +19 -0
- data/lib/expressir/express/remark.rb +8 -0
- data/lib/expressir/express/repository.rb +306 -0
- data/lib/expressir/express/schema_definition.rb +96 -0
- data/lib/expressir/express/subtype_constraint.rb +14 -0
- data/lib/expressir/express/type.rb +26 -0
- data/lib/expressir/express/type_aggregate.rb +42 -0
- data/lib/expressir/express/type_enum.rb +29 -0
- data/lib/expressir/express/type_parser.rb +45 -0
- data/lib/expressir/express/type_select.rb +82 -0
- data/lib/expressir/express/unique_rule.rb +35 -0
- data/lib/expressir/express/where_rule.rb +32 -0
- data/lib/expressir/express_parser.rb +30 -0
- data/lib/expressir/parser.rb +6 -0
- data/lib/expressir/parser/owl_parser.rb +8 -0
- data/lib/expressir/version.rb +3 -0
- data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +9589 -0
- data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +36619 -0
- data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +13294 -0
- data/original/examples/employment/eclipse/.project +17 -0
- data/original/examples/employment/eclipse/Export/Employment.png +0 -0
- data/original/examples/employment/eclipse/Express/employment_schema.exp +33 -0
- data/original/examples/employment/eclipse/Express/employment_schema.xmi +77 -0
- data/original/examples/employment/eclipse/Express/employment_schema.xml +93 -0
- data/original/examples/employment/eclipse/Models/Employment.uml +4 -0
- data/original/examples/employment/eclipse/Models/Employment.umldi +240 -0
- data/original/examples/employment/eclipse/readme.txt +7 -0
- data/original/examples/employment/employment_schema.exp +33 -0
- data/original/examples/employment/employment_schema.rb +232 -0
- data/original/examples/employment/employment_schema.xml +93 -0
- data/original/examples/employment/employment_schema___module.rb +46 -0
- data/original/examples/employment/employment_schema___p28attr.rb +126 -0
- data/original/examples/employment/employment_schema___p28inst.rb +26 -0
- data/original/examples/employment/example_employment_data.xml +1 -0
- data/original/examples/employment/example_employment_data_copy.xml +1 -0
- data/original/examples/employment/example_employment_reader.rb +30 -0
- data/original/examples/employment/example_employment_writer.rb +51 -0
- data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +3710 -0
- data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +35880 -0
- data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +15357 -0
- data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +9468 -0
- data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +8404 -0
- data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +43147 -0
- data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +18341 -0
- data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +11632 -0
- data/original/exp2ruby.rb +525 -0
- data/original/expsm.rb +34 -0
- data/original/mapping_owl.rb +1018 -0
- data/original/mapping_sysml.rb +2281 -0
- data/original/mapping_uml2.rb +599 -0
- data/original/mapping_uml2_eclipse.rb +433 -0
- data/original/reeper.rb +134 -0
- data/spec/acceptance/express_to_owl_spec.rb +18 -0
- data/spec/acceptance/version_spec.rb +12 -0
- data/spec/expressir/express/repository_spec.rb +25 -0
- data/spec/expressr_spec.rb +5 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/console_helper.rb +29 -0
- metadata +239 -0
data/original/expsm.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
## EXPRESS STEPMod Model Ruby Classes
|
2
|
+
## Version 0.1
|
3
|
+
##
|
4
|
+
## The Ruby classes in the model are based on the STEPMod DTD.
|
5
|
+
##
|
6
|
+
|
7
|
+
## process descriptions in external XML file
|
8
|
+
def load_descriptions( descxml, therepos )
|
9
|
+
|
10
|
+
desc_list = descxml.elements.to_a("//ext_descriptions/ext_description")
|
11
|
+
desclinkend_list = []
|
12
|
+
XPath.each( descxml, '//ext_descriptions/ext_description/@linkend' ) { |n| desclinkend_list.push n.to_s }
|
13
|
+
count_desc = desc_list.size
|
14
|
+
puts "-- Processing descriptions . Count is #{count_desc.to_s}"
|
15
|
+
|
16
|
+
for schema in therepos.schemas
|
17
|
+
|
18
|
+
for decl in schema.contents
|
19
|
+
if decl.kind_of? EXPSM::Entity
|
20
|
+
pos = desclinkend_list.index(schema.name + '.' + decl.name)
|
21
|
+
if pos != nil
|
22
|
+
if desc_list[pos].has_elements?
|
23
|
+
defn = 'ELEMENTS_FOUND'
|
24
|
+
else
|
25
|
+
defn = desc_list[pos].text
|
26
|
+
end
|
27
|
+
defn = defn.gsub('"','*')
|
28
|
+
decl.definition = defn.strip
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,1018 @@
|
|
1
|
+
require 'erb'
|
2
|
+
# EXPRESS to OWL Structural Mapping
|
3
|
+
# Version 0.5
|
4
|
+
# This function navigates the EXPRESS STEPMod Model Ruby Classes
|
5
|
+
# and performs a structural EXPRESS-to-OWL mapping using Ruby ERB templates.
|
6
|
+
# The output is in OWL RDF/XML abbreviated syntax.
|
7
|
+
# Mapping summary reports constructs where mapping is not sufficient (i.e. may need editing) or uses newer OWL capabilities
|
8
|
+
#
|
9
|
+
# Configurable items are:
|
10
|
+
# If file named definitions.csv is found, definitions of items are read from that CSV.
|
11
|
+
# Double quotes around ITEM and DEFINITION column values is required
|
12
|
+
# include_dublin_core - If true, import of the Dublin Core OWL is included. Set to true if dc used in annotation_list
|
13
|
+
# annotation_list - added to each construct created if found. Annotations are added if not 'nil'.
|
14
|
+
# usr_base of namespace for OWL constructs
|
15
|
+
# top_class - if not nil, makes every OWL class created a subclass if this class which is added to output
|
16
|
+
# thing_attributes - if specified, OWL DatatypeProperty domain is set to OWL Thing and range set to string
|
17
|
+
# datatype_hash - sets mappings for EXPRESS builtin to XSD datatypes
|
18
|
+
# post_processed_schema - If true, write post-processed schema data (e.g. propety hash) for inclusion in other program or script
|
19
|
+
#
|
20
|
+
# Mappings are:
|
21
|
+
# Entity Types and Subtypes are mapped to OWL Class hierarchy.
|
22
|
+
# Entity Type SUPERTYPE OF ONEOF( list-of-EntityTypes ) are mapped to OWL disjoint between Classes
|
23
|
+
# Select Types that resolve to all Entity Types are mapped to OWL Class hierarchy.
|
24
|
+
# Select Types that resolve to all Type are mapped to RDFS Datatype.
|
25
|
+
# Select Types that resolve to mixed Entity Types and Type are mapped to OWL Class hierarchy, so may need cleanup
|
26
|
+
# Enumeration Types are mapped to OWL Enumerated Classes
|
27
|
+
# Type = builtin are mapped to RDFS Datatypes that subtype XSD datatypes
|
28
|
+
# Type of Type of ... that ultimately resolve to builtin are mapped to datatype subtype hierarchy
|
29
|
+
# Explicit attrs of Type = builtin are mapped to OWL DatatypeProperties
|
30
|
+
# Type = AGGR are mapped to subClassOf rdf:List and type of element not specified
|
31
|
+
|
32
|
+
# Explicit attrs of 1-D LIST/ARRAY OF builtin/Type = builtin mapped to OWL ObjectProperty and subClassOf rdf:List and cardinality 1
|
33
|
+
# Explicit attrs of n-D AGGR mapped to OWL ObjectProperty and subClassOf rdf:List, type of element not specified, and cardinality 1
|
34
|
+
|
35
|
+
# Inverse attrs are mapped to OWL DatatypeProperties with inverseOf set, except inverse of inherited not mapped
|
36
|
+
# BOOLEAN attributes are mapped to OWL DatatypeProperties.
|
37
|
+
|
38
|
+
# Attribute redeclarations that ref Entity/Select are mapped to ObjectProperty that is subproperty of that it redeclares
|
39
|
+
# Attribute redeclarations that ref builting simple types are mapped to DatatypeProperty that is subproperty of that it redeclares
|
40
|
+
# Type = type that is a select are mapped to Class subclass of referenced select Class
|
41
|
+
# Single Attribute OPTIONAL or not maps to cardinality restriction on Class owning attribute
|
42
|
+
# 1D SET/BAG Attribute bound maps to cardinality restriction on Class owning attribute
|
43
|
+
# n-dimensional aggregates map to rdf List with no internal structure and type of element not specified
|
44
|
+
|
45
|
+
|
46
|
+
#
|
47
|
+
def map_from_express( mapinput )
|
48
|
+
puts ' '
|
49
|
+
puts 'EXPRESS to OWL Structural Mapping V0.5'
|
50
|
+
puts ' '
|
51
|
+
|
52
|
+
######### Mapping Configuration Starts Here ##############
|
53
|
+
|
54
|
+
# Set the base of the URI (i.e. the namespace) for OWL constructs created during the mapping
|
55
|
+
uri_base = 'http://www.reeper.org'
|
56
|
+
|
57
|
+
# Add RDFS andor Dublin Core basic annotations
|
58
|
+
|
59
|
+
# Set to true if any annotation_list elements use Dublin Core (dc: or dcterms:)
|
60
|
+
include_dublin_core = false
|
61
|
+
|
62
|
+
annotation_list = Array.new
|
63
|
+
# rdfs:comment must be position 0 as definition assignment hardcoded there
|
64
|
+
#annotation_list[0] = ['rdfs:comment', nil]
|
65
|
+
#annotation_list[1] = ['owl:versionInfo', '1']
|
66
|
+
#annotation_list[2] = ['dc:creator', 'David Price, TopQuadrant Limited']
|
67
|
+
#annotation_list[3] = ['dcterms:created','2010-10-22']
|
68
|
+
#annotation_list[4] = ['dc:source', '{ iso standard 10303 part(214) version(2) object(1) automotive-design-schema(1) }']
|
69
|
+
|
70
|
+
# Read definitions from csv file if found
|
71
|
+
definition_hash = Hash.new
|
72
|
+
if FileTest.exist?('definitions.csv')
|
73
|
+
require 'csv'
|
74
|
+
puts '-- Definitions CSV File Found'
|
75
|
+
CSV.open('definitions.csv', 'r') do |row|
|
76
|
+
definition_hash[row[0].downcase] = row[1]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# set to class name (e.g. 'TOP-THING') to make all created OWL Classes subclasses of a topmost class
|
81
|
+
top_class = 'AP233-ARM-THING'
|
82
|
+
|
83
|
+
# add common string attributes to use OWL Thing as domain rather than schema classes
|
84
|
+
thing_attributes = []
|
85
|
+
#thing_attributes.push 'id'
|
86
|
+
#thing_attributes.push 'name'
|
87
|
+
#thing_attributes.push 'description'
|
88
|
+
|
89
|
+
# datatypes for simple and aggregates of simple type
|
90
|
+
datatype_hash = Hash.new
|
91
|
+
datatype_hash["INTEGER"] = 'http://www.w3.org/2001/XMLSchema#integer'
|
92
|
+
datatype_hash["REAL"] = 'http://www.w3.org/2001/XMLSchema#float'
|
93
|
+
datatype_hash["NUMBER"] = 'http://www.w3.org/2001/XMLSchema#float'
|
94
|
+
datatype_hash["BINARY"] = 'http://www.w3.org/2001/XMLSchema#hexBinary'
|
95
|
+
datatype_hash["BOOLEAN"] = 'http://www.w3.org/2001/XMLSchema#boolean'
|
96
|
+
datatype_hash["LOGICAL"] = 'http://www.w3.org/2001/XMLSchema#boolean'
|
97
|
+
datatype_hash["STRING"] = 'http://www.w3.org/2001/XMLSchema#string'
|
98
|
+
|
99
|
+
# Write the property_type_hash for inclusion in other scripts or not
|
100
|
+
post_processed_schema = false
|
101
|
+
post_processed_schema_file_name = 'postprocessed_schema.rb'
|
102
|
+
post_processed_schema_file = File.new(post_processed_schema_file_name,'w') if post_processed_schema
|
103
|
+
|
104
|
+
######### Mapping Configuration Ends Here ##############
|
105
|
+
|
106
|
+
|
107
|
+
# Template covering the start of the output file
|
108
|
+
overall_start_template = %{<rdf:RDF
|
109
|
+
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
110
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
111
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
|
112
|
+
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
|
113
|
+
<% if include_dublin_core %>
|
114
|
+
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
115
|
+
xmlns:dcterms="http://purl.org/dc/terms/"
|
116
|
+
<% end %>
|
117
|
+
}
|
118
|
+
|
119
|
+
# Template covering the output file contents for each schema start
|
120
|
+
schema_start_template = %{xmlns="<%= uri_base %>/<%= schema.name %>#"
|
121
|
+
xml:base="<%= uri_base %>/<%= schema.name %>#" >
|
122
|
+
|
123
|
+
<owl:Ontology rdf:about='' rdfs:label='<%= schema.name %>' >
|
124
|
+
<% annotation_list.each do |i| %><% if i[1] != nil and i[1] != '' %><<%= i[0] %> rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><%= i[1] %></<%= i[0] %>><% end %>
|
125
|
+
<% end %>
|
126
|
+
<% if include_dublin_core %>
|
127
|
+
<owl:imports rdf:resource="http://purl.org/dc/terms/"/>
|
128
|
+
<owl:imports rdf:resource="http://purl.org/dc/elements/1.1/"/>
|
129
|
+
<% end %>
|
130
|
+
</owl:Ontology>
|
131
|
+
<% if top_class != nil %>
|
132
|
+
<owl:Class rdf:ID='<%= top_class %>' />
|
133
|
+
<% end %>
|
134
|
+
}
|
135
|
+
|
136
|
+
# Template covering the output file contents for each entity type start or start of type = type that is a select
|
137
|
+
entity_start_template = %{
|
138
|
+
<owl:Class rdf:ID='<%= class_name %>' >
|
139
|
+
<% annotation_list.each do |i| %><% if i[1] != nil and i[1] != '' %><<%= i[0] %> rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><%= i[1] %></<%= i[0] %>><% end %>
|
140
|
+
<% end %>
|
141
|
+
}
|
142
|
+
# Template covering the output file contents for each entity type end or end of type = type that is a select
|
143
|
+
entity_end_template = %{
|
144
|
+
<% if top_class != nil %>
|
145
|
+
<rdfs:subClassOf rdf:resource='#<%= top_class %>' />
|
146
|
+
<% end %>
|
147
|
+
</owl:Class>
|
148
|
+
}
|
149
|
+
|
150
|
+
# Template covering the output file contents for end of type = type that is a select
|
151
|
+
class_end_template = %{</owl:Class>}
|
152
|
+
|
153
|
+
# Template covering the output file contents for each select type start
|
154
|
+
select_start_template = %{
|
155
|
+
<owl:Class rdf:ID='<%= select.name %>' >
|
156
|
+
<% annotation_list.each do |i| %><% if i[1] != nil and i[1] != '' %><<%= i[0] %> rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><%= i[1] %></<%= i[0] %>><% end %>
|
157
|
+
<% end %>
|
158
|
+
}
|
159
|
+
# Template covering the output file contents for each select type end
|
160
|
+
select_end_template = %{<% if top_class != nil %>
|
161
|
+
<rdfs:subClassOf rdf:resource='#<%= top_class %>' />
|
162
|
+
<% end %>
|
163
|
+
</owl:Class>
|
164
|
+
}
|
165
|
+
|
166
|
+
# Template covering the supertype(s) for each entity type and type = type that is a select
|
167
|
+
supertype_template = %{<rdfs:subClassOf rdf:resource='#<%= superclass_name %>' />
|
168
|
+
}
|
169
|
+
|
170
|
+
# Template covering OWL collections of class contents
|
171
|
+
class_collection_template = %{<owl:Class><owl:unionOf rdf:parseType="Collection">
|
172
|
+
<% item_name_list.each do |name| %>
|
173
|
+
<rdf:Description rdf:about='#<%= name %>'/>
|
174
|
+
<% end %>
|
175
|
+
</owl:unionOf>
|
176
|
+
</owl:Class>}
|
177
|
+
|
178
|
+
# Template covering OWL collections of RDFS datatypes
|
179
|
+
datatype_collection_template = %{<rdfs:Datatype rdf:ID='<%= type_name %>'>
|
180
|
+
<owl:equivalentClass><rdfs:Datatype><owl:unionOf rdf:parseType="Collection">
|
181
|
+
<% type_name_list.each do |name| %>
|
182
|
+
<rdf:Description rdf:about='#<%= name %>' />
|
183
|
+
<% end %>
|
184
|
+
</owl:unionOf>
|
185
|
+
</rdfs:Datatype></owl:equivalentClass>
|
186
|
+
</rdfs:Datatype>}
|
187
|
+
|
188
|
+
# Template covering abstract entity types
|
189
|
+
abstract_entity_template = %{<rdfs:subClassOf rdf:resource='#<%= supertype.name %>' />
|
190
|
+
}
|
191
|
+
|
192
|
+
# Template covering the output file contents for each defined type of builtin datatype
|
193
|
+
type_builtin_template = %{
|
194
|
+
<rdfs:Datatype rdf:ID='<%= datatype_name %>'>
|
195
|
+
<rdfs:subClassOf rdf:resource='<%= superdatatype_name %>'/>
|
196
|
+
</rdfs:Datatype>
|
197
|
+
}
|
198
|
+
|
199
|
+
# Template covering the mappings to rdf list
|
200
|
+
rdflist_template = %{<rdfs:Class rdf:ID='<%= list_name %>'>
|
201
|
+
<rdfs:subClassOf rdf:resource='<%= superlist_name %>'/>
|
202
|
+
</rdfs:Class>}
|
203
|
+
|
204
|
+
# Template covering the output file contents for each attribute that is an aggregate
|
205
|
+
attribute_aggregate_template = %{}
|
206
|
+
|
207
|
+
# Template covering the output file contents for each attribute that is an aggregate of select of entity
|
208
|
+
attribute_aggregate_entity_select_template = %{}
|
209
|
+
|
210
|
+
# Template covering the output file contents for each attribute that is a select of entity
|
211
|
+
attribute_entity_select_template = %{}
|
212
|
+
|
213
|
+
# Template covering the output file contents for each attribute
|
214
|
+
attribute_template = %{}
|
215
|
+
|
216
|
+
# Template covering the output file contents for each attribute that is builtin datatype
|
217
|
+
attribute_builtin_template = %{<owl:DatatypeProperty rdf:ID='<%= owl_property_name %>'>
|
218
|
+
<% if owl_property_domain != nil %>
|
219
|
+
<rdfs:domain rdf:resource='#<%= owl_property_domain %>' />
|
220
|
+
<% end %>
|
221
|
+
<rdfs:range rdf:resource='<%= owl_property_range %>' />
|
222
|
+
<% annotation_list.each do |i| %><% if i[1] != nil and i[1] != '' %><<%= i[0] %> rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><%= i[1] %></<%= i[0] %>><% end %>
|
223
|
+
<% end %>
|
224
|
+
<% if owl_super_property_name != nil %>
|
225
|
+
<rdfs:subPropertyOf rdf:resource='#<%= owl_super_property_name %>' />
|
226
|
+
<% end %>
|
227
|
+
</owl:DatatypeProperty>
|
228
|
+
}
|
229
|
+
|
230
|
+
# Template covering the output file contents for each attribute that is type that is builtin datatype
|
231
|
+
attribute_typebuiltin_template = %{<owl:DatatypeProperty rdf:ID='<%= owl_property_name %>'>
|
232
|
+
<% if owl_property_domain != nil %>
|
233
|
+
<rdfs:domain rdf:resource='#<%= owl_property_domain %>' />
|
234
|
+
<% end %>
|
235
|
+
<rdfs:range rdf:resource='#<%= owl_property_range %>' />
|
236
|
+
<% annotation_list.each do |i| %><% if i[1] != nil and i[1] != '' %><<%= i[0] %> rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><%= i[1] %></<%= i[0] %>><% end %>
|
237
|
+
<% end %>
|
238
|
+
</owl:DatatypeProperty>
|
239
|
+
}
|
240
|
+
|
241
|
+
# Template covering the output file contents for each attribute that is entity or select type
|
242
|
+
attribute_entity_template = %{<owl:ObjectProperty rdf:ID='<%= owl_property_name %>'>
|
243
|
+
<rdfs:domain rdf:resource='#<%= owl_property_domain %>' />
|
244
|
+
<rdfs:range rdf:resource='#<%= owl_property_range %>' />
|
245
|
+
<% annotation_list.each do |i| %><% if i[1] != nil and i[1] != '' %><<%= i[0] %> rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><%= i[1] %></<%= i[0] %>><% end %>
|
246
|
+
<% end %>
|
247
|
+
</owl:ObjectProperty>
|
248
|
+
}
|
249
|
+
|
250
|
+
# Template covering the output file contents for each attribute that is entity or select type
|
251
|
+
inverse_entity_template = %{<owl:ObjectProperty rdf:ID='<%= owl_property_name %>'>
|
252
|
+
<rdfs:domain rdf:resource='#<%= owl_property_domain %>' />
|
253
|
+
<rdfs:range rdf:resource='#<%= owl_property_range %>' />
|
254
|
+
<% annotation_list.each do |i| %><% if i[1] != nil and i[1] != '' %><<%= i[0] %> rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><%= i[1] %></<%= i[0] %>><% end %>
|
255
|
+
<% end %>
|
256
|
+
<owl:inverseOf rdf:resource="#<%= owl_inverted_property_name %>"/>
|
257
|
+
</owl:ObjectProperty>
|
258
|
+
}
|
259
|
+
|
260
|
+
# Template covering the output file contents for each attribute that is a redeclaration and reference to an entity or select type
|
261
|
+
attribute_redeclare_entity_template = %{<owl:ObjectProperty rdf:ID='<%= owl_property_name %>'>
|
262
|
+
<rdfs:domain rdf:resource='#<%= owl_property_domain %>' />
|
263
|
+
<rdfs:range rdf:resource='#<%= owl_property_range %>' />
|
264
|
+
<rdfs:subPropertyOf rdf:resource='#<%= owl_super_property_name %>' />
|
265
|
+
<% annotation_list.each do |i| %><% if i[1] != nil and i[1] != '' %><<%= i[0] %> rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><%= i[1] %></<%= i[0] %>><% end %>
|
266
|
+
<% end %>
|
267
|
+
</owl:ObjectProperty>
|
268
|
+
}
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
# Template covering the output file contents for each attribute that is enum datatype
|
273
|
+
class_enum_template = %{<owl:Class rdf:ID='<%= owl_class_name %>'>
|
274
|
+
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
|
275
|
+
<owl:oneOf rdf:parseType="Collection">
|
276
|
+
<% enumitem_name_list.each do |name| %>
|
277
|
+
<rdf:Description rdf:ID="<%= owl_class_name + '.' + name %>"/>
|
278
|
+
<% end %>
|
279
|
+
</owl:oneOf>
|
280
|
+
</owl:Class>}
|
281
|
+
|
282
|
+
|
283
|
+
# Template covering the output file contents for each attribute that is enum datatype
|
284
|
+
attribute_enum_template = %{<owl:DatatypeProperty rdf:ID='<%= owl_property_name %>'>
|
285
|
+
<rdfs:domain rdf:resource='#<%= owl_property_domain %>' />
|
286
|
+
<rdfs:range><owl:DataRange><owl:oneOf><rdf:List>
|
287
|
+
<% enumitem_name_list.each do |name| %>
|
288
|
+
<rdf:first rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><%= name %></rdf:first>
|
289
|
+
<% if enumitem_name_list[enumitem_name_list.size-1] != name %>
|
290
|
+
<rdf:rest><rdf:List>
|
291
|
+
<% end %>
|
292
|
+
<% if enumitem_name_list[enumitem_name_list.size-1] == name %>
|
293
|
+
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/> </rdf:List>
|
294
|
+
<% end %>
|
295
|
+
<% end %>
|
296
|
+
<% (1..enumitem_name_list.size-1).each do %>
|
297
|
+
</rdf:rest></rdf:List>
|
298
|
+
<% end %>
|
299
|
+
</owl:oneOf></owl:DataRange></rdfs:range>
|
300
|
+
<% annotation_list.each do |i| %><% if i[1] != nil and i[1] != '' %><<%= i[0] %> rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><%= i[1] %></<%= i[0] %>><% end %>
|
301
|
+
<% end %>
|
302
|
+
</owl:DatatypeProperty>}
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
# Template covering min cardinality
|
307
|
+
min_cardinality_template = %{<rdf:Description rdf:about='#<%= class_name %>'>
|
308
|
+
<rdfs:subClassOf>
|
309
|
+
<owl:Restriction>
|
310
|
+
<owl:onProperty rdf:resource='#<%= owl_property_name %>'/>
|
311
|
+
<owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"><%= min_cardinality %></owl:minCardinality>
|
312
|
+
</owl:Restriction>
|
313
|
+
</rdfs:subClassOf>
|
314
|
+
</rdf:Description>}
|
315
|
+
|
316
|
+
|
317
|
+
# Template covering max cardinality
|
318
|
+
max_cardinality_template = %{<rdf:Description rdf:about='#<%= class_name %>'>
|
319
|
+
<rdfs:subClassOf>
|
320
|
+
<owl:Restriction>
|
321
|
+
<owl:onProperty rdf:resource='#<%= owl_property_name %>'/>
|
322
|
+
<owl:maxCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"><%= max_cardinality %></owl:maxCardinality>
|
323
|
+
</owl:Restriction>
|
324
|
+
</rdfs:subClassOf>
|
325
|
+
</rdf:Description>}
|
326
|
+
|
327
|
+
# Template covering cardinality
|
328
|
+
cardinality_template = %{<rdf:Description rdf:about='#<%= class_name %>'>
|
329
|
+
<rdfs:subClassOf>
|
330
|
+
<owl:Restriction>
|
331
|
+
<owl:onProperty rdf:resource='#<%= owl_property_name %>'/>
|
332
|
+
<owl:cardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"><%= min_cardinality %></owl:cardinality>
|
333
|
+
</owl:Restriction>
|
334
|
+
</rdfs:subClassOf>
|
335
|
+
</rdf:Description>}
|
336
|
+
|
337
|
+
# Template covering the output file contents for each schema end
|
338
|
+
disjoint_template = %{
|
339
|
+
<rdf:Description rdf:about='#<%= first_class_name %>'>
|
340
|
+
<owl:disjointWith rdf:resource="#<%= disjoint_class_name %>"/>
|
341
|
+
</rdf:Description>}
|
342
|
+
|
343
|
+
|
344
|
+
# Template covering the output file contents for each schema end
|
345
|
+
schema_end_template = %{}
|
346
|
+
|
347
|
+
# Template covering the end of the output file
|
348
|
+
overall_end_template = %{ </rdf:RDF>}
|
349
|
+
|
350
|
+
|
351
|
+
def post_process_entity(entity, post_processed_schema_file, datatype_hash)
|
352
|
+
attribute_list = entity.attributes_all_array.find_all{ |a| a.kind_of? EXPSM::Explicit}
|
353
|
+
|
354
|
+
for attribute in attribute_list
|
355
|
+
|
356
|
+
express_attribute_domain = nil
|
357
|
+
if !attribute.isBuiltin
|
358
|
+
express_attribute_domain = NamedType.find_by_name( attribute.domain )
|
359
|
+
end
|
360
|
+
p28_property_name = entity.name.capitalize + '.' + attribute.name.capitalize
|
361
|
+
property_quoted = false
|
362
|
+
property_list = false
|
363
|
+
property_type = '"' + attribute.domain + '"'
|
364
|
+
if attribute.isBuiltin
|
365
|
+
property_type = '"' + datatype_hash[attribute.domain] + '"'
|
366
|
+
end
|
367
|
+
if attribute.isBuiltin and attribute.domain == 'STRING'
|
368
|
+
property_quoted = true
|
369
|
+
end
|
370
|
+
if (!attribute.redeclare_entity and express_attribute_domain.instance_of? EXPSM::Type and express_attribute_domain.isBuiltin and express_attribute_domain == 'STRING')
|
371
|
+
property_quoted = true
|
372
|
+
property_type = '"' + datatype_hash[express_attribute_domain.domain] + '"'
|
373
|
+
end
|
374
|
+
if ( attribute.isBuiltin and attribute.instance_of? EXPSM::ExplicitAggregate and attribute.rank == 1 and attribute.dimensions[0].aggrtype = 'LIST')
|
375
|
+
property_list = true
|
376
|
+
property_type = '"' + datatype_hash[attribute.domain] + '"'
|
377
|
+
end
|
378
|
+
|
379
|
+
if (express_attribute_domain.instance_of? EXPSM::Type and express_attribute_domain.isBuiltin and attribute.instance_of? EXPSM::ExplicitAggregate and attribute.rank == 1 and attribute.dimensions[0].aggrtype = 'LIST')
|
380
|
+
property_list = true
|
381
|
+
property_type = '"' + datatype_hash[express_attribute_domain.domain] + '"'
|
382
|
+
end
|
383
|
+
|
384
|
+
property_type = property_type.gsub('http://www.w3.org/2001/XMLSchema#','xsd:')
|
385
|
+
post_processed_schema_file.puts 'property_range_hash["' + p28_property_name + '"] = [' + property_quoted.to_s + ',' + property_list.to_s + ',' + property_type.to_s + ']'
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
|
390
|
+
# A recursive function to return complete set of items, following nested selects, for a select that are not selects themselves
|
391
|
+
def get_all_selections( item_list )
|
392
|
+
select_items = item_list.find_all{ |a| a.kind_of? EXPSM::TypeSelect}
|
393
|
+
if select_items.size == 0
|
394
|
+
return item_list
|
395
|
+
end
|
396
|
+
temp_item_list = item_list
|
397
|
+
for select in select_items
|
398
|
+
temp_item_list.delete( select )
|
399
|
+
temp_item_list = temp_item_list + select.selectitems_array
|
400
|
+
end
|
401
|
+
final_list = get_all_selections( temp_item_list )
|
402
|
+
end
|
403
|
+
|
404
|
+
# A recursive function to return the ultimate underlying type of a type
|
405
|
+
def is_utlimate_type_builtin( the_type )
|
406
|
+
return true if the_type.isBuiltin
|
407
|
+
base_type = NamedType.find_by_name( the_type.domain )
|
408
|
+
case
|
409
|
+
when (base_type.instance_of? EXPSM::TypeSelect or base_type.instance_of? EXPSM::Entity)
|
410
|
+
return false
|
411
|
+
when (base_type.kind_of? EXPSM::Type and base_type.isBuiltin)
|
412
|
+
return true
|
413
|
+
else
|
414
|
+
return is_utlimate_type_builtin( base_type )
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
# Set up list of schemas to process, input may be a repository containing schemas or a single schema
|
419
|
+
if mapinput.kind_of? EXPSM::Repository
|
420
|
+
schema_list = mapinput.schemas
|
421
|
+
elsif mapinput.kind_of? EXPSM::SchemaDefinition
|
422
|
+
schema_list = [mapinput]
|
423
|
+
else
|
424
|
+
puts "ERROR : map_from_express input no Repository instance or Schema instance"
|
425
|
+
exit
|
426
|
+
end
|
427
|
+
|
428
|
+
|
429
|
+
for schema in schema_list
|
430
|
+
|
431
|
+
type_mapped_list = []
|
432
|
+
entity_mapped_list = []
|
433
|
+
explicit_mapped_list = []
|
434
|
+
inverse_mapped_list = []
|
435
|
+
thing_attr_mapped_list = []
|
436
|
+
superexpression_mapped_list = []
|
437
|
+
list_mapped_attr_list = []
|
438
|
+
list_mapped_type_list = []
|
439
|
+
type_union_mapped_list = []
|
440
|
+
mixed_select_list = []
|
441
|
+
all_explicit_list = []
|
442
|
+
all_derived_list = []
|
443
|
+
all_inverse_list = []
|
444
|
+
all_superexpression_list = []
|
445
|
+
|
446
|
+
# Set up separate file for each schema
|
447
|
+
filename = schema.name.to_s + ".owl"
|
448
|
+
file = File.new(filename, "w")
|
449
|
+
|
450
|
+
# Evaluate and write file start template
|
451
|
+
res = ERB.new(overall_start_template)
|
452
|
+
t = res.result(binding)
|
453
|
+
file.puts t
|
454
|
+
|
455
|
+
# Evaluate and write schema start template
|
456
|
+
res = ERB.new(schema_start_template)
|
457
|
+
t = res.result(binding)
|
458
|
+
file.puts t
|
459
|
+
|
460
|
+
select_list = schema.contents.find_all{ |e| e.kind_of? EXPSM::TypeSelect }
|
461
|
+
entity_list = schema.contents.find_all{ |e| e.kind_of? EXPSM::Entity }
|
462
|
+
defined_type_list = schema.contents.find_all{ |e| e.kind_of? EXPSM::Type }
|
463
|
+
enum_type_list = schema.contents.find_all{ |e| e.kind_of? EXPSM::TypeEnum }
|
464
|
+
defined_type_not_builtin_list = defined_type_list.find_all{ |e| !e.isBuiltin }
|
465
|
+
defined_type_builtin_list = defined_type_list.find_all{ |e| e.isBuiltin }
|
466
|
+
|
467
|
+
# Handle enumeration type maps to RDFS Datatype string
|
468
|
+
|
469
|
+
for type_enum in enum_type_list
|
470
|
+
type_mapped_list.push type_enum
|
471
|
+
owl_class_name = type_enum.name
|
472
|
+
enumitem_name_list = type_enum.items.scan(/\w+/)
|
473
|
+
res = ERB.new(class_enum_template)
|
474
|
+
t = res.result(binding)
|
475
|
+
file.puts t
|
476
|
+
end
|
477
|
+
|
478
|
+
|
479
|
+
# Handle defined type maps to RDFS Datatype
|
480
|
+
|
481
|
+
for type_builtin in defined_type_builtin_list
|
482
|
+
|
483
|
+
# Handle defined type maps to RDFS Datatype
|
484
|
+
if !type_builtin.instance_of? EXPSM::TypeAggregate
|
485
|
+
type_mapped_list.push type_builtin
|
486
|
+
datatype_name = type_builtin.name
|
487
|
+
superdatatype_name = datatype_hash[type_builtin.domain]
|
488
|
+
res = ERB.new(type_builtin_template)
|
489
|
+
t = res.result(binding)
|
490
|
+
file.puts t
|
491
|
+
# Handle defined type maps to RDF List
|
492
|
+
else
|
493
|
+
list_mapped_type_list.push type_builtin
|
494
|
+
type_mapped_list.push type_builtin
|
495
|
+
list_name = type_builtin.name
|
496
|
+
superlist_name = "http://www.w3.org/1999/02/22-rdf-syntax-ns#List"
|
497
|
+
res = ERB.new(rdflist_template)
|
498
|
+
t = res.result(binding)
|
499
|
+
file.puts t
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
|
504
|
+
for type_not_builtin in defined_type_not_builtin_list
|
505
|
+
|
506
|
+
type_domain = NamedType.find_by_name( type_not_builtin.domain )
|
507
|
+
type_is_builtin = is_utlimate_type_builtin( type_not_builtin )
|
508
|
+
|
509
|
+
case
|
510
|
+
|
511
|
+
# Handle simple defined type refining simple defined type of builtin map to RDFS Datatype
|
512
|
+
when (!type_not_builtin.instance_of? EXPSM::TypeAggregate and type_is_builtin and !type_domain.instance_of? EXPSM::TypeAggregate)
|
513
|
+
type_mapped_list.push type_not_builtin
|
514
|
+
datatype_name = type_not_builtin.name
|
515
|
+
superdatatype_name = '#' + type_domain.name
|
516
|
+
res = ERB.new(type_builtin_template)
|
517
|
+
t = res.result(binding)
|
518
|
+
file.puts t
|
519
|
+
|
520
|
+
# Handle simple defined type of aggr defined type of builtin map to RDF List
|
521
|
+
when (!type_not_builtin.instance_of? EXPSM::TypeAggregate and type_domain.instance_of? EXPSM::TypeAggregate and type_is_builtin)
|
522
|
+
type_mapped_list.push type_not_builtin
|
523
|
+
list_mapped_type_list.push type_not_builtin
|
524
|
+
list_name = type_not_builtin.name
|
525
|
+
superlist_name = '#' + type_domain.name
|
526
|
+
res = ERB.new(rdflist_template)
|
527
|
+
t = res.result(binding)
|
528
|
+
file.puts t
|
529
|
+
|
530
|
+
# Handle aggr defined type of simple defined type of builtin map to RDF List
|
531
|
+
when (type_not_builtin.instance_of? EXPSM::TypeAggregate and type_domain.instance_of? EXPSM::Type and type_is_builtin)
|
532
|
+
type_mapped_list.push type_not_builtin
|
533
|
+
list_mapped_type_list.push type_not_builtin
|
534
|
+
list_name = type_not_builtin.name
|
535
|
+
superlist_name = "http://www.w3.org/1999/02/22-rdf-syntax-ns#List"
|
536
|
+
res = ERB.new(rdflist_template)
|
537
|
+
t = res.result(binding)
|
538
|
+
file.puts t
|
539
|
+
|
540
|
+
# Handle aggr of entity/select type map to RDF List
|
541
|
+
when (type_not_builtin.instance_of? EXPSM::TypeAggregate and (type_domain.instance_of? EXPSM::Entity or type_domain.instance_of? EXPSM::TypeSelect))
|
542
|
+
type_mapped_list.push type_not_builtin
|
543
|
+
list_mapped_type_list.push type_not_builtin
|
544
|
+
list_name = type_not_builtin.name
|
545
|
+
superlist_name = "http://www.w3.org/1999/02/22-rdf-syntax-ns#List"
|
546
|
+
res = ERB.new(rdflist_template)
|
547
|
+
t = res.result(binding)
|
548
|
+
file.puts t
|
549
|
+
|
550
|
+
# Handle defined type that are type = type that is a select
|
551
|
+
when (type_domain.kind_of? EXPSM::TypeSelect)
|
552
|
+
type_mapped_list.push type_not_builtin
|
553
|
+
superclass_name = type_not_builtin.domain
|
554
|
+
class_name = type_not_builtin.name
|
555
|
+
res = ERB.new(entity_start_template)
|
556
|
+
t = res.result(binding)
|
557
|
+
file.puts t
|
558
|
+
|
559
|
+
superclass_name = type_not_builtin.domain
|
560
|
+
res = ERB.new(supertype_template)
|
561
|
+
t = res.result(binding)
|
562
|
+
file.puts t
|
563
|
+
|
564
|
+
res = ERB.new(class_end_template)
|
565
|
+
t = res.result(binding)
|
566
|
+
file.puts t
|
567
|
+
|
568
|
+
else
|
569
|
+
puts 'ERROR : Not mapped = ' + type_not_builtin.name
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
|
574
|
+
# Handle EXPRESS SELECT Type mapping to OWL Class hierarchy and RDFS Datatypes
|
575
|
+
|
576
|
+
for select in select_list
|
577
|
+
|
578
|
+
item_name_list = select.selectitems.scan(/\w+/)
|
579
|
+
|
580
|
+
this_select_all_items = get_all_selections( select.selectitems_array )
|
581
|
+
this_select_type_items = this_select_all_items.find_all{ |a| a.kind_of? EXPSM::Type}
|
582
|
+
|
583
|
+
case
|
584
|
+
|
585
|
+
# Handle case of select items resolving to containing only items that are non-select Type
|
586
|
+
when this_select_type_items.size == this_select_all_items.size
|
587
|
+
type_mapped_list.push select
|
588
|
+
type_union_mapped_list.push select
|
589
|
+
type_name_list = item_name_list
|
590
|
+
type_name = select.name
|
591
|
+
res = ERB.new(datatype_collection_template)
|
592
|
+
t = res.result(binding)
|
593
|
+
file.puts t
|
594
|
+
|
595
|
+
# Handle case of select items resolving to containing no item that is a non-select Type
|
596
|
+
else
|
597
|
+
type_mapped_list.push select
|
598
|
+
|
599
|
+
res = ERB.new(select_start_template)
|
600
|
+
t = res.result(binding)
|
601
|
+
file.puts t
|
602
|
+
file.puts '<owl:equivalentClass>'
|
603
|
+
|
604
|
+
res = ERB.new(class_collection_template)
|
605
|
+
t = res.result(binding)
|
606
|
+
file.puts t
|
607
|
+
file.puts '</owl:equivalentClass>'
|
608
|
+
|
609
|
+
res = ERB.new(select_end_template)
|
610
|
+
t = res.result(binding)
|
611
|
+
file.puts t
|
612
|
+
if (this_select_type_items.size != 0 and this_select_type_items.size != this_select_all_items.size)
|
613
|
+
mixed_select_list.push select
|
614
|
+
end
|
615
|
+
|
616
|
+
end
|
617
|
+
end
|
618
|
+
|
619
|
+
# Handle EXPRESS Entity mappings to OWL Class hierarchy
|
620
|
+
|
621
|
+
for entity in entity_list
|
622
|
+
|
623
|
+
if definition_hash[entity.name.downcase] != nil
|
624
|
+
annotation_list[0] = ['rdfs:comment', definition_hash[entity.name.downcase]]
|
625
|
+
else
|
626
|
+
annotation_list[0] = ['rdfs:comment', nil]
|
627
|
+
end
|
628
|
+
|
629
|
+
entity_mapped_list.push entity
|
630
|
+
|
631
|
+
class_name = entity.name
|
632
|
+
res = ERB.new(entity_start_template)
|
633
|
+
t = res.result(binding)
|
634
|
+
file.puts t
|
635
|
+
|
636
|
+
for supertype in entity.supertypes_array
|
637
|
+
superclass_name = supertype.name
|
638
|
+
res = ERB.new(supertype_template)
|
639
|
+
t = res.result(binding)
|
640
|
+
file.puts t
|
641
|
+
end
|
642
|
+
|
643
|
+
res = ERB.new(entity_end_template)
|
644
|
+
t = res.result(binding)
|
645
|
+
file.puts t
|
646
|
+
|
647
|
+
# Post-process the entity
|
648
|
+
post_process_entity(entity, post_processed_schema_file, datatype_hash) if post_processed_schema
|
649
|
+
|
650
|
+
|
651
|
+
if entity.superexpression != nil
|
652
|
+
all_superexpression_list.push entity
|
653
|
+
|
654
|
+
# Handle simple case of one ONEOF in supertype expression mapped to disjoint between listed subclasses
|
655
|
+
case
|
656
|
+
# when (entity.superexpression.include?('ONEOF') and !entity.superexpression.include?('ANDOR') and !entity.superexpression.include?('TOTAL_OVER') and !entity.superexpression.include?('AND') and !entity.superexpression.include?('ABSTRACT'))
|
657
|
+
|
658
|
+
when (entity.superexpression.include?('ONEOF'))
|
659
|
+
superexpression_mapped_list.push entity
|
660
|
+
tempexpression = entity.superexpression
|
661
|
+
if entity.superexpression.index('ONEOF') != 0
|
662
|
+
puts 'WARNING: ' + entity.name + ' supertype mapping may be incomplete, only ONEOFs processed'
|
663
|
+
end
|
664
|
+
while (tempexpression.include?('ONEOF'))
|
665
|
+
posoneof = tempexpression.index('ONEOF')
|
666
|
+
tempexpression = tempexpression[posoneof + 5,tempexpression.length - 5]
|
667
|
+
posclose = tempexpression.index(')')
|
668
|
+
oneof_name_list = tempexpression[0,posclose].scan(/\w+/)
|
669
|
+
while oneof_name_list.size != 0
|
670
|
+
first_class_name = oneof_name_list[0]
|
671
|
+
oneof_name_list.delete(first_class_name)
|
672
|
+
for disjoint_class_name in oneof_name_list
|
673
|
+
res = ERB.new(disjoint_template)
|
674
|
+
t = res.result(binding)
|
675
|
+
file.puts t
|
676
|
+
end
|
677
|
+
end
|
678
|
+
end
|
679
|
+
else
|
680
|
+
end
|
681
|
+
|
682
|
+
end
|
683
|
+
|
684
|
+
|
685
|
+
end
|
686
|
+
|
687
|
+
# Handle mapping common string attributes to OWL DatatypeProperties of OWL Thing
|
688
|
+
|
689
|
+
for thing_attribute in thing_attributes
|
690
|
+
owl_property_name = thing_attribute
|
691
|
+
owl_property_range = 'http://www.w3.org/2001/XMLSchema#string'
|
692
|
+
owl_property_domain = nil
|
693
|
+
owl_super_property_name = nil
|
694
|
+
res = ERB.new(attribute_builtin_template)
|
695
|
+
t = res.result(binding)
|
696
|
+
file.puts t
|
697
|
+
end
|
698
|
+
|
699
|
+
# Handle EXPRESS attributes on an entity-by-entity basis
|
700
|
+
for entity in entity_list
|
701
|
+
|
702
|
+
class_name = entity.name
|
703
|
+
|
704
|
+
attribute_list = entity.attributes.find_all{ |a| a.kind_of? EXPSM::Explicit and !thing_attributes.include?(a.name)}
|
705
|
+
thing_attr_list = entity.attributes.find_all{ |a| a.kind_of? EXPSM::Explicit and thing_attributes.include?(a.name)}
|
706
|
+
inverse_list = entity.attributes.find_all{ |a| a.kind_of? EXPSM::Inverse and !thing_attributes.include?(a.name)}
|
707
|
+
|
708
|
+
thing_attr_mapped_list = thing_attr_mapped_list + thing_attr_list
|
709
|
+
|
710
|
+
all_explicit_list = all_explicit_list + entity.attributes.find_all{ |a| a.kind_of? EXPSM::Explicit}
|
711
|
+
all_derived_list = all_derived_list + entity.attributes.find_all{ |a| a.kind_of? EXPSM::Derived}
|
712
|
+
|
713
|
+
all_inverse_list = all_inverse_list + inverse_list
|
714
|
+
|
715
|
+
# Handle EXPRESS inverse attribute mapping to OWL inverse property
|
716
|
+
for attribute in inverse_list
|
717
|
+
if attribute.reverseAttr != []
|
718
|
+
inverse_mapped_list.push attribute
|
719
|
+
owl_property_range = attribute.domain
|
720
|
+
owl_property_name = entity.name + '.' + attribute.name
|
721
|
+
owl_property_domain = entity.name
|
722
|
+
owl_inverted_property_name = attribute.reverseEntity.name + '.' + attribute.reverseAttr.name
|
723
|
+
res = ERB.new(inverse_entity_template)
|
724
|
+
t = res.result(binding)
|
725
|
+
file.puts t
|
726
|
+
end
|
727
|
+
end
|
728
|
+
|
729
|
+
# Handle EXPRESS explicit attribute mapping to OWL property
|
730
|
+
for attribute in attribute_list
|
731
|
+
|
732
|
+
express_attribute_domain = nil
|
733
|
+
type_is_builtin = false
|
734
|
+
if !attribute.isBuiltin
|
735
|
+
express_attribute_domain = NamedType.find_by_name( attribute.domain )
|
736
|
+
if express_attribute_domain.instance_of? EXPSM::Type
|
737
|
+
type_is_builtin = is_utlimate_type_builtin( express_attribute_domain )
|
738
|
+
end
|
739
|
+
end
|
740
|
+
|
741
|
+
case
|
742
|
+
|
743
|
+
# Handle EXPRESS explicit attributes of LIST of built-in simple type, including redeclaration
|
744
|
+
when (attribute.isBuiltin and attribute.instance_of? EXPSM::ExplicitAggregate and attribute.rank == 1 and attribute.dimensions[0].aggrtype = 'LIST')
|
745
|
+
explicit_mapped_list.push attribute
|
746
|
+
list_mapped_attr_list.push attribute
|
747
|
+
list_name = entity.name + '.' + attribute.name + '-' + attribute.domain.to_s + '-List'
|
748
|
+
superlist_name = "http://www.w3.org/1999/02/22-rdf-syntax-ns#List"
|
749
|
+
res = ERB.new(rdflist_template)
|
750
|
+
t = res.result(binding)
|
751
|
+
file.puts t
|
752
|
+
owl_property_name = entity.name + '.' + attribute.name
|
753
|
+
owl_property_domain = entity.name
|
754
|
+
owl_property_range = list_name
|
755
|
+
res = ERB.new(attribute_entity_template)
|
756
|
+
t = res.result(binding)
|
757
|
+
file.puts t
|
758
|
+
|
759
|
+
# Handle EXPRESS explicit attributes of ARRAY of built-in simple type, including redeclaration
|
760
|
+
when (attribute.isBuiltin and attribute.instance_of? EXPSM::ExplicitAggregate and attribute.rank == 1 and attribute.dimensions[0].aggrtype = 'ARRAY')
|
761
|
+
explicit_mapped_list.push attribute
|
762
|
+
list_mapped_attr_list.push attribute
|
763
|
+
list_name = entity.name + '.' + attribute.name + '-' + attribute.domain.to_s + '-Array'
|
764
|
+
superlist_name = "http://www.w3.org/1999/02/22-rdf-syntax-ns#List"
|
765
|
+
res = ERB.new(rdflist_template)
|
766
|
+
t = res.result(binding)
|
767
|
+
file.puts t
|
768
|
+
owl_property_name = entity.name + '.' + attribute.name
|
769
|
+
owl_property_domain = entity.name
|
770
|
+
owl_property_range = list_name
|
771
|
+
res = ERB.new(attribute_entity_template)
|
772
|
+
t = res.result(binding)
|
773
|
+
file.puts t
|
774
|
+
|
775
|
+
# Handle EXPRESS explicit attributes of LIST of TYPE that is built-in simple type, including redeclaration
|
776
|
+
when (express_attribute_domain.instance_of? EXPSM::Type and type_is_builtin and attribute.instance_of? EXPSM::ExplicitAggregate and attribute.rank == 1 and attribute.dimensions[0].aggrtype = 'LIST')
|
777
|
+
explicit_mapped_list.push attribute
|
778
|
+
list_mapped_attr_list.push attribute
|
779
|
+
list_name = entity.name + '.' + attribute.name + '-' + attribute.domain.to_s + '-List'
|
780
|
+
superlist_name = "http://www.w3.org/1999/02/22-rdf-syntax-ns#List"
|
781
|
+
res = ERB.new(rdflist_template)
|
782
|
+
t = res.result(binding)
|
783
|
+
file.puts t
|
784
|
+
owl_property_name = entity.name + '.' + attribute.name
|
785
|
+
owl_property_domain = entity.name
|
786
|
+
owl_property_range = list_name
|
787
|
+
res = ERB.new(attribute_entity_template)
|
788
|
+
t = res.result(binding)
|
789
|
+
file.puts t
|
790
|
+
|
791
|
+
# Handle EXPRESS explicit attributes of ARRAY of TYPE that is built-in simple type, including redeclaration
|
792
|
+
when (express_attribute_domain.instance_of? EXPSM::Type and type_is_builtin and attribute.instance_of? EXPSM::ExplicitAggregate and attribute.rank == 1 and attribute.dimensions[0].aggrtype = 'ARRAY')
|
793
|
+
explicit_mapped_list.push attribute
|
794
|
+
list_mapped_attr_list.push attribute
|
795
|
+
list_name = entity.name + '.' + attribute.name + '-' + attribute.domain.to_s + '-Array'
|
796
|
+
superlist_name = "http://www.w3.org/1999/02/22-rdf-syntax-ns#List"
|
797
|
+
res = ERB.new(rdflist_template)
|
798
|
+
t = res.result(binding)
|
799
|
+
file.puts t
|
800
|
+
owl_property_name = entity.name + '.' + attribute.name
|
801
|
+
owl_property_domain = entity.name
|
802
|
+
owl_property_range = list_name
|
803
|
+
res = ERB.new(attribute_entity_template)
|
804
|
+
t = res.result(binding)
|
805
|
+
file.puts t
|
806
|
+
|
807
|
+
|
808
|
+
# Handle EXPRESS explicit attributes of built-in simple type, including redeclaration
|
809
|
+
when (attribute.isBuiltin)
|
810
|
+
explicit_mapped_list.push attribute
|
811
|
+
owl_property_range = datatype_hash[attribute.domain]
|
812
|
+
owl_property_name = entity.name + '.' + attribute.name
|
813
|
+
owl_property_domain = entity.name
|
814
|
+
owl_super_property_name = nil
|
815
|
+
if attribute.redeclare_entity != nil
|
816
|
+
if attribute.redeclare_oldname == nil
|
817
|
+
owl_super_property_name = attribute.redeclare_entity + '.' + attribute.name
|
818
|
+
else
|
819
|
+
owl_super_property_name = attribute.redeclare_entity + '.' + attribute.redeclare_oldname
|
820
|
+
end
|
821
|
+
end
|
822
|
+
res = ERB.new(attribute_builtin_template)
|
823
|
+
t = res.result(binding)
|
824
|
+
file.puts t
|
825
|
+
|
826
|
+
# Handle EXPRESS explicit attribute, not redeclaration, refers to Type that is Type = builtin datatype
|
827
|
+
when (!attribute.redeclare_entity and express_attribute_domain.instance_of? EXPSM::Type and type_is_builtin)
|
828
|
+
explicit_mapped_list.push attribute
|
829
|
+
owl_property_range = attribute.domain
|
830
|
+
owl_property_name = entity.name + '.' + attribute.name
|
831
|
+
owl_property_domain = entity.name
|
832
|
+
res = ERB.new(attribute_typebuiltin_template)
|
833
|
+
t = res.result(binding)
|
834
|
+
file.puts t
|
835
|
+
|
836
|
+
# Handle EXPRESS explicit attributes of enum type, ignoring redeclarations
|
837
|
+
when (express_attribute_domain.kind_of? EXPSM::TypeEnum)
|
838
|
+
explicit_mapped_list.push attribute
|
839
|
+
owl_property_name = entity.name + '.' + attribute.name
|
840
|
+
owl_property_domain = entity.name
|
841
|
+
owl_property_range = attribute.domain
|
842
|
+
res = ERB.new(attribute_entity_template)
|
843
|
+
|
844
|
+
# if !type_mapped_list.include?(express_attribute_domain)
|
845
|
+
# type_mapped_list.push express_attribute_domain
|
846
|
+
# end
|
847
|
+
# enumitem_name_list = express_attribute_domain.items.scan(/\w+/)
|
848
|
+
# res = ERB.new(attribute_enum_template)
|
849
|
+
|
850
|
+
t = res.result(binding)
|
851
|
+
file.puts t
|
852
|
+
if attribute.redeclare_entity
|
853
|
+
puts 'WARNING: ' + entity.name + ' ' + attribute.name + ' Attribute redeclaration for Enumerations not mapped'
|
854
|
+
end
|
855
|
+
|
856
|
+
# Handle EXPRESS explicit attribute, not redeclaration, and only refer to EXPRESS Select or Entity
|
857
|
+
when (!attribute.redeclare_entity and (express_attribute_domain.kind_of? EXPSM::Entity or express_attribute_domain.kind_of? EXPSM::TypeSelect))
|
858
|
+
explicit_mapped_list.push attribute
|
859
|
+
owl_property_range = attribute.domain
|
860
|
+
owl_property_name = entity.name + '.' + attribute.name
|
861
|
+
owl_property_domain = entity.name
|
862
|
+
res = ERB.new(attribute_entity_template)
|
863
|
+
t = res.result(binding)
|
864
|
+
file.puts t
|
865
|
+
|
866
|
+
# Handle EXPRESS explicit attribute, redeclaration, and only refer to EXPRESS Select or Entity
|
867
|
+
when (attribute.redeclare_entity and (express_attribute_domain.kind_of? EXPSM::Entity or express_attribute_domain.kind_of? EXPSM::TypeSelect))
|
868
|
+
explicit_mapped_list.push attribute
|
869
|
+
owl_property_range = attribute.domain
|
870
|
+
owl_property_name = entity.name + '.' + attribute.name
|
871
|
+
if attribute.redeclare_oldname == nil
|
872
|
+
owl_super_property_name = attribute.redeclare_entity + '.' + attribute.name
|
873
|
+
else
|
874
|
+
owl_super_property_name = attribute.redeclare_entity + '.' + attribute.redeclare_oldname
|
875
|
+
end
|
876
|
+
owl_property_domain = entity.name
|
877
|
+
res = ERB.new(attribute_redeclare_entity_template)
|
878
|
+
t = res.result(binding)
|
879
|
+
file.puts t
|
880
|
+
|
881
|
+
# Handle EXPRESS explicit attribute of EXPRESS Type = A Type name that is a Select
|
882
|
+
when (express_attribute_domain.kind_of? EXPSM::Type and NamedType.find_by_name( express_attribute_domain.domain ).kind_of? EXPSM::TypeSelect)
|
883
|
+
explicit_mapped_list.push attribute
|
884
|
+
owl_property_range = attribute.domain
|
885
|
+
owl_property_name = entity.name + '.' + attribute.name
|
886
|
+
owl_property_domain = entity.name
|
887
|
+
res = ERB.new(attribute_entity_template)
|
888
|
+
t = res.result(binding)
|
889
|
+
file.puts t
|
890
|
+
|
891
|
+
# Handle EXPRESS explicit attribute, redeclaration, and only refer to EXPRESS Type = A Type name that is a Select
|
892
|
+
when (attribute.redeclare_entity and (express_attribute_domain.kind_of? EXPSM::Type and NamedType.find_by_name( express_attribute_domain.domain ).kind_of? EXPSM::TypeSelect))
|
893
|
+
|
894
|
+
explicit_mapped_list.push attribute
|
895
|
+
owl_property_range = attribute.domain
|
896
|
+
owl_property_name = entity.name + '.' + attribute.name
|
897
|
+
if attribute.redeclare_oldname == nil
|
898
|
+
owl_super_property_name = attribute.redeclare_entity + '.' + attribute.name
|
899
|
+
else
|
900
|
+
owl_super_property_name = attribute.redeclare_entity + '.' + attribute.redeclare_oldname
|
901
|
+
end
|
902
|
+
owl_property_domain = entity.name
|
903
|
+
res = ERB.new(attribute_redeclare_entity_template)
|
904
|
+
t = res.result(binding)
|
905
|
+
file.puts t
|
906
|
+
|
907
|
+
else
|
908
|
+
puts 'WARNING: ' + entity.name + ' ' + attribute.name + ' Attribute type not yet mapped'
|
909
|
+
end
|
910
|
+
|
911
|
+
min_cardinality = 1
|
912
|
+
max_cardinality = 1
|
913
|
+
|
914
|
+
if attribute.isOptional == true
|
915
|
+
min_cardinality = 0
|
916
|
+
end
|
917
|
+
|
918
|
+
if (attribute.instance_of? EXPSM::ExplicitAggregate and attribute.rank == 1 and attribute.dimensions[0].aggrtype != 'LIST' and attribute.dimensions[0].aggrtype != 'ARRAY')
|
919
|
+
if attribute.isOptional == false
|
920
|
+
min_cardinality = attribute.dimensions[0].lower.to_i
|
921
|
+
end
|
922
|
+
if attribute.dimensions[0].upper == '?'
|
923
|
+
max_cardinality = -1
|
924
|
+
else
|
925
|
+
max_cardinality = attribute.dimensions[0].upper.to_i
|
926
|
+
end
|
927
|
+
if attribute.rank > 1
|
928
|
+
puts 'WARNING: ' + owl_property_name + ' n-dimensional aggregate attribute cardinalities not mapped '
|
929
|
+
max_cardinality = -1
|
930
|
+
end
|
931
|
+
end
|
932
|
+
|
933
|
+
if min_cardinality == max_cardinality
|
934
|
+
res = ERB.new(cardinality_template)
|
935
|
+
t = res.result(binding)
|
936
|
+
file.puts t
|
937
|
+
else
|
938
|
+
res = ERB.new(min_cardinality_template)
|
939
|
+
t = res.result(binding)
|
940
|
+
file.puts t
|
941
|
+
if max_cardinality != -1
|
942
|
+
res = ERB.new(max_cardinality_template)
|
943
|
+
t = res.result(binding)
|
944
|
+
file.puts t
|
945
|
+
end
|
946
|
+
end
|
947
|
+
|
948
|
+
|
949
|
+
if (attribute.redeclare_entity and !(express_attribute_domain.kind_of? EXPSM::Entity or express_attribute_domain.kind_of? EXPSM::TypeSelect))
|
950
|
+
if (attribute.redeclare_entity and !(express_attribute_domain.kind_of? EXPSM::Type and NamedType.find_by_name( express_attribute_domain.domain ).kind_of? EXPSM::TypeSelect))
|
951
|
+
if (attribute.redeclare_entity and !attribute.isBuiltin)
|
952
|
+
puts 'WARNING: ' + entity.name + ' ' + attribute.name + ' Attribute redeclaration may need hand editing'
|
953
|
+
end
|
954
|
+
end
|
955
|
+
end
|
956
|
+
|
957
|
+
end
|
958
|
+
|
959
|
+
end
|
960
|
+
|
961
|
+
|
962
|
+
res = ERB.new(schema_end_template)
|
963
|
+
t = res.result(binding)
|
964
|
+
file.puts t
|
965
|
+
|
966
|
+
puts ' '
|
967
|
+
puts 'Schema Mapping Summary for : ' + schema.name
|
968
|
+
all_type_list = schema.contents.find_all{ |e| e.kind_of? EXPSM::DefinedType }
|
969
|
+
|
970
|
+
|
971
|
+
puts ' ENTITYs mapped = ' + entity_mapped_list.size.to_s + ' of ' + entity_list.size.to_s
|
972
|
+
puts ' - ' + superexpression_mapped_list.size.to_s + ' of ' + all_superexpression_list.size.to_s + ' ENTITY SUPERTYPE expressions mapped (only simple ONEOF supported)'
|
973
|
+
for t in all_superexpression_list - superexpression_mapped_list
|
974
|
+
puts ' Not mapped: ' + t.name
|
975
|
+
end
|
976
|
+
puts ' - ' + inverse_mapped_list.size.to_s + ' of ' + all_inverse_list.size.to_s + ' inverse attributes mapped (inverse of inherited not supported)'
|
977
|
+
notmapped_list = all_inverse_list - inverse_mapped_list
|
978
|
+
for t in notmapped_list
|
979
|
+
puts ' Not mapped: ' + t.entity.name + '.' + t.name
|
980
|
+
end
|
981
|
+
puts ' - ' + thing_attr_mapped_list.size.to_s + ' of ' + all_explicit_list.size.to_s + ' explicit attributes mapped with owl:Thing as domain (configurable)'
|
982
|
+
puts ' - ' + explicit_mapped_list.size.to_s + ' of ' + all_explicit_list.size.to_s + ' explicit attributes mapped'
|
983
|
+
for t in list_mapped_attr_list
|
984
|
+
puts ' rdf:List mapped: ' + t.name
|
985
|
+
end
|
986
|
+
|
987
|
+
notmapped_list = all_explicit_list - explicit_mapped_list - thing_attr_mapped_list
|
988
|
+
for t in notmapped_list
|
989
|
+
puts ' Not mapped: ' + t.entity.name + '.' + t.name
|
990
|
+
end
|
991
|
+
puts ' - ' + all_derived_list.size.to_s + ' derived attributes not mapped, not supported'
|
992
|
+
puts ' TYPEs mapped = ' + type_mapped_list.size.to_s + ' of ' + all_type_list.size.to_s
|
993
|
+
for t in list_mapped_type_list
|
994
|
+
puts ' rdf:List mapped: ' + t.name
|
995
|
+
end
|
996
|
+
for t in mixed_select_list
|
997
|
+
puts ' Select of entity & type Class mapped: ' + t.name
|
998
|
+
end
|
999
|
+
for t in type_union_mapped_list
|
1000
|
+
puts ' Select RDFS Datatype owl:unionOf mapped: ' + t.name
|
1001
|
+
end
|
1002
|
+
notmapped_list = all_type_list - type_mapped_list
|
1003
|
+
for t in notmapped_list
|
1004
|
+
puts ' Not mapped: ' + t.name
|
1005
|
+
end
|
1006
|
+
puts ' '
|
1007
|
+
puts 'Wrote post-processed schema to file: ' + post_processed_schema_file_name if post_processed_schema
|
1008
|
+
|
1009
|
+
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
res = ERB.new(overall_end_template)
|
1013
|
+
t = res.result(binding)
|
1014
|
+
file.puts t
|
1015
|
+
|
1016
|
+
post_processed_schema_file.close if post_processed_schema
|
1017
|
+
|
1018
|
+
end
|