activefacts-generators 1.8.3 → 1.9.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.
@@ -14,22 +14,22 @@ module ActiveFacts
14
14
  class HELP
15
15
  private
16
16
  def initialize(vocabulary, *options)
17
- generators = $:.
18
- map{|path|
17
+ generators = $:.
18
+ map{|path|
19
19
  Dir[path+"/activefacts/generators/**/*.rb"].
20
- reject{|p|
21
- p =~ %r{/(transform|helpers)/}
22
- }.
23
- map{|p|
20
+ reject{|p|
21
+ p =~ %r{/(transform|helpers)/}
22
+ }.
23
+ map{|p|
24
24
  p.sub(%r{.*/activefacts/generators/}, '').sub(/\.rb/,'')
25
25
  }
26
26
  }
27
- transformers = $:.
28
- map{|path|
27
+ transformers = $:.
28
+ map{|path|
29
29
  Dir[path+"/activefacts/generators/transform/**/*.rb"].
30
- map{|p|
30
+ map{|p|
31
31
  p.sub(%r{.*/activefacts/generators/}, '').sub(/\.rb/,'')
32
- }
32
+ }
33
33
  }
34
34
 
35
35
  puts %Q{
@@ -5,11 +5,11 @@ module ActiveFacts
5
5
  def self.included other
6
6
  overlap = Metamodel.constants & other.constants
7
7
  overlap.each do |const|
8
- mix_into = Metamodel.const_get(const)
9
- mix_in = other.const_get(const)
10
- mix_into.instance_exec {
11
- include(mix_in)
12
- }
8
+ mix_into = Metamodel.const_get(const)
9
+ mix_in = other.const_get(const)
10
+ mix_into.instance_exec {
11
+ include(mix_in)
12
+ }
13
13
  end
14
14
  end
15
15
  end
@@ -47,7 +47,7 @@ module ActiveFacts
47
47
  !role.fact_type.is_a?(ActiveFacts::Metamodel::LinkFactType)
48
48
  }.
49
49
  sort_by{|role|
50
- other_role = role.fact_type.all_role.select{|r2| r2 != role}[0] || role
50
+ other_role = role.fact_type.all_role.select{|r2| r2 != role}[0] || role
51
51
  other_role.preferred_role_name(o) + ':' + role.preferred_role_name(other_role.object_type)
52
52
  }.each{|role|
53
53
  role_dump(role)
@@ -59,7 +59,7 @@ module ActiveFacts
59
59
  if fact_type.all_role.size == 1
60
60
  unary_dump(role, role.preferred_role_name)
61
61
  return
62
- end
62
+ end
63
63
  return if role.fact_type.entity_type
64
64
 
65
65
  if fact_type.all_role.size != 2
@@ -91,8 +91,8 @@ module ActiveFacts
91
91
  other_role_method = one_to_one ? role_method : "all_"+role_method
92
92
  # puts "---"+role.role_name if role.role_name
93
93
  if other_role_name != other_player.oo_default_role_name and
94
- role_method == role.object_type.oo_default_role_name
95
- # debugger
94
+ role_method == role.object_type.oo_default_role_name
95
+ # debugger
96
96
  other_role_method += "_as_#{other_role_name}"
97
97
  end
98
98
 
@@ -119,7 +119,7 @@ puts b
119
119
  role_name = role.preferred_role_name(fact_type.entity_type)
120
120
  one_to_one = role.is_unique
121
121
  as = role_name != role.object_type.oo_default_role_name ? "_as_#{role_name}" : ""
122
- # debugger if as != ''
122
+ # debugger if as != ''
123
123
  raise "Fact #{fact_type.describe} type is not objectified" unless fact_type.entity_type
124
124
  other_role_method = (one_to_one ? "" : "all_") +
125
125
  fact_type.entity_type.oo_default_role_name +
@@ -71,24 +71,24 @@ module ActiveFacts
71
71
  end
72
72
 
73
73
  def value_type_fork(o)
74
- if o.name == "_ImplicitBooleanValueType"
75
- # do nothing
76
- elsif
77
- !o.supertype # No supertype, i.e. a base type
78
- o.all_role.size == 0 && # No roles
79
- !o.is_independent && # not independent
80
- !o.value_constraint && # No value constraints
81
- o.concept.all_context_note_as_relevant_concept.size == 0 && # No context notes
82
- o.all_instance.size == 0 # No instances
83
- data_type_dump(o)
84
- else
85
- super_type_name = o.supertype ? o.supertype.name : o.name
86
- length = (l = o.length) && l > 0 ? "#{l}" : nil
87
- scale = (s = o.scale) && s > 0 ? "#{s}" : nil
88
- facets = { :length => length, :scale => scale }
89
- value_type_dump(o, super_type_name, facets)
90
- end
91
- end
74
+ if o.name == "_ImplicitBooleanValueType"
75
+ # do nothing
76
+ elsif
77
+ !o.supertype # No supertype, i.e. a base type
78
+ o.all_role.size == 0 && # No roles
79
+ !o.is_independent && # not independent
80
+ !o.value_constraint && # No value constraints
81
+ o.concept.all_context_note_as_relevant_concept.size == 0 && # No context notes
82
+ o.all_instance.size == 0 # No instances
83
+ data_type_dump(o)
84
+ else
85
+ super_type_name = o.supertype ? o.supertype.name : o.name
86
+ length = (l = o.length) && l > 0 ? "#{l}" : nil
87
+ scale = (s = o.scale) && s > 0 ? "#{s}" : nil
88
+ facets = { :length => length, :scale => scale }
89
+ value_type_dump(o, super_type_name, facets)
90
+ end
91
+ end
92
92
 
93
93
  def value_types_dump
94
94
  done_banner = false
@@ -100,7 +100,7 @@ module ActiveFacts
100
100
 
101
101
  value_type_chain_dump(o)
102
102
  # @object_types_dumped[o] = true
103
- o.ordered_dumped!
103
+ o.ordered_dumped!
104
104
  }
105
105
  value_type_end if done_banner
106
106
  end
@@ -129,18 +129,18 @@ module ActiveFacts
129
129
  count_this_pass = 0
130
130
  skipped_this_pass = 0
131
131
  sorted.each{|o|
132
- next if o.ordered_dumped # Already done
132
+ next if o.ordered_dumped # Already done
133
133
 
134
- trace :ordered, "Panicing to dump #{panic.name}" if panic
134
+ trace :ordered, "Panicing to dump #{panic.name}" if panic
135
135
  # Can we do this yet?
136
- remaining_precursors = Array(@precursors[o])-[o]
136
+ remaining_precursors = Array(@precursors[o])-[o]
137
137
  if (o != panic and # We don't *have* to do it (panic mode)
138
138
  remaining_precursors.size > 0) # precursors - still blocked
139
- trace :ordered, "Can't dump #{o.name} despite panic for #{panic.name}, it still needs #{remaining_precursors.map(&:name)*', '}" if panic
139
+ trace :ordered, "Can't dump #{o.name} despite panic for #{panic.name}, it still needs #{remaining_precursors.map(&:name)*', '}" if panic
140
140
  skipped_this_pass += 1
141
141
  next
142
142
  end
143
- trace :ordered, "Dumping #{o.name} in panic mode, even though it still needs #{remaining_precursors.map(&:name)*', '}" if panic
143
+ trace :ordered, "Dumping #{o.name} in panic mode, even though it still needs #{remaining_precursors.map(&:name)*', '}" if panic
144
144
 
145
145
  entity_type_banner unless done_banner
146
146
  done_banner = true
@@ -168,24 +168,24 @@ module ActiveFacts
168
168
  =begin
169
169
  if panic # We were already panicing... what to do now?
170
170
  # This won't happen again unless the above code is changed to decide it can't dump "panic".
171
- bad = sorted.select do |o|
172
- o.is_a?(ActiveFacts::Metamodel::EntityType) &&
173
- !o.ordered_dumped &&
174
- (Array(@precursors[o])-[o]).size > 0 &&
175
- (Array(@followers[o])-[o]).size > 0
176
- end
171
+ bad = sorted.select do |o|
172
+ o.is_a?(ActiveFacts::Metamodel::EntityType) &&
173
+ !o.ordered_dumped &&
174
+ (Array(@precursors[o])-[o]).size > 0 &&
175
+ (Array(@followers[o])-[o]).size > 0
176
+ end
177
177
 
178
178
  raise "Unresolvable cycle of forward references: " +
179
179
  bad.map { |o| o.name }*', ' +
180
180
  ":\n\t" +
181
- (
182
- bad.map do |o|
183
- o.name +
184
- " depends on " +
185
- (@precursors[o].uniq.map{|p| p.name}.sort*', ')
186
- end
187
- ) * "\n\t" +
188
- "\n"
181
+ (
182
+ bad.map do |o|
183
+ o.name +
184
+ " depends on " +
185
+ (@precursors[o].uniq.map{|p| p.name}.sort*', ')
186
+ end
187
+ ) * "\n\t" +
188
+ "\n"
189
189
  =end
190
190
  # else
191
191
  # Find the object that has the most followers and no fwd-ref'd supertypes:
@@ -211,8 +211,8 @@ module ActiveFacts
211
211
  # which will be attached to the uniqueness constraint on this object in the binary FT that
212
212
  # attaches that identifying role.
213
213
  identifying_role_refs =
214
- (o.fact_type && o.fact_type.all_role.size == 1 ? o.fact_type.preferred_reading : pi).
215
- role_sequence.all_role_ref_in_order
214
+ (o.fact_type && o.fact_type.all_role.size == 1 ? o.fact_type.preferred_reading : pi).
215
+ role_sequence.all_role_ref_in_order
216
216
 
217
217
  # We need to get the adjectives for the roles from the identifying fact's preferred readings:
218
218
  identifying_facts = ([o.fact_type]+identifying_role_refs.map{|rr| rr.role.fact_type }).compact.uniq
@@ -326,7 +326,7 @@ module ActiveFacts
326
326
 
327
327
  # REVISIT: There might be constraints we have to merge into the nested entity or subtype.
328
328
  # These will come up as un-handled constraints:
329
- # Dump this fact type only if it contains a presence constraint we've missed:
329
+ # Dump this fact type only if it contains a presence constraint we've missed:
330
330
  pcs = @presence_constraints_by_fact[f]
331
331
  pcs && pcs.size > 0 && !pcs.detect{|c| !c.ordered_dumped }
332
332
  end
@@ -338,7 +338,7 @@ module ActiveFacts
338
338
  return if skip_fact_type(fact_type)
339
339
 
340
340
  if (et = fact_type.entity_type) &&
341
- fact_type.all_role.size > 1 &&
341
+ fact_type.all_role.size > 1 &&
342
342
  (pi = et.preferred_identifier) &&
343
343
  pi.role_sequence.all_role_ref.detect{|rr| rr.role.fact_type != fact_type }
344
344
  # trace "Dumping objectified FT #{et.name} as an entity, non-fact PI"
@@ -423,11 +423,11 @@ module ActiveFacts
423
423
  def fact_type_key(fact_type)
424
424
  role_names =
425
425
  if (pr = fact_type.preferred_reading)
426
- pr.role_sequence.
427
- all_role_ref.
428
- sort_by{|role_ref| role_ref.ordinal}.
426
+ role_refs = pr.role_sequence.all_role_ref.sort_by{|role_ref| role_ref.ordinal}
427
+ role_refs.
429
428
  map{|role_ref| [ role_ref.leading_adjective, role_ref.role.object_type.name, role_ref.trailing_adjective ].compact*"-" } +
430
- [pr.text]
429
+ [pr.text] +
430
+ role_refs.map{|role_ref| [role_ref.role.is_mandatory ? 0 : 1] }
431
431
  else
432
432
  fact_type.all_role.map{|role| role.object_type.name }
433
433
  end
@@ -490,10 +490,10 @@ module ActiveFacts
490
490
  def constraints_dump
491
491
  heading = false
492
492
  @vocabulary.
493
- all_constraint.
494
- reject{|c| c.ordered_dumped}.
495
- sort_by{ |c| constraint_sort_key(c) }.
496
- each do |c|
493
+ all_constraint.
494
+ reject{|c| c.ordered_dumped}.
495
+ sort_by{ |c| constraint_sort_key(c) }.
496
+ each do |c|
497
497
  # Skip some PresenceConstraints:
498
498
  if c.is_a?(ActiveFacts::Metamodel::PresenceConstraint)
499
499
  # Skip uniqueness constraints that cover all roles of a fact type, they're implicit
@@ -550,7 +550,7 @@ module ActiveFacts
550
550
  trace "Should override data_type_dump"
551
551
  end
552
552
 
553
- def value_type_dump(o, super_type_name, facets)
553
+ def value_type_dump(o, super_type_name, facets)
554
554
  trace "Should override value_type_dump"
555
555
  end
556
556
 
@@ -43,10 +43,10 @@ module ActiveFacts
43
43
  def generate(out = $>)
44
44
  @out = out
45
45
 
46
- @all_object_type =
47
- @vocabulary.
48
- all_object_type.
49
- sort_by{|o| o.name.gsub(/ /,'').downcase}
46
+ @all_object_type =
47
+ @vocabulary.
48
+ all_object_type.
49
+ sort_by{|o| o.name.gsub(/ /,'').downcase}
50
50
 
51
51
  vocabulary_start
52
52
 
@@ -65,133 +65,133 @@ module ActiveFacts
65
65
  # puts "<link rel='stylesheet' href='css/orm2.css' media='screen' type='text/css'/>"
66
66
  css_file = "/../../../../css/orm2.css"
67
67
 
68
- File.open(File.dirname(__FILE__)+css_file) do |f|
69
- puts "<style media='screen' type='text/css'>"
70
- puts f.read
71
- puts %Q{
72
- .glossary-facttype, .glossary-constraints { display: block; }
73
- .glossary-doc.hide-alternates .glossary-alternates { display: none; }
74
- .glossary-doc.hide-constraints .glossary-constraints { display: none; }
75
- .glossary-doc.hide-examples .glossary-example { display: none; }
76
- }.gsub(/^\s+/, '')
77
- puts "</style>"
78
- end
79
-
80
- puts %Q{
81
- <style media='print' type='text/css'>
82
- .keyword { color: #0000CC; font-style: italic; display: inline; }
83
- .vocabulary, .object_type { color: #8A0092; font-weight: bold; }
84
- .copula { color: #0E5400; }
85
- .value { color: #FF990E; display: inline; }
86
- .glossary-toc { display: none; }
87
- .glossary-facttype, .glossary-reading { display: inline; }
88
- </style>
89
- }.gsub(/^\s+/, '')
68
+ File.open(File.dirname(__FILE__)+css_file) do |f|
69
+ puts "<style media='screen' type='text/css'>"
70
+ puts f.read
71
+ puts %Q{
72
+ .glossary-facttype, .glossary-constraints { display: block; }
73
+ .glossary-doc.hide-alternates .glossary-alternates { display: none; }
74
+ .glossary-doc.hide-constraints .glossary-constraints { display: none; }
75
+ .glossary-doc.hide-examples .glossary-example { display: none; }
76
+ }.gsub(/^\s+/, '')
77
+ puts "</style>"
78
+ end
79
+
80
+ puts %Q{
81
+ <style media='print' type='text/css'>
82
+ .keyword { color: #0000CC; font-style: italic; display: inline; }
83
+ .vocabulary, .object_type { color: #8A0092; font-weight: bold; }
84
+ .copula { color: #0E5400; }
85
+ .value { color: #FF990E; display: inline; }
86
+ .glossary-toc { display: none; }
87
+ .glossary-facttype, .glossary-reading { display: inline; }
88
+ </style>
89
+ }.gsub(/^\s+/, '')
90
90
  end
91
91
  end
92
92
 
93
93
  def vocabulary_end
94
94
  if !@gen_bootstrap
95
- puts %Q{
96
- <script type="text/javascript">
97
- function toggle_class(e, c) {
98
- if (!e) return;
99
- var n = e.className;
100
- var i = n.indexOf(c);
101
- if (i == -1) {
102
- e.className = n+' '+c;
103
- } else {
104
- e.className = n.slice(0, i)+n.slice(i+c.length);
105
- }
106
- if (document.location.toString().indexOf('#') >= 0)
107
- document.location = document.location; // Re-scroll to the current fragment
108
- }
109
- function toggle_constraints() {
110
- toggle_class(document.getElementById('glossary-doc'), 'hide-constraints');
111
- }
112
- function toggle_alternates() {
113
- toggle_class(document.getElementById('glossary-doc'), 'hide-alternates');
114
- }
115
- function toggle_examples() {
116
- toggle_class(document.getElementById('glossary-doc'), 'hide-examples');
117
- }
118
- </script>
119
- }.gsub(/^\s+/, '')
95
+ puts %Q{
96
+ <script type="text/javascript">
97
+ function toggle_class(e, c) {
98
+ if (!e) return;
99
+ var n = e.className;
100
+ var i = n.indexOf(c);
101
+ if (i == -1) {
102
+ e.className = n+' '+c;
103
+ } else {
104
+ e.className = n.slice(0, i)+n.slice(i+c.length);
105
+ }
106
+ if (document.location.toString().indexOf('#') >= 0)
107
+ document.location = document.location; // Re-scroll to the current fragment
108
+ }
109
+ function toggle_constraints() {
110
+ toggle_class(document.getElementById('glossary-doc'), 'hide-constraints');
111
+ }
112
+ function toggle_alternates() {
113
+ toggle_class(document.getElementById('glossary-doc'), 'hide-alternates');
114
+ }
115
+ function toggle_examples() {
116
+ toggle_class(document.getElementById('glossary-doc'), 'hide-examples');
117
+ }
118
+ </script>
119
+ }.gsub(/^\s+/, '')
120
120
  end
121
121
  end
122
122
 
123
123
  def object_types_dump_toc
124
- if @gen_bootstrap
124
+ if @gen_bootstrap
125
125
  puts '<div class="col-md-3 glossary-sidebar">'
126
126
  else
127
- puts '<div class="glossary-sidebar">'
127
+ puts '<div class="glossary-sidebar">'
128
128
  end
129
- puts '<h1 style="visibility: hidden">X</h1>'
129
+ puts '<h1 style="visibility: hidden">X</h1>'
130
130
  puts '<ol class="glossary-toc">'
131
- @all_object_type.
132
- reject do |o|
133
- o.name == '_ImplicitBooleanValueType' or
134
- o.kind_of?(ActiveFacts::Metamodel::ValueType) && o.all_role.size == 0 or
135
- o.kind_of?(ActiveFacts::Metamodel::TypeInheritance)
136
- end.
137
- each do |o|
138
- puts "<li>#{termref(o.name)}</li>"
139
- end
131
+ @all_object_type.
132
+ reject do |o|
133
+ o.name == '_ImplicitBooleanValueType' or
134
+ o.kind_of?(ActiveFacts::Metamodel::ValueType) && o.all_role.size == 0 or
135
+ o.kind_of?(ActiveFacts::Metamodel::TypeInheritance)
136
+ end.
137
+ each do |o|
138
+ puts "<li>#{termref(o.name)}</li>"
139
+ end
140
140
  puts '</ol>'
141
- puts '<div class="glossary-controls">'
142
- puts ' <input type="button" onclick="toggle_constraints()" value="Constraints" class="glossary-toggle-constraint">'
143
- puts ' <input type="button" onclick="toggle_alternates()" value="Alternates" class="glossary-toggle-alternates">'
144
- puts ' <input type="button" onclick="toggle_examples()" value="Examples" class="glossary-toggle-examples">'
145
- puts '</div>'
146
- puts '</div>'
141
+ puts '<div class="glossary-controls">'
142
+ puts ' <input type="button" onclick="toggle_constraints()" value="Constraints" class="glossary-toggle-constraint">'
143
+ puts ' <input type="button" onclick="toggle_alternates()" value="Alternates" class="glossary-toggle-alternates">'
144
+ puts ' <input type="button" onclick="toggle_examples()" value="Examples" class="glossary-toggle-examples">'
145
+ puts '</div>'
146
+ puts '</div>'
147
147
  end
148
148
 
149
149
  def object_types_dump_def
150
- if @gen_bootstrap
150
+ if @gen_bootstrap
151
151
  puts '<div class="col-md-5 glossary-doc hide-alternates hide-constraints" id="glossary-doc">'
152
152
  else
153
153
  puts '<div class="glossary-doc hide-alternates hide-constraints" id="glossary-doc">'
154
154
  end
155
- puts "<h1>#{@vocabulary.name}</h1>"
156
- puts '<dl>'
157
- @all_object_type.
158
- each do |o|
159
- case o
160
- when ActiveFacts::Metamodel::TypeInheritance
161
- nil
162
- when ActiveFacts::Metamodel::ValueType
163
- value_type_dump(o)
164
- else
165
- if o.fact_type
166
- objectified_fact_type_dump(o)
167
- else
168
- entity_type_dump(o)
169
- end
170
- end
171
- end
172
- puts '</dl>'
173
- puts '</div>'
174
- end
155
+ puts "<h1>#{@vocabulary.name}</h1>"
156
+ puts '<dl>'
157
+ @all_object_type.
158
+ each do |o|
159
+ case o
160
+ when ActiveFacts::Metamodel::TypeInheritance
161
+ nil
162
+ when ActiveFacts::Metamodel::ValueType
163
+ value_type_dump(o)
164
+ else
165
+ if o.fact_type
166
+ objectified_fact_type_dump(o)
167
+ else
168
+ entity_type_dump(o)
169
+ end
170
+ end
171
+ end
172
+ puts '</dl>'
173
+ puts '</div>'
174
+ end
175
175
 
176
176
  def element(text, attrs, tag = 'span')
177
177
  "<#{tag}#{attrs.empty? ? '' : attrs.map{|k,v| " #{k}='#{v}'"}*''}>#{text}</#{tag}>"
178
178
  end
179
179
 
180
- def span(text, klass = nil)
181
- element(text, klass ? {:class => klass} : {})
182
- end
180
+ def span(text, klass = nil)
181
+ element(text, klass ? {:class => klass} : {})
182
+ end
183
183
 
184
- def div(text, klass = nil)
185
- element(text, klass ? {:class => klass} : {}, 'div')
186
- end
184
+ def div(text, klass = nil)
185
+ element(text, klass ? {:class => klass} : {}, 'div')
186
+ end
187
187
 
188
- def h1(text, klass = nil)
189
- element(text, klass ? {:class => klass} : {}, 'h1')
190
- end
188
+ def h1(text, klass = nil)
189
+ element(text, klass ? {:class => klass} : {}, 'h1')
190
+ end
191
191
 
192
- def dl(text, klass = nil)
193
- element(text, klass ? {:class => klass} : {}, 'dl')
194
- end
192
+ def dl(text, klass = nil)
193
+ element(text, klass ? {:class => klass} : {}, 'dl')
194
+ end
195
195
 
196
196
  # A definition of a term
197
197
  def termdef(name)
@@ -211,54 +211,54 @@ module ActiveFacts
211
211
 
212
212
  def value_type_dump(o)
213
213
  return if o.all_role.size == 0 or # Skip value types that are only used as supertypes
214
- o.name == '_ImplicitBooleanValueType'
214
+ o.name == '_ImplicitBooleanValueType'
215
215
  puts " <dt>" +
216
216
  "#{termdef(o.name)} " +
217
- (if o.supertype
218
- span('is written as ', :keyword) + termref(o.supertype.name)
219
- else
220
- " (a fundamental data type)"
221
- end) +
217
+ (if o.supertype
218
+ span('is written as ', :keyword) + termref(o.supertype.name)
219
+ else
220
+ " (a fundamental data type)"
221
+ end) +
222
222
  "</dt>"
223
223
 
224
224
  puts " <dd>"
225
- value_sub_types(o)
225
+ value_sub_types(o)
226
226
  relevant_facts_and_constraints(o)
227
- values(o)
227
+ values(o)
228
228
  puts " </dd>"
229
229
  end
230
230
 
231
- def value_sub_types(o)
232
- o.
233
- all_value_type_as_supertype. # All value types for which o is a supertype
234
- sort_by{|sub| sub.name}.
235
- each do |sub|
236
- puts div(
237
- "#{termref(sub.name)} #{span('is written as', 'keyword')} #{termref(o.name)}",
238
- 'glossary-facttype'
239
- )
240
- end
241
- end
242
-
243
- def values(o)
244
- o.all_instance.
245
- sort_by{|i|
246
- [i.population.name, i.value.literal]
247
- }.
248
- each do |i|
249
- v = i.value
250
- puts div(
251
- (i.population.name.empty? ? '' : i.population.name+': ') +
252
- termref(o.name) + ' ' +
253
- div(
254
- # v.is_literal_string ? v.literal.inspect : v.literal,
255
- v.literal.inspect,
256
- 'value'
257
- ),
258
- 'glossary-example'
259
- )
260
- end
261
- end
231
+ def value_sub_types(o)
232
+ o.
233
+ all_value_type_as_supertype. # All value types for which o is a supertype
234
+ sort_by{|sub| sub.name}.
235
+ each do |sub|
236
+ puts div(
237
+ "#{termref(sub.name)} #{span('is written as', 'keyword')} #{termref(o.name)}",
238
+ 'glossary-facttype'
239
+ )
240
+ end
241
+ end
242
+
243
+ def values(o)
244
+ o.all_instance.
245
+ sort_by{|i|
246
+ [i.population.name, i.value.literal]
247
+ }.
248
+ each do |i|
249
+ v = i.value
250
+ puts div(
251
+ (i.population.name.empty? ? '' : i.population.name+': ') +
252
+ termref(o.name) + ' ' +
253
+ div(
254
+ # v.is_literal_string ? v.literal.inspect : v.literal,
255
+ v.literal.inspect,
256
+ 'value'
257
+ ),
258
+ 'glossary-example'
259
+ )
260
+ end
261
+ end
262
262
 
263
263
  def relevant_facts_and_constraints(o)
264
264
  puts(
@@ -267,14 +267,14 @@ module ActiveFacts
267
267
  map{|r| r.fact_type}.
268
268
  uniq.
269
269
  reject do |ft|
270
- ft.is_a?(ActiveFacts::Metamodel::LinkFactType)
271
- end.
270
+ ft.is_a?(ActiveFacts::Metamodel::LinkFactType)
271
+ end.
272
272
  map { |ft| [ft, " #{fact_type_with_constraints(ft, o)}"] }.
273
273
  sort_by{|ft, text|
274
- [ ft.is_a?(ActiveFacts::Metamodel::TypeInheritance) ? 0 : 1, text]
275
- }.
276
- map{|ft, text| text}.
277
- join "\n"
274
+ [ ft.is_a?(ActiveFacts::Metamodel::TypeInheritance) ? 0 : 1, text]
275
+ }.
276
+ map{|ft, text| text}.
277
+ join "\n"
278
278
  )
279
279
  end
280
280
 
@@ -291,11 +291,11 @@ module ActiveFacts
291
291
  def expand_reading(reading, include_rolenames = true)
292
292
  element(
293
293
  reading.expand([], include_rolenames) do |rr, freq_con, l_adj, name, t_adj, role_name_def, literal|
294
- if role_name_def
295
- role_name_def = role_name_def.gsub(/\(as ([^)]+)\)/) {
296
- span("(as #{ termref(rr.role.object_type.name, $1) })", 'keyword')
297
- }
298
- end
294
+ if role_name_def
295
+ role_name_def = role_name_def.gsub(/\(as ([^)]+)\)/) {
296
+ span("(as #{ termref(rr.role.object_type.name, $1) })", 'keyword')
297
+ }
298
+ end
299
299
  role_ref rr, freq_con, l_adj, name, t_adj, role_name_def, literal
300
300
  end,
301
301
  {:class => 'copula'}
@@ -303,52 +303,52 @@ module ActiveFacts
303
303
  end
304
304
 
305
305
  def fact_type_block(ft, include_alternates = true, wrt = nil, include_rolenames = true)
306
- div(fact_type(ft, include_alternates, wrt, include_rolenames), 'glossary-facttype')
307
- end
306
+ div(fact_type(ft, include_alternates, wrt, include_rolenames), 'glossary-facttype')
307
+ end
308
308
 
309
309
  def fact_type(ft, include_alternates = true, wrt = nil, include_rolenames = true)
310
310
  role = ft.all_role.detect{|r| r.object_type == wrt}
311
311
  preferred_reading = ft.reading_preferably_starting_with_role(role)
312
312
  alternate_readings = ft.all_reading.reject{|r| r == preferred_reading}
313
313
 
314
- div(
315
- expand_reading(preferred_reading, include_rolenames),
316
- 'glossary-reading'
317
- )+
318
- (if include_alternates and alternate_readings.size > 0
319
- div(
320
- "(alternatively: " +
321
- alternate_readings.map do |reading|
322
- div(
323
- expand_reading(reading, include_rolenames),
324
- 'glossary-reading'
325
- )
326
- end*",\n"+')',
327
- 'glossary-alternates'
328
- )
329
- else
330
- ''
331
- end
332
- )
314
+ div(
315
+ expand_reading(preferred_reading, include_rolenames),
316
+ 'glossary-reading'
317
+ )+
318
+ (if include_alternates and alternate_readings.size > 0
319
+ div(
320
+ "(alternatively: " +
321
+ alternate_readings.map do |reading|
322
+ div(
323
+ expand_reading(reading, include_rolenames),
324
+ 'glossary-reading'
325
+ )
326
+ end*",\n"+')',
327
+ 'glossary-alternates'
328
+ )
329
+ else
330
+ ''
331
+ end
332
+ )
333
333
  end
334
334
 
335
335
  def fact_type_with_constraints(ft, wrt = nil)
336
- if ft.entity_type
337
- div(
338
- termref(ft.entity_type.name) +
339
- div(' is where ', 'keyword') +
340
- fact_type(ft, true, wrt),
341
- 'glossary-objectification'
342
- )
343
- else
344
- fact_type_block(ft, true, wrt)
345
- end +
336
+ if ft.entity_type
337
+ div(
338
+ termref(ft.entity_type.name) +
339
+ div(' is where ', 'keyword') +
340
+ fact_type(ft, true, wrt),
341
+ 'glossary-objectification'
342
+ )
343
+ else
344
+ fact_type_block(ft, true, wrt)
345
+ end +
346
346
  %Q{\n<ul class="glossary-constraints">\n}+
347
- (unless ft.is_a?(ActiveFacts::Metamodel::TypeInheritance)
348
- fact_type_constraints(ft)
349
- else
350
- ''
351
- end) +
347
+ (unless ft.is_a?(ActiveFacts::Metamodel::TypeInheritance)
348
+ fact_type_constraints(ft)
349
+ else
350
+ ''
351
+ end) +
352
352
  "</ul>"
353
353
  end
354
354
 
@@ -360,13 +360,13 @@ module ActiveFacts
360
360
  reading.role_sequence.all_role_ref_in_order[reading.role_numbers[-1]].role == residual_role
361
361
  }
362
362
  next nil unless reading
363
- div(
364
- element(
365
- reading.expand_with_final_presence_constraint { |*a| role_ref(*a) },
366
- {:class => 'copula'}
367
- ),
368
- 'glossary-constraint'
369
- )+"\n"
363
+ div(
364
+ element(
365
+ reading.expand_with_final_presence_constraint { |*a| role_ref(*a) },
366
+ {:class => 'copula'}
367
+ ),
368
+ 'glossary-constraint'
369
+ )+"\n"
370
370
  end.compact*''
371
371
  end
372
372
 
@@ -378,7 +378,7 @@ module ActiveFacts
378
378
  # REVISIT: Handle separate identification
379
379
 
380
380
  puts " <dd>"
381
- puts fact_type_with_constraints(o.fact_type)
381
+ puts fact_type_with_constraints(o.fact_type)
382
382
 
383
383
  o.fact_type.all_role_in_order.each do |r|
384
384
  n = r.object_type.name
@@ -400,59 +400,59 @@ module ActiveFacts
400
400
  [
401
401
  (supers.size > 0 ? "#{span('is a kind of', 'keyword')} #{supers.map{|s| termref(s.name)}*', '}" : nil),
402
402
  (if pi
403
- "#{span('is identified by', 'keyword')} " +
404
- pi.role_sequence.all_role_ref_in_order.map do |rr|
405
- termref(
406
- rr.role.object_type.name,
407
- [ rr.leading_adjective,
408
- rr.role.role_name || rr.role.object_type.name,
409
- rr.trailing_adjective
410
- ].compact*'-'
411
- )
412
- end*", "
413
- else
414
- nil
415
- end)
403
+ "#{span('is identified by', 'keyword')} " +
404
+ pi.role_sequence.all_role_ref_in_order.map do |rr|
405
+ termref(
406
+ rr.role.object_type.name,
407
+ [ rr.leading_adjective,
408
+ rr.role.role_name || rr.role.object_type.name,
409
+ rr.trailing_adjective
410
+ ].compact*'-'
411
+ )
412
+ end*", "
413
+ else
414
+ nil
415
+ end)
416
416
  ].compact*', '
417
417
  "</dt>"
418
418
 
419
419
  puts " <dd>"
420
420
  relevant_facts_and_constraints(o)
421
- entities(o)
421
+ entities(o)
422
422
  puts " </dd>"
423
423
  end
424
424
 
425
- def entities(o)
426
- return if o.preferred_identifier.role_sequence.all_role_ref.size > 1 # REVISIT: Composite identification
427
- o.all_instance.each do |i|
428
- v = i.value
429
- ii = i # The identifying instance
430
-
431
- until v
432
- pi = ii.object_type.preferred_identifier # ii is an Entity Type
433
- break if pi.role_sequence.all_role_ref.size > 1 # REVISIT: Composite identification
434
-
435
- identifying_fact_type = pi.role_sequence.all_role_ref.single.role.fact_type
436
- # Find the role played by this instance through which it is identified:
437
- irv = i.all_role_value.detect{|rv| rv.fact.fact_type == identifying_fact_type }
438
- # Get the other RoleValue in what must be a binary fact type:
439
- orv = irv.fact.all_role_value.detect{|rv| rv != irv}
440
- ii = orv.instance
441
- v = ii.value # Does this instance have a value? If so, we're done.
442
- end
443
-
444
- next unless v
445
- puts div(
446
- (i.population.name.empty? ? '' : i.population.name+': ') +
447
- termref(o.name) + ' ' +
448
- div(
449
- # v.is_literal_string ? v.literal.inspect : v.literal,
450
- v.literal.inspect,
451
- 'value'),
452
- 'glossary-example'
453
- )
454
- end
455
- end
425
+ def entities(o)
426
+ return if o.preferred_identifier.role_sequence.all_role_ref.size > 1 # REVISIT: Composite identification
427
+ o.all_instance.each do |i|
428
+ v = i.value
429
+ ii = i # The identifying instance
430
+
431
+ until v
432
+ pi = ii.object_type.preferred_identifier # ii is an Entity Type
433
+ break if pi.role_sequence.all_role_ref.size > 1 # REVISIT: Composite identification
434
+
435
+ identifying_fact_type = pi.role_sequence.all_role_ref.single.role.fact_type
436
+ # Find the role played by this instance through which it is identified:
437
+ irv = i.all_role_value.detect{|rv| rv.fact.fact_type == identifying_fact_type }
438
+ # Get the other RoleValue in what must be a binary fact type:
439
+ orv = irv.fact.all_role_value.detect{|rv| rv != irv}
440
+ ii = orv.instance
441
+ v = ii.value # Does this instance have a value? If so, we're done.
442
+ end
443
+
444
+ next unless v
445
+ puts div(
446
+ (i.population.name.empty? ? '' : i.population.name+': ') +
447
+ termref(o.name) + ' ' +
448
+ div(
449
+ # v.is_literal_string ? v.literal.inspect : v.literal,
450
+ v.literal.inspect,
451
+ 'value'),
452
+ 'glossary-example'
453
+ )
454
+ end
455
+ end
456
456
 
457
457
  end
458
458
  end