Class: ActiveFacts::Metamodel::FactType
- Inherits:
-
Object
- Object
- ActiveFacts::Metamodel::FactType
show all
- Defined in:
- lib/activefacts/vocabulary/metamodel.rb,
lib/activefacts/vocabulary/extensions.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#check_and_add_spanning_uniqueness_constraint ⇒ Object
Returns the value of attribute check_and_add_spanning_uniqueness_constraint.
192
193
194
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 192
def check_and_add_spanning_uniqueness_constraint
@check_and_add_spanning_uniqueness_constraint
end
|
Instance Method Details
#all_reading_by_ordinal ⇒ Object
194
195
196
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 194
def all_reading_by_ordinal
all_reading.sort_by{|reading| reading.ordinal}
end
|
#all_role_in_order ⇒ Object
260
261
262
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 260
def all_role_in_order
all_role.sort_by{|r| r.ordinal}
end
|
#compatible_readings(types_array) ⇒ Object
264
265
266
267
268
269
270
271
272
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 264
def compatible_readings types_array
all_reading.select do |reading|
ok = true
reading.role_sequence.all_role_ref_in_order.each_with_index do |rr, i|
ok = false unless types_array[i].include?(rr.role.object_type)
end
ok
end
end
|
#create_implicit_fact_type_for_unary ⇒ Object
This entity type has just objectified a fact type. Create the necessary ImplicitFactTypes with phantom roles
241
242
243
244
245
246
247
248
249
250
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 241
def create_implicit_fact_type_for_unary
role = all_role.single
return if role.link_fact_type link_fact_type = @constellation.LinkFactType(:new, :implying_role => role)
link_fact_type.concept.implication_rule = 'unary'
entity_type = @entity_type || implicit_boolean_type(role.object_type.vocabulary)
phantom_role = @constellation.Role(link_fact_type, 0, :object_type => entity_type, :concept => :new)
end
|
#default_reading(frequency_constraints = [], define_role_names = nil) ⇒ Object
209
210
211
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 209
def default_reading(frequency_constraints = [], define_role_names = nil)
preferred_reading.expand(frequency_constraints, define_role_names)
end
|
#describe(highlight = nil) ⇒ Object
204
205
206
207
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 204
def describe(highlight = nil)
(entity_type ? entity_type.name : "")+
'('+all_role.map{|role| role.describe(highlight) }*", "+')'
end
|
#implicit_boolean_type(vocabulary) ⇒ Object
235
236
237
238
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 235
def implicit_boolean_type vocabulary
@constellation.ImplicitBooleanValueType[[vocabulary.identifying_role_values, "_ImplicitBooleanValueType"]] or
@constellation.ImplicitBooleanValueType(vocabulary.identifying_role_values, "_ImplicitBooleanValueType", :concept => [:new, :implication_rule => 'unary'])
end
|
#internal_presence_constraints ⇒ Object
225
226
227
228
229
230
231
232
233
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 225
def internal_presence_constraints
all_role.map do |r|
r.all_role_ref.map do |rr|
!rr.role_sequence.all_role_ref.detect{|rr1| rr1.role.fact_type != self } ?
rr.role_sequence.all_presence_constraint.to_a :
[]
end
end.flatten.compact.uniq
end
|
#is_existential ⇒ Object
Does any role of this fact type participate in a preferred identifier?
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 214
def is_existential
return false if all_role.size > 2
all_role.detect do |role|
role.all_role_ref.detect do |rr|
rr.role_sequence.all_presence_constraint.detect do |pc|
pc.is_preferred_identifier
end
end
end
end
|
#preferred_reading(negated = false) ⇒ Object
198
199
200
201
202
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 198
def preferred_reading negated = false
pr = all_reading_by_ordinal.detect{|r| !r.is_negative == !negated }
raise "No reading for (#{all_role.map{|r| r.object_type.name}*", "})" unless pr || negated
pr
end
|
#reading_preferably_starting_with_role(role, negated = false) ⇒ Object
252
253
254
255
256
257
258
|
# File 'lib/activefacts/vocabulary/extensions.rb', line 252
def reading_preferably_starting_with_role role, negated = false
all_reading_by_ordinal.detect do |reading|
reading.text =~ /\{\d\}/ and
reading.role_sequence.all_role_ref_in_order[$1.to_i].role == role and
reading.is_negative == !!negated
end || preferred_reading(negated)
end
|