lib/activefacts/input/orm.rb in activefacts-0.8.18 vs lib/activefacts/input/orm.rb in activefacts-1.0.0
- old
+ new
@@ -46,12 +46,12 @@
"UnsignedTinyIntegerNumeric" => "Unsigned Integer(8)",
"UnsignedSmallIntegerNumeric" => "Unsigned Integer(16)",
"UnsignedLargeIntegerNumeric" => "Unsigned Integer(64)",
"AutoCounterNumeric" => "Auto Counter",
"FloatingPointNumeric" => "Real(64)",
- "SinglePrecisionFloatingPointNumeric" => " Real(32)",
- "DoublePrecisionFloatingPointNumeric" => " Real(32)",
+ "SinglePrecisionFloatingPointNumeric" => "Real(32)",
+ "DoublePrecisionFloatingPointNumeric" => "Real(32)",
"DecimalNumeric" => "Decimal",
"MoneyNumeric" => "Money",
"FixedLengthRawData" => "Blob",
"VariableLengthRawData" => "Blob",
"LargeLengthRawData" => "Blob",
@@ -158,11 +158,11 @@
name = nil if name.size == 0
entity_type =
@by_id[id] =
debug :orm, "Asserting new EntityType #{name.inspect}" do
@vocabulary.valid_entity_type_name(name) ||
- @constellation.EntityType(@vocabulary, name, :guid => id_of(x))
+ @constellation.EntityType(@vocabulary, name, :concept => id_of(x))
end
entity_types << entity_type
independent = x['IsIndependent']
entity_type.is_independent = true if independent && independent == 'true'
personal = x['IsPersonal']
@@ -231,30 +231,30 @@
raise "Supertype of #{name} is post-defined but recursiving processing failed" unless supertype
raise "Supertype #{supertype_name} of #{name} is not a value type" unless supertype.kind_of? ActiveFacts::Metamodel::ValueType
debug :orm, "Asserting new ValueType #{supertype_name.inspect} for supertype" do
value_super_type =
@vocabulary.valid_value_type_name(supertype_name) ||
- @constellation.ValueType(@vocabulary, supertype_name, :guid => id_of(x_supertype))
+ @constellation.ValueType(@vocabulary, supertype_name, :concept => id_of(x_supertype))
end
else
# REVISIT: Need to handle standard types better here:
value_super_type =
if type_name != name
debug :orm, "Asserting new ValueType #{type_name.inspect} for supertype" do
@vocabulary.valid_value_type_name(type_name) ||
- @constellation.ValueType(@vocabulary.identifying_role_values, type_name, :guid => :new)
+ @constellation.ValueType(@vocabulary.identifying_role_values, type_name, :concept => :new)
end
else
nil
end
end
vt =
debug :orm, "Asserting new ValueType #{name.inspect}" do
@by_id[id] =
@vocabulary.valid_value_type_name(name) ||
- @constellation.ValueType(@vocabulary.identifying_role_values, name, :guid => id_of(x))
+ @constellation.ValueType(@vocabulary.identifying_role_values, name, :concept => id_of(x))
end
vt.supertype = value_super_type
vt.length = length if length
vt.scale = scale if scale && scale != 0
independent = x['IsIndependent']
@@ -303,11 +303,10 @@
id = x['id']
name = x['Name'] || x['_Name']
name = "<unnamed>" if !name
name = "" if !name || name.size == 0
# Note that the new metamodel doesn't have a name for a facttype unless it's objectified
- next if x.xpath("orm:DerivationRule").size > 0
debug :orm, "FactType #{name || id}"
facts << @by_id[id] = fact_type = @constellation.FactType(id_of(x))
}
end
@@ -351,11 +350,11 @@
# We already handled ValueType subtyping:
next if subtype.kind_of? ActiveFacts::Metamodel::ValueType or
supertype.kind_of? ActiveFacts::Metamodel::ValueType
- inheritance_fact = @constellation.TypeInheritance(subtype, supertype, :guid => id_of(x))
+ inheritance_fact = @constellation.TypeInheritance(subtype, supertype, :concept => id_of(x))
if x["IsPrimary"] == "true" or # Old way
x["PreferredIdentificationPath"] == "true" # Newer
debug :orm, "#{supertype.name} is primary supertype of #{subtype.name}"
inheritance_fact.provides_identification = true
end
@@ -363,12 +362,12 @@
mapping_choice = mapping ? mapping.parent['AbsorptionChoice'] : 'Absorbed'
inheritance_fact.assimilation = mapping_choice.downcase.sub(/partition/, 'partitioned') if mapping_choice != 'Absorbed'
facts << @by_id[id] = inheritance_fact
# Create the new Roles so we can find constraints on them:
- subtype_role = @by_id[subtype_role_id] = @constellation.Role(inheritance_fact, 0, :object_type => subtype, :guid => id_of(x_subtype_role))
- supertype_role = @by_id[supertype_role_id] = @constellation.Role(inheritance_fact, 1, :object_type => supertype, :guid => id_of(x_supertype_role))
+ subtype_role = @by_id[subtype_role_id] = @constellation.Role(inheritance_fact, 0, :object_type => subtype, :concept => id_of(x_subtype_role))
+ supertype_role = @by_id[supertype_role_id] = @constellation.Role(inheritance_fact, 1, :object_type => supertype, :concept => id_of(x_supertype_role))
# Create readings, so constraints can be verbalised for example:
rs = @constellation.RoleSequence(:new)
@constellation.RoleRef(rs, 0, :role => subtype_role)
@constellation.RoleRef(rs, 1, :role => supertype_role)
@@ -400,21 +399,20 @@
x_fact_type = x.xpath('orm:NestedPredicate')[0]
is_implied = x_fact_type['IsImplied'] == "true"
fact_id = x_fact_type['ref']
fact_type = @by_id[fact_id]
- next if x.xpath("orm:DerivationRule").size > 0
next unless fact_type # "Nested fact #{fact_id} not found; objectification of a derived fact type?"
- debug :orm, "NestedType #{name} is #{id}, nests #{fact_type.guid}"
+ debug :orm, "NestedType #{name} is #{id}, nests #{fact_type.concept.guid}"
@nested_types <<
@by_id[id] =
nested_type = @vocabulary.valid_entity_type_name(name) ||
- @constellation.EntityType(@vocabulary, name, :guid => id_of(x))
+ @constellation.EntityType(@vocabulary, name, :concept => id_of(x))
independent = x['IsIndependent']
nested_type.is_independent = true if independent && independent == 'true' && !is_implied
- nested_type.is_implied_by_objectification = is_implied
+ nested_type.concept.implication_rule = 'objectification' if is_implied
nested_type.fact_type = fact_type
}
end
end
@@ -429,11 +427,10 @@
def read_roles
debug :orm, "Reading roles and readings" do
@x_facts.each{|x|
id = x['id']
- next if x.xpath("orm:DerivationRule").size > 0
fact_type = @by_id[id]
fact_name = x['Name'] || x['_Name'] || ''
#fact_name.gsub!(/\s/,'')
fact_name = nil if fact_name == ''
@@ -473,20 +470,22 @@
other_role.role_name = role_name if role_name && role_name != ''
@by_id.delete(ref) # and de-index it from our list
next
end
- throw "RolePlayer for '#{name}' #{ref} in fact type #{x.parent.parent['_Name']} was not found" if !object_type
+ if !object_type
+ throw "RolePlayer for '#{name}' #{ref} in fact type #{x.parent.parent['_Name']} was not found"
+ end
debug :orm, "#{@vocabulary.name}, RoleName=#{x['Name'].inspect} played by object_type=#{object_type.name}"
throw "Role is played by #{object_type.class} not ObjectType" if !(@constellation.vocabulary.object_type(:ObjectType) === object_type)
- debug :orm, "Creating role #{name} nr#{fact_type.all_role.size} of #{fact_type.guid} played by #{object_type.name}"
+ debug :orm, "Creating role #{name} nr#{fact_type.all_role.size} of #{fact_type.concept.guid} played by #{object_type.name}"
- role = @by_id[id] = @constellation.Role(fact_type, fact_type.all_role.size, :object_type => object_type, :guid => id_of(x))
+ role = @by_id[id] = @constellation.Role(fact_type, fact_type.all_role.size, :object_type => object_type, :concept => id_of(x))
role.role_name = name if name && name != object_type.name
- debug :orm, "Fact #{fact_name} (id #{fact_type.guid.object_id}) role #{x['Name']} is played by #{object_type.name}, role is #{role.object_id}"
+ debug :orm, "Fact #{fact_name} (id #{fact_type.concept.guid}) role #{x['Name']} is played by #{object_type.name}, role is #{role.concept.guid}"
x_vr = x.xpath("orm:ValueRestriction/orm:RoleValueConstraint")
x_vr.each{|vr|
x_ranges = vr.xpath("orm:ValueRanges/orm:ValueRange")
next if x_ranges.size == 0
@@ -569,11 +568,11 @@
}
text.sub!(/\s\s*/, ' ') # Compress extra spaces
text.strip!
text.downcase! # Check for reserved words and object type names *after* downcasing
elided = ''
- text.gsub!(/( |-?\b[A-Za-z_][A-Za-z0-9_]*\b-?|\{\d\})|./) do |w|
+ text.gsub!(/( |[a-z]+(-[a-z]+)+|-?\b[A-Za-z_][A-Za-z0-9_]*\b-?|\{\d\})|./) do |w|
case w
when /[A-Za-z]/
if RESERVED_WORDS.include?(w)
$stderr.puts "Masking reserved word '#{w}' in reading '#{text}'"
next "_#{w}"
@@ -597,11 +596,11 @@
$stderr.puts "Elided illegal characters '#{elided}' from reading #{text.inspect}" unless elided.empty?
text
end
def get_role_sequence(role_array)
- # puts "Getting RoleSequence [#{role_array.map{|r| "#{r.object_type.name} (role #{r.object_id})" }*", "}]"
+ # puts "Getting RoleSequence [#{role_array.map{|r| "#{r.object_type.name} (role #{r.concept.guid})" }*", "}]"
# Look for an existing RoleSequence
# REVISIT: This searches all role sequences. Perhaps we could narrow it down first instead?
role_sequence = @constellation.RoleSequence.values.detect{|c|
#puts "Checking RoleSequence [#{c.all_role_ref.map{|rr| rr.role.object_type.name}*", "}]"
@@ -638,12 +637,10 @@
end
# This might have been a role of an ImpliedFact, which makes it safe to ignore.
next if 'ImpliedFact' == x_role.parent.parent.name
- next if x_role.parent.parent.xpath('orm:DerivationRule').size > 0
-
# Talk about why this wasn't found - this shouldn't happen.
if (!x_nests || !implied)
#puts "="*60
# We skip creating TypeInheritance implied fact types for ValueType inheritance
return nil if x_role.name = 'orm:SubtypeMetaRole' or x_role.name = 'orm:SupertypeMetaRole'
@@ -1234,11 +1231,11 @@
end
end
def read_instances
debug :orm, "Reading sample data" do
- population = @constellation.Population(@vocabulary, "sample", :guid => :new)
+ population = @constellation.Population(@vocabulary, "sample", :concept => :new)
# Value instances first, then entities then facts:
x_values = @x_model.xpath("orm:Objects/orm:ValueType/orm:Instances/orm:ValueTypeInstance/orm:Value")
#pp x_values.map{|v| [ v.parent['id'], v.text ] }
@@ -1404,11 +1401,11 @@
location = convert_location(bounds, Gravity::C)
shape = @constellation.RingConstraintShape(
:guid => id_of(x_shape), :orm_diagram => diagram, :location => location, :is_expanded => is_expanded,
:constraint => subject
)
- shape.fact_type = subject.role.fact_type
+ shape.fact_type_shape = subject.role.fact_type.all_fact_type_shape.to_a[0]
when 'ModelNoteShape'
# REVISIT: Add model notes
when 'ObjectTypeShape'
location = convert_location(bounds, Gravity::C)
# $stderr.puts "#{subject.name}: bounds=#{bounds} -> location = (#{location.x}, #{location.y})"
@@ -1443,10 +1440,10 @@
# Location of a fact type is the centre of the row of role boxes
offs_x = 11
offs_y = -12
if fact_type.entity_type
offs_x -= 12
- offs_y -= 9 if !fact_type.entity_type.is_implied_by_objectification
+ offs_y -= 9 if !fact_type.entity_type.concept.implication_rule # .implication_rule_name == 'objectification'
end
location = convert_location(bounds, Gravity::S, offs_x, offs_y)
# $stderr.puts "#{fact_type.describe}: bounds=#{bounds} -> location = (#{location.x}, #{location.y})"