Class: ActiveFacts::Metamodel::FactType

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/vocabulary/metamodel.rb,
lib/activefacts/vocabulary/extensions.rb

Direct Known Subclasses

LinkFactType, TypeInheritance

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#check_and_add_spanning_uniqueness_constraintObject

Returns the value of attribute check_and_add_spanning_uniqueness_constraint.



70
71
72
# File 'lib/activefacts/vocabulary/extensions.rb', line 70

def check_and_add_spanning_uniqueness_constraint
  @check_and_add_spanning_uniqueness_constraint
end

Instance Method Details

#all_reading_by_ordinalObject



72
73
74
# File 'lib/activefacts/vocabulary/extensions.rb', line 72

def all_reading_by_ordinal
  all_reading.sort_by{|reading| reading.ordinal}
end

#all_role_in_orderObject



137
138
139
# File 'lib/activefacts/vocabulary/extensions.rb', line 137

def all_role_in_order
  all_role.sort_by{|r| r.ordinal}
end

#compatible_readings(types_array) ⇒ Object



141
142
143
144
145
146
147
148
149
# File 'lib/activefacts/vocabulary/extensions.rb', line 141

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_unaryObject

This entity type has just objectified a fact type. Create the necessary ImplicitFactTypes with phantom roles



119
120
121
122
123
124
125
126
127
# File 'lib/activefacts/vocabulary/extensions.rb', line 119

def create_implicit_fact_type_for_unary
  role = all_role.single
  return if role.link_fact_type     # Already exists
  # NORMA doesn't create an implicit fact type here, rather the fact type has an implicit extra role, so looks like a binary
  # We only do it when the unary fact type is not objectified
  link_fact_type = @constellation.LinkFactType(:new, :implying_role => role)
  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



87
88
89
# File 'lib/activefacts/vocabulary/extensions.rb', line 87

def default_reading(frequency_constraints = [], define_role_names = nil)
  preferred_reading.expand(frequency_constraints, define_role_names)
end

#describe(highlight = nil) ⇒ Object



82
83
84
85
# File 'lib/activefacts/vocabulary/extensions.rb', line 82

def describe(highlight = nil)
  (entity_type ? entity_type.name : "")+
  '('+all_role.map{|role| role.describe(highlight) }*", "+')'
end

#implicit_boolean_type(vocabulary) ⇒ Object



113
114
115
116
# File 'lib/activefacts/vocabulary/extensions.rb', line 113

def implicit_boolean_type vocabulary
  @constellation.ImplicitBooleanValueType[[vocabulary.identifying_role_values, "_ImplicitBooleanValueType"]] ||
  @constellation.ImplicitBooleanValueType(vocabulary.identifying_role_values, "_ImplicitBooleanValueType", :concept => :new)
end

#internal_presence_constraintsObject



103
104
105
106
107
108
109
110
111
# File 'lib/activefacts/vocabulary/extensions.rb', line 103

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_existentialObject

Does any role of this fact type participate in a preferred identifier?



92
93
94
95
96
97
98
99
100
101
# File 'lib/activefacts/vocabulary/extensions.rb', line 92

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



76
77
78
79
80
# File 'lib/activefacts/vocabulary/extensions.rb', line 76

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



129
130
131
132
133
134
135
# File 'lib/activefacts/vocabulary/extensions.rb', line 129

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