activefacts 1.6.0 → 1.7.1

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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +14 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +60 -0
  8. data/Rakefile +3 -80
  9. data/activefacts.gemspec +36 -0
  10. data/bin/afgen +4 -2
  11. data/bin/cql +5 -1
  12. data/lib/activefacts.rb +3 -12
  13. data/lib/activefacts/{vocabulary/query_evaluator.rb → query/evaluator.rb} +0 -0
  14. data/lib/activefacts/version.rb +2 -2
  15. metadata +48 -296
  16. data/History.txt +0 -4
  17. data/LICENSE +0 -19
  18. data/Manifest.txt +0 -165
  19. data/README.rdoc +0 -81
  20. data/css/offline.css +0 -3
  21. data/css/orm2.css +0 -124
  22. data/css/print.css +0 -8
  23. data/css/style-print.css +0 -357
  24. data/css/style.css +0 -387
  25. data/download.html +0 -110
  26. data/examples/CQL/Address.cql +0 -44
  27. data/examples/CQL/Blog.cql +0 -54
  28. data/examples/CQL/CompanyDirectorEmployee.cql +0 -56
  29. data/examples/CQL/Death.cql +0 -17
  30. data/examples/CQL/Diplomacy.cql +0 -48
  31. data/examples/CQL/Genealogy.cql +0 -98
  32. data/examples/CQL/Insurance.cql +0 -320
  33. data/examples/CQL/Marriage.cql +0 -18
  34. data/examples/CQL/Metamodel.cql +0 -493
  35. data/examples/CQL/Monogamy.cql +0 -24
  36. data/examples/CQL/MultiInheritance.cql +0 -22
  37. data/examples/CQL/NonRoleId.cql +0 -14
  38. data/examples/CQL/OddIdentifier.cql +0 -18
  39. data/examples/CQL/OilSupply.cql +0 -53
  40. data/examples/CQL/OneToOnes.cql +0 -17
  41. data/examples/CQL/Orienteering.cql +0 -111
  42. data/examples/CQL/PersonPlaysGame.cql +0 -18
  43. data/examples/CQL/RedundantDependency.cql +0 -34
  44. data/examples/CQL/SchoolActivities.cql +0 -33
  45. data/examples/CQL/SeparateSubtype.cql +0 -30
  46. data/examples/CQL/ServiceDirector.cql +0 -276
  47. data/examples/CQL/SimplestUnary.cql +0 -12
  48. data/examples/CQL/Supervision.cql +0 -34
  49. data/examples/CQL/WaiterTips.cql +0 -33
  50. data/examples/CQL/Warehousing.cql +0 -101
  51. data/examples/CQL/WindowInRoomInBldg.cql +0 -28
  52. data/examples/CQL/unit.cql +0 -474
  53. data/examples/index.html +0 -420
  54. data/examples/intro.html +0 -327
  55. data/examples/local.css +0 -24
  56. data/index.html +0 -111
  57. data/lib/activefacts/cql.rb +0 -35
  58. data/lib/activefacts/cql/CQLParser.treetop +0 -158
  59. data/lib/activefacts/cql/Context.treetop +0 -48
  60. data/lib/activefacts/cql/Expressions.treetop +0 -67
  61. data/lib/activefacts/cql/FactTypes.treetop +0 -358
  62. data/lib/activefacts/cql/Language/English.treetop +0 -315
  63. data/lib/activefacts/cql/LexicalRules.treetop +0 -253
  64. data/lib/activefacts/cql/ObjectTypes.treetop +0 -210
  65. data/lib/activefacts/cql/Rakefile +0 -14
  66. data/lib/activefacts/cql/Terms.treetop +0 -183
  67. data/lib/activefacts/cql/ValueTypes.treetop +0 -202
  68. data/lib/activefacts/cql/compiler.rb +0 -156
  69. data/lib/activefacts/cql/compiler/clause.rb +0 -1137
  70. data/lib/activefacts/cql/compiler/constraint.rb +0 -581
  71. data/lib/activefacts/cql/compiler/entity_type.rb +0 -457
  72. data/lib/activefacts/cql/compiler/expression.rb +0 -443
  73. data/lib/activefacts/cql/compiler/fact.rb +0 -390
  74. data/lib/activefacts/cql/compiler/fact_type.rb +0 -421
  75. data/lib/activefacts/cql/compiler/query.rb +0 -106
  76. data/lib/activefacts/cql/compiler/shared.rb +0 -161
  77. data/lib/activefacts/cql/compiler/value_type.rb +0 -174
  78. data/lib/activefacts/cql/nodes.rb +0 -49
  79. data/lib/activefacts/cql/parser.rb +0 -241
  80. data/lib/activefacts/dependency_analyser.rb +0 -182
  81. data/lib/activefacts/generate/absorption.rb +0 -70
  82. data/lib/activefacts/generate/composition.rb +0 -118
  83. data/lib/activefacts/generate/cql.rb +0 -714
  84. data/lib/activefacts/generate/dm.rb +0 -279
  85. data/lib/activefacts/generate/help.rb +0 -64
  86. data/lib/activefacts/generate/helpers/inject.rb +0 -16
  87. data/lib/activefacts/generate/helpers/oo.rb +0 -162
  88. data/lib/activefacts/generate/helpers/ordered.rb +0 -605
  89. data/lib/activefacts/generate/helpers/rails.rb +0 -57
  90. data/lib/activefacts/generate/html/glossary.rb +0 -461
  91. data/lib/activefacts/generate/json.rb +0 -337
  92. data/lib/activefacts/generate/null.rb +0 -32
  93. data/lib/activefacts/generate/rails/models.rb +0 -246
  94. data/lib/activefacts/generate/rails/schema.rb +0 -216
  95. data/lib/activefacts/generate/records.rb +0 -46
  96. data/lib/activefacts/generate/ruby.rb +0 -133
  97. data/lib/activefacts/generate/sql/mysql.rb +0 -280
  98. data/lib/activefacts/generate/sql/server.rb +0 -273
  99. data/lib/activefacts/generate/stats.rb +0 -69
  100. data/lib/activefacts/generate/text.rb +0 -27
  101. data/lib/activefacts/generate/topics.rb +0 -265
  102. data/lib/activefacts/generate/traits/datavault.rb +0 -241
  103. data/lib/activefacts/generate/traits/oo.rb +0 -73
  104. data/lib/activefacts/generate/traits/ordered.rb +0 -33
  105. data/lib/activefacts/generate/traits/ruby.rb +0 -210
  106. data/lib/activefacts/generate/transform/datavault.rb +0 -266
  107. data/lib/activefacts/generate/transform/surrogate.rb +0 -214
  108. data/lib/activefacts/generate/version.rb +0 -26
  109. data/lib/activefacts/input/cql.rb +0 -43
  110. data/lib/activefacts/input/orm.rb +0 -1636
  111. data/lib/activefacts/mapping/rails.rb +0 -132
  112. data/lib/activefacts/persistence.rb +0 -15
  113. data/lib/activefacts/persistence/columns.rb +0 -446
  114. data/lib/activefacts/persistence/foreignkey.rb +0 -187
  115. data/lib/activefacts/persistence/index.rb +0 -240
  116. data/lib/activefacts/persistence/object_type.rb +0 -198
  117. data/lib/activefacts/persistence/reference.rb +0 -434
  118. data/lib/activefacts/persistence/tables.rb +0 -380
  119. data/lib/activefacts/registry.rb +0 -11
  120. data/lib/activefacts/support.rb +0 -132
  121. data/lib/activefacts/vocabulary.rb +0 -9
  122. data/lib/activefacts/vocabulary/extensions.rb +0 -1348
  123. data/lib/activefacts/vocabulary/metamodel.rb +0 -570
  124. data/lib/activefacts/vocabulary/verbaliser.rb +0 -804
  125. data/script/txt2html +0 -71
  126. data/spec/absorption_spec.rb +0 -95
  127. data/spec/cql/comparison_spec.rb +0 -89
  128. data/spec/cql/context_spec.rb +0 -94
  129. data/spec/cql/contractions_spec.rb +0 -224
  130. data/spec/cql/deontic_spec.rb +0 -88
  131. data/spec/cql/entity_type_spec.rb +0 -320
  132. data/spec/cql/expressions_spec.rb +0 -66
  133. data/spec/cql/fact_type_matching_spec.rb +0 -338
  134. data/spec/cql/french_spec.rb +0 -21
  135. data/spec/cql/parser/bad_literals_spec.rb +0 -86
  136. data/spec/cql/parser/constraints_spec.rb +0 -19
  137. data/spec/cql/parser/entity_types_spec.rb +0 -106
  138. data/spec/cql/parser/expressions_spec.rb +0 -199
  139. data/spec/cql/parser/fact_types_spec.rb +0 -44
  140. data/spec/cql/parser/literals_spec.rb +0 -312
  141. data/spec/cql/parser/pragmas_spec.rb +0 -89
  142. data/spec/cql/parser/value_types_spec.rb +0 -42
  143. data/spec/cql/role_matching_spec.rb +0 -148
  144. data/spec/cql/samples_spec.rb +0 -244
  145. data/spec/cql_cql_spec.rb +0 -73
  146. data/spec/cql_dm_spec.rb +0 -136
  147. data/spec/cql_mysql_spec.rb +0 -69
  148. data/spec/cql_parse_spec.rb +0 -34
  149. data/spec/cql_ruby_spec.rb +0 -73
  150. data/spec/cql_sql_spec.rb +0 -72
  151. data/spec/cql_symbol_tables_spec.rb +0 -261
  152. data/spec/cqldump_spec.rb +0 -170
  153. data/spec/helpers/array_matcher.rb +0 -23
  154. data/spec/helpers/ctrl_c_support.rb +0 -52
  155. data/spec/helpers/diff_matcher.rb +0 -39
  156. data/spec/helpers/file_matcher.rb +0 -34
  157. data/spec/helpers/parse_to_ast_matcher.rb +0 -80
  158. data/spec/helpers/string_matcher.rb +0 -30
  159. data/spec/helpers/test_parser.rb +0 -15
  160. data/spec/norma_cql_spec.rb +0 -66
  161. data/spec/norma_ruby_spec.rb +0 -62
  162. data/spec/norma_ruby_sql_spec.rb +0 -107
  163. data/spec/norma_sql_spec.rb +0 -57
  164. data/spec/norma_tables_spec.rb +0 -95
  165. data/spec/ruby_api_spec.rb +0 -23
  166. data/spec/spec_helper.rb +0 -35
  167. data/spec/transform_surrogate_spec.rb +0 -59
  168. data/status.html +0 -138
  169. data/why.html +0 -60
@@ -1,57 +0,0 @@
1
- module ActiveFacts
2
- module Generate
3
- module Rails
4
- module Helpers
5
- def rails_plural_name name
6
- # Crunch spaces and pluralise the first part, all in snake_case
7
- name.pop if name.is_a?(Array) and name.last == []
8
- name = name[0]*'_' if name.is_a?(Array) and name.size == 1
9
- if name.is_a?(Array)
10
- name = ActiveSupport::Inflector.tableize((name[0]*'_').gsub(/\s+/, '_')) +
11
- '_' +
12
- ActiveSupport::Inflector.underscore((name[1..-1].flatten*'_').gsub(/\s+/, '_'))
13
- else
14
- ActiveSupport::Inflector.tableize(name.gsub(/\s+/, '_'))
15
- end
16
- end
17
-
18
- def rails_singular_name name
19
- # Crunch spaces and convert to snake_case
20
- name = name.flatten*'_' if name.is_a?(Array)
21
- ActiveSupport::Inflector.underscore(name.gsub(/\s+/, '_'))
22
- end
23
-
24
- def rails_class_name name
25
- name = name*'_' if name.is_a?(Array)
26
- ActiveSupport::Inflector.camelize(name.gsub(/\s+/, '_'))
27
- end
28
-
29
- end
30
- end
31
- end
32
-
33
- module Metamodel
34
- class ObjectType
35
- end
36
- end
37
-
38
- module Persistence
39
- class ForeignKey
40
- include Generate::Rails::Helpers
41
-
42
- def rails_from_association_name
43
- rails_singular_name(to_name.join('_'))
44
- end
45
-
46
- def rails_to_association
47
- jump = jump_reference
48
- if jump.is_one_to_one
49
- [ "has_one", rails_singular_name(from_name)]
50
- else
51
- [ "has_many", rails_plural_name(from_name)]
52
- end
53
- end
54
-
55
- end
56
- end
57
- end
@@ -1,461 +0,0 @@
1
- #
2
- # ActiveFacts Generators.
3
- #
4
- # Generate a glossary in HTML
5
- #
6
- # Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
7
- #
8
- require 'activefacts/api'
9
-
10
- module ActiveFacts
11
- module Generate #:nodoc:
12
- class HTML #:nodoc:
13
- class GLOSSARY #:nodoc:
14
- # Base class for generators of object-oriented class libraries for an ActiveFacts vocabulary.
15
- def initialize(vocabulary, *options)
16
- @vocabulary = vocabulary
17
- @vocabulary = @vocabulary.Vocabulary.values[0] if ActiveFacts::API::Constellation === @vocabulary
18
- options.each{|option| set_option(option) }
19
- end
20
-
21
- def set_option(option)
22
- @gen_bootstrap = false
23
- case option
24
- when 'help', '?'
25
- $stderr.puts "Usage:\t\tafgen --html/glossary[=option] input_file.cql\n"+
26
- "\t\tbootstrap\tGenerate bootstrap styled glossary html"
27
- exit 0
28
- when /bootstrap/
29
- @gen_bootstrap = true
30
- else super
31
- end
32
- end
33
-
34
- def puts(*a)
35
- @out.puts *a
36
- end
37
-
38
- def print(*a)
39
- @out.print *a
40
- end
41
-
42
- def generate(out = $>)
43
- @out = out
44
-
45
- @all_object_type =
46
- @vocabulary.
47
- all_object_type.
48
- sort_by{|o| o.name.gsub(/ /,'').downcase}
49
-
50
- vocabulary_start
51
-
52
- if @gen_bootstrap
53
- object_types_dump_toc()
54
- object_types_dump_def()
55
- else
56
- object_types_dump_def()
57
- object_types_dump_toc()
58
- end
59
- vocabulary_end
60
- end
61
-
62
- def vocabulary_start
63
- if !@gen_bootstrap
64
- # puts "<link rel='stylesheet' href='css/orm2.css' media='screen' type='text/css'/>"
65
- css_file = "/../../../../css/orm2.css"
66
-
67
- File.open(File.dirname(__FILE__)+css_file) do |f|
68
- puts "<style media='screen' type='text/css'>"
69
- puts f.read
70
- puts %Q{
71
- .glossary-facttype, .glossary-constraints { display: block; }
72
- .glossary-doc.hide-alternates .glossary-alternates { display: none; }
73
- .glossary-doc.hide-constraints .glossary-constraints { display: none; }
74
- .glossary-doc.hide-examples .glossary-example { display: none; }
75
- }.gsub(/^\s+/, '')
76
- puts "</style>"
77
- end
78
-
79
- puts %Q{
80
- <style media='print' type='text/css'>
81
- .keyword { color: #0000CC; font-style: italic; display: inline; }
82
- .vocabulary, .object_type { color: #8A0092; font-weight: bold; }
83
- .copula { color: #0E5400; }
84
- .value { color: #FF990E; display: inline; }
85
- .glossary-toc { display: none; }
86
- .glossary-facttype, .glossary-reading { display: inline; }
87
- </style>
88
- }.gsub(/^\s+/, '')
89
- end
90
- end
91
-
92
- def vocabulary_end
93
- if !@gen_bootstrap
94
- puts %Q{
95
- <script type="text/javascript">
96
- function toggle_class(e, c) {
97
- if (!e) return;
98
- var n = e.className;
99
- var i = n.indexOf(c);
100
- if (i == -1) {
101
- e.className = n+' '+c;
102
- } else {
103
- e.className = n.slice(0, i)+n.slice(i+c.length);
104
- }
105
- if (document.location.toString().indexOf('#') >= 0)
106
- document.location = document.location; // Re-scroll to the current fragment
107
- }
108
- function toggle_constraints() {
109
- toggle_class(document.getElementById('glossary-doc'), 'hide-constraints');
110
- }
111
- function toggle_alternates() {
112
- toggle_class(document.getElementById('glossary-doc'), 'hide-alternates');
113
- }
114
- function toggle_examples() {
115
- toggle_class(document.getElementById('glossary-doc'), 'hide-examples');
116
- }
117
- </script>
118
- }.gsub(/^\s+/, '')
119
- end
120
- end
121
-
122
- def object_types_dump_toc
123
- if @gen_bootstrap
124
- puts '<div class="col-md-3 glossary-sidebar">'
125
- else
126
- puts '<div class="glossary-sidebar">'
127
- end
128
- puts '<h1 style="visibility: hidden">X</h1>'
129
- puts '<ol class="glossary-toc">'
130
- @all_object_type.
131
- reject do |o|
132
- o.name == '_ImplicitBooleanValueType' or
133
- o.kind_of?(ActiveFacts::Metamodel::ValueType) && o.all_role.size == 0 or
134
- o.kind_of?(ActiveFacts::Metamodel::TypeInheritance)
135
- end.
136
- each do |o|
137
- puts "<li>#{termref(o.name)}</li>"
138
- end
139
- puts '</ol>'
140
- puts '<div class="glossary-controls">'
141
- puts ' <input type="button" onclick="toggle_constraints()" value="Constraints" class="glossary-toggle-constraint">'
142
- puts ' <input type="button" onclick="toggle_alternates()" value="Alternates" class="glossary-toggle-alternates">'
143
- puts ' <input type="button" onclick="toggle_examples()" value="Examples" class="glossary-toggle-examples">'
144
- puts '</div>'
145
- puts '</div>'
146
- end
147
-
148
- def object_types_dump_def
149
- if @gen_bootstrap
150
- puts '<div class="col-md-5 glossary-doc hide-alternates hide-constraints" id="glossary-doc">'
151
- else
152
- puts '<div class="glossary-doc hide-alternates hide-constraints" id="glossary-doc">'
153
- end
154
- puts "<h1>#{@vocabulary.name}</h1>"
155
- puts '<dl>'
156
- @all_object_type.
157
- each do |o|
158
- case o
159
- when ActiveFacts::Metamodel::TypeInheritance
160
- nil
161
- when ActiveFacts::Metamodel::ValueType
162
- value_type_dump(o)
163
- else
164
- if o.fact_type
165
- objectified_fact_type_dump(o)
166
- else
167
- entity_type_dump(o)
168
- end
169
- end
170
- end
171
- puts '</dl>'
172
- puts '</div>'
173
- end
174
-
175
- def element(text, attrs, tag = 'span')
176
- "<#{tag}#{attrs.empty? ? '' : attrs.map{|k,v| " #{k}='#{v}'"}*''}>#{text}</#{tag}>"
177
- end
178
-
179
- def span(text, klass = nil)
180
- element(text, klass ? {:class => klass} : {})
181
- end
182
-
183
- def div(text, klass = nil)
184
- element(text, klass ? {:class => klass} : {}, 'div')
185
- end
186
-
187
- def h1(text, klass = nil)
188
- element(text, klass ? {:class => klass} : {}, 'h1')
189
- end
190
-
191
- def dl(text, klass = nil)
192
- element(text, klass ? {:class => klass} : {}, 'dl')
193
- end
194
-
195
- # A definition of a term
196
- def termdef(name)
197
- element(name, {:name => name, :class => 'object_type'}, 'a')
198
- end
199
-
200
- # A reference to a defined term (excluding role adjectives)
201
- def termref(name, role_name = nil)
202
- role_name ||= name
203
- element(role_name, {:href=>'#'+name, :class=>:object_type}, 'a')
204
- end
205
-
206
- # Text that should appear as part of a term (including role adjectives)
207
- def term(name)
208
- element(name, :class=>:object_type)
209
- end
210
-
211
- def value_type_dump(o)
212
- return if o.all_role.size == 0 or # Skip value types that are only used as supertypes
213
- o.name == '_ImplicitBooleanValueType'
214
- puts " <dt>" +
215
- "#{termdef(o.name)} " +
216
- (if o.supertype
217
- span('is written as ', :keyword) + termref(o.supertype.name)
218
- else
219
- " (a fundamental data type)"
220
- end) +
221
- "</dt>"
222
-
223
- puts " <dd>"
224
- value_sub_types(o)
225
- relevant_facts_and_constraints(o)
226
- values(o)
227
- puts " </dd>"
228
- end
229
-
230
- def value_sub_types(o)
231
- o.
232
- all_value_type_as_supertype. # All value types for which o is a supertype
233
- sort_by{|sub| sub.name}.
234
- each do |sub|
235
- puts div(
236
- "#{termref(sub.name)} #{span('is written as', 'keyword')} #{termref(o.name)}",
237
- 'glossary-facttype'
238
- )
239
- end
240
- end
241
-
242
- def values(o)
243
- o.all_instance.
244
- sort_by{|i|
245
- [i.population.name, i.value.literal]
246
- }.
247
- each do |i|
248
- v = i.value
249
- puts div(
250
- (i.population.name.empty? ? '' : i.population.name+': ') +
251
- termref(o.name) + ' ' +
252
- div(
253
- # v.is_literal_string ? v.literal.inspect : v.literal,
254
- v.literal.inspect,
255
- 'value'
256
- ),
257
- 'glossary-example'
258
- )
259
- end
260
- end
261
-
262
- def relevant_facts_and_constraints(o)
263
- puts(
264
- o.
265
- all_role.
266
- map{|r| r.fact_type}.
267
- uniq.
268
- reject do |ft|
269
- ft.is_a?(ActiveFacts::Metamodel::LinkFactType)
270
- end.
271
- map { |ft| [ft, " #{fact_type_with_constraints(ft, o)}"] }.
272
- sort_by{|ft, text|
273
- [ ft.is_a?(ActiveFacts::Metamodel::TypeInheritance) ? 0 : 1, text]
274
- }.
275
- map{|ft, text| text}.
276
- join "\n"
277
- )
278
- end
279
-
280
- def role_ref(rr, freq_con, l_adj, name, t_adj, role_name_def, literal)
281
- term_parts = [l_adj, termref(name), t_adj].compact
282
- [
283
- freq_con ? element(freq_con, :class=>:keyword) : nil,
284
- term_parts.size > 1 ? term([l_adj, termref(name), t_adj].compact*' ') : term_parts[0],
285
- role_name_def,
286
- literal
287
- ]
288
- end
289
-
290
- def expand_reading(reading, include_rolenames = true)
291
- element(
292
- reading.expand([], include_rolenames) do |rr, freq_con, l_adj, name, t_adj, role_name_def, literal|
293
- if role_name_def
294
- role_name_def = role_name_def.gsub(/\(as ([^)]+)\)/) {
295
- span("(as #{ termref(rr.role.object_type.name, $1) })", 'keyword')
296
- }
297
- end
298
- role_ref rr, freq_con, l_adj, name, t_adj, role_name_def, literal
299
- end,
300
- {:class => 'copula'}
301
- )
302
- end
303
-
304
- def fact_type_block(ft, include_alternates = true, wrt = nil, include_rolenames = true)
305
- div(fact_type(ft, include_alternates, wrt, include_rolenames), 'glossary-facttype')
306
- end
307
-
308
- def fact_type(ft, include_alternates = true, wrt = nil, include_rolenames = true)
309
- role = ft.all_role.detect{|r| r.object_type == wrt}
310
- preferred_reading = ft.reading_preferably_starting_with_role(role)
311
- alternate_readings = ft.all_reading.reject{|r| r == preferred_reading}
312
-
313
- div(
314
- expand_reading(preferred_reading, include_rolenames),
315
- 'glossary-reading'
316
- )+
317
- (if include_alternates and alternate_readings.size > 0
318
- div(
319
- "(alternatively: " +
320
- alternate_readings.map do |reading|
321
- div(
322
- expand_reading(reading, include_rolenames),
323
- 'glossary-reading'
324
- )
325
- end*",\n"+')',
326
- 'glossary-alternates'
327
- )
328
- else
329
- ''
330
- end
331
- )
332
- end
333
-
334
- def fact_type_with_constraints(ft, wrt = nil)
335
- if ft.entity_type
336
- div(
337
- termref(ft.entity_type.name) +
338
- div(' is where ', 'keyword') +
339
- fact_type(ft, true, wrt),
340
- 'glossary-objectification'
341
- )
342
- else
343
- fact_type_block(ft, true, wrt)
344
- end +
345
- %Q{\n<ul class="glossary-constraints">\n}+
346
- (unless ft.is_a?(ActiveFacts::Metamodel::TypeInheritance)
347
- fact_type_constraints(ft)
348
- else
349
- ''
350
- end) +
351
- "</ul>"
352
- end
353
-
354
- def fact_type_constraints(ft)
355
- ft.internal_presence_constraints.map do |pc|
356
- residual_role = ft.all_role.detect{|r| !pc.role_sequence.all_role_ref.detect{|rr| rr.role == r}}
357
- next nil unless residual_role
358
- reading = ft.all_reading.detect{|reading|
359
- reading.role_sequence.all_role_ref_in_order[reading.role_numbers[-1]].role == residual_role
360
- }
361
- next nil unless reading
362
- div(
363
- element(
364
- reading.expand_with_final_presence_constraint { |*a| role_ref(*a) },
365
- {:class => 'copula'}
366
- ),
367
- 'glossary-constraint'
368
- )+"\n"
369
- end.compact*''
370
- end
371
-
372
- def objectified_fact_type_dump(o)
373
- puts " <dt>" +
374
- "#{termdef(o.name)}" +
375
- # " (#{span('in which', 'keyword')} #{fact_type(o.fact_type, false, nil, nil)})" +
376
- "</dt>"
377
- # REVISIT: Handle separate identification
378
-
379
- puts " <dd>"
380
- puts fact_type_with_constraints(o.fact_type)
381
-
382
- o.fact_type.all_role_in_order.each do |r|
383
- n = r.object_type.name
384
- puts div("#{termref(o.name)} involves #{span('one', 'keyword')} #{termref(r.role_name || n, n)}", "glossary-facttype")
385
- end
386
- relevant_facts_and_constraints(o)
387
- puts " </dd>"
388
- end
389
-
390
- def entity_type_dump(o)
391
- pi = o.preferred_identifier
392
- supers = o.supertypes
393
- if (supers.size > 0) # Ignore identification by a supertype:
394
- pi = nil if pi && pi.role_sequence.all_role_ref.detect{|rr| rr.role.fact_type.is_a?(ActiveFacts::Metamodel::TypeInheritance) }
395
- end
396
-
397
- puts " <dt>" +
398
- "#{termdef(o.name)} " +
399
- [
400
- (supers.size > 0 ? "#{span('is a kind of', 'keyword')} #{supers.map{|s| termref(s.name)}*', '}" : nil),
401
- (if pi
402
- "#{span('is identified by', 'keyword')} " +
403
- pi.role_sequence.all_role_ref_in_order.map do |rr|
404
- termref(
405
- rr.role.object_type.name,
406
- [ rr.leading_adjective,
407
- rr.role.role_name || rr.role.object_type.name,
408
- rr.trailing_adjective
409
- ].compact*'-'
410
- )
411
- end*", "
412
- else
413
- nil
414
- end)
415
- ].compact*', '
416
- "</dt>"
417
-
418
- puts " <dd>"
419
- relevant_facts_and_constraints(o)
420
- entities(o)
421
- puts " </dd>"
422
- end
423
-
424
- def entities(o)
425
- return if o.preferred_identifier.role_sequence.all_role_ref.size > 1 # REVISIT: Composite identification
426
- o.all_instance.each do |i|
427
- v = i.value
428
- ii = i # The identifying instance
429
-
430
- until v
431
- pi = ii.object_type.preferred_identifier # ii is an Entity Type
432
- break if pi.role_sequence.all_role_ref.size > 1 # REVISIT: Composite identification
433
-
434
- identifying_fact_type = pi.role_sequence.all_role_ref.single.role.fact_type
435
- # Find the role played by this instance through which it is identified:
436
- irv = i.all_role_value.detect{|rv| rv.fact.fact_type == identifying_fact_type }
437
- # Get the other RoleValue in what must be a binary fact type:
438
- orv = irv.fact.all_role_value.detect{|rv| rv != irv}
439
- ii = orv.instance
440
- v = ii.value # Does this instance have a value? If so, we're done.
441
- end
442
-
443
- next unless v
444
- puts div(
445
- (i.population.name.empty? ? '' : i.population.name+': ') +
446
- termref(o.name) + ' ' +
447
- div(
448
- # v.is_literal_string ? v.literal.inspect : v.literal,
449
- v.literal.inspect,
450
- 'value'),
451
- 'glossary-example'
452
- )
453
- end
454
- end
455
-
456
- end
457
- end
458
- end
459
- end
460
-
461
- ActiveFacts::Registry.generator('html/glossary', ActiveFacts::Generate::HTML::GLOSSARY)