Module: Muml_Property

Defined in:
lib/ontomde-uml2/uml2.rb,
lib/ontomde-uml2/umlx.rb,
lib/ontomde-uml2/umlx.rb,
lib/ontomde-uml2/owner.rb,
lib/ontomde-uml2/dotDiagram.rb,
lib/ontomde-uml2/kb/protege.rb,
lib/ontomde-uml2/cardinality.rb

Instance Method Summary collapse

Instance Method Details

#prot_writeNTripleObject

writes this property as RDF triples



270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/ontomde-uml2/kb/protege.rb', line 270

def prot_writeNTriple
  # against infinite loop
  return unless @kb_exported.nil?
  @kb_exported=true
  
  if (uml_association.length==0)
    prot_writeNTriple_common
    #prot_writeNTriple_attribute
  else
    prot_writeNTriple_common
    prot_writeNTriple_association
  end
end

#prot_writeNTriple_associationObject



339
340
341
342
343
# File 'lib/ontomde-uml2/kb/protege.rb', line 339

def prot_writeNTriple_association
  write("<#{prot_uri}> <http://protege.stanford.edu/system#inverseProperty> <#{umlx_otherEnd.prot_uri}> .\n");
  # make sure other end is exported when it is not navigable.
  umlx_otherEnd.prot_writeNTriple unless umlx_otherEnd.umlx_isNavigable?
end

#prot_writeNTriple_commonObject

writes property elements common to association and attribute as RDF triples



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/ontomde-uml2/kb/protege.rb', line 285

def prot_writeNTriple_common
  o=self
  e=o.umlx_class_one
  #e=o.uml_ownedAttribute_inv
  #e=uml_class_one if e.nil?
  if e.nil?
    #log.debug "null!!!!"
    return
  end

  write("<#{o.prot_uri}> <#{NS_RDF_2000}rdf-schema#domain> <#{e.prot_uri}> .\n");
  append_comment
  o.uml_type.each { |t|
    if (t.kind_of?(Cuml_PrimitiveType))
      write("<#{o.prot_uri}> <#{NS_RDF_2000}rdf-schema#range> <#{t.prot_uri}> .\n")
      write(%{<#{o.prot_uri}> <http://protege.stanford.edu/system#range> "#{t.prot_primitive_type}" .\n})
    elsif t.kind_of?(Cuml_Enumeration)
      write("<#{o.prot_uri}> <#{NS_RDF_2000}rdf-schema#range> <#{NS_RDF_2000}rdf-schema#Literal> .\n")
      write(%{<#{o.prot_uri}> <http://protege.stanford.edu/system#range> "symbol" .\n})
      t.uml_ownedLiteral.each {|c|
        write(%{<#{o.prot_uri}> <http://protege.stanford.edu/system#allowedValues> "#{c}" .\n})
      }
    else
      write("<#{o.prot_uri}> <#{NS_RDF_2000}rdf-schema#range> <#{t.prot_uri}> .\n")
    end
  }
  write("<#{o.prot_uri}> <#{NS_RDF_1999}22-rdf-syntax-ns#type> <http://protege.stanford.edu/kb#UML_SLOT> .\n")
  write("<#{o.prot_uri}> <http://protege.stanford.edu/kb#UML_LABEL> \"#{o.prot_label}\".\n")
  write("<#{o.prot_uri}> <#{NS_UML_CLASS}#UML_URI> \"#{UriNamespace.instance.unalias(o.rdf_uri)}\" .\n")
  write("<#{o.prot_uri}> <#{RDF_LABEL_URI}> \"#{o.uml_name.to_s.nt_escape}\" .\n")

  cardUp=umlx_upperValueIsOne? ? "1" : "*"
  cardLow=umlx_lowerValueIsZero? ? "0" : "1"

  if ! uml_qualifier.empty?
    #qualifiers changes cardinality semantics
    cardLow="0"
    cardUp="*"
  end

  ##if isComposition
  # log.debug "est une composition"
  # cardLow="1"
  #end

  if cardLow!="0"
    write("<#{o.prot_uri}> <http://protege.stanford.edu/system#minCardinality> \"#{cardLow}\" .\n")
  end

  if cardUp!="-1"
    write("<#{o.prot_uri}> <http://protege.stanford.edu/system#maxCardinality> \"#{cardUp}\" .\n")
  end
end

#umlx_class_oneObject

uml_ownedAttribute_inv_one is sometime broken (RSM does not consistently populate this field) umlx_class_one figures out the correct value of uml_ownedAttribute_inv_one



562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
# File 'lib/ontomde-uml2/umlx.rb', line 562

def umlx_class_one
  # return uml_ownedAttribute_inv_one

  #ret=uml_ownedAttribute_inv_one0
  ret=uml_class_one0
  return ret unless ret.nil?

  #use association other end
  oe=umlx_otherEnd
  ret=oe.uml_type_one if !oe.nil?
  return ret unless ret.nil?

  #use ext_isReferencedBy
  ext_isReferencedBy.each { |o|
    next unless o.respond_to?(:uml_ownedAttribute)
    o.uml_ownedAttribute.each { |c|
      return o if c==self
    }
  }
  log.error("umlx_class_one not found in model for #{self}:#{self.class}")
  return nil
end

#umlx_classDiagram_dotFragmentObject

Generate dot graphical instruction for this element.



108
109
110
111
112
113
114
# File 'lib/ontomde-uml2/dotDiagram.rb', line 108

def umlx_classDiagram_dotFragment
  return if umlx_isAttribute?
  o=uml_class_one
  c=uml_type_one
  write(%{#{c.dotId} [label="#{c.uml_name}"]\n})
  write(%{#{o.dotId}->#{c.dotId} [arrowtail=none,arrowhead=vee,minlen=2,label="#{uml_name}"]\n})
end

#umlx_copyToAttributeProperty(oa) ⇒ Object

copy elements to the attribute property in Muml_Classifier module



71
72
73
74
75
76
77
# File 'lib/ontomde-uml2/umlx.rb', line 71

def umlx_copyToAttributeProperty(oa)
  oa.uml_upperValue=self.uml_upperValue
  oa.uml_lowerValue=self.uml_lowerValue
  oa.uml_type=self.uml_type
  oa.uml_isOrdered=self.uml_isOrdered
  oa.uml_isUnique=self.uml_isUnique
end

#umlx_exactlyOneSide?Boolean

Is this property such an extremity of an SQL mapping ? (lowerValue==1 && upperValue==1)

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ontomde-uml2/cardinality.rb', line 32

def umlx_exactlyOneSide?
  assoc = uml_association_one0
  return false if assoc.nil?
  lowerValue = self.uml_lowerValue_one0
  return false if lowerValue.nil?
  return false if lowerValue.umlx_to_i != 1
  upperValue = self.uml_upperValue_one0
  if !upperValue.nil?
    return false if upperValue.umlx_to_i!=1
  end
  return true
end

#umlx_isAssociation?Boolean

returns true if this property is part of an association.

Returns:

  • (Boolean)


57
58
59
# File 'lib/ontomde-uml2/umlx.rb', line 57

def umlx_isAssociation?
  return (!umlx_isAttribute?) && (!uml_aggregation_one0.nil?) && (uml_aggregation_one.isNone?)
end

#umlx_isAttribute?Boolean

returns true if this property is not part of an association. An attribute whose type is a class is considered an association.

Returns:

  • (Boolean)


50
51
52
53
54
# File 'lib/ontomde-uml2/umlx.rb', line 50

def umlx_isAttribute?
  t=uml_type_one
  ret=(uml_association.to_s.empty?) && (t.kind_of?(Muml_DataType)||t.kind_of?(Muml_Enumeration))
  return ret
end

#umlx_isComposite?Boolean

returns true if this property is part of composite association

Returns:

  • (Boolean)


66
67
68
# File 'lib/ontomde-uml2/umlx.rb', line 66

def umlx_isComposite?
  return (!umlx_isAttribute?) && (!uml_aggregation_one0.nil?) && (uml_aggregation_one.isComposite?)
end

#umlx_isNavigable?Boolean

returns true if property is navigable

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/ontomde-uml2/umlx.rb', line 42

def umlx_isNavigable?
  o=umlx_owner_one(true)
  return false if o.nil?
  return o.uml_ownedAttribute.include?(self)
end

#umlx_isShared?Boolean

returns true if this property is part of an shared association.

Returns:

  • (Boolean)


62
63
64
# File 'lib/ontomde-uml2/umlx.rb', line 62

def umlx_isShared?
  return (!umlx_isAttribute?) && (uml_aggregation_one.isShared?)
end

#umlx_manySide?Boolean

Is this property such an extremity of an SQL mapping ?

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ontomde-uml2/cardinality.rb', line 91

def umlx_manySide?
  #assoc = uml_association_one0
  #return false if assoc.nil?
  lowerValue = uml_lowerValue_one0
  if !lowerValue.nil?
    return true if lowerValue.umlx_to_i>1 || lowerValue.umlx_to_i==-1
  end
  upperValue = uml_upperValue_one0
  if !upperValue.nil?
    return true if upperValue.umlx_to_i>1 || upperValue.umlx_to_i==-1
  end
  return false
end

#umlx_manyToMany?Boolean

Should this SQL mapping used for this association ?

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
# File 'lib/ontomde-uml2/cardinality.rb', line 62

def umlx_manyToMany?
  assoc = uml_association_one0
  return false if assoc.nil?
  return false if !umlx_manySide?
  otherEnd = umlx_otherEnd
  return false if otherEnd.nil?
  return otherEnd.umlx_manySide?
end

#umlx_manyToOne?Boolean

Should this SQL mapping used for this association ?

Returns:

  • (Boolean)


82
83
84
85
86
87
88
# File 'lib/ontomde-uml2/cardinality.rb', line 82

def umlx_manyToOne?
  assoc = uml_association_one0
  return false if assoc.nil?
  otherEnd = umlx_otherEnd
  return false if otherEnd.nil?
  return otherEnd.umlx_oneToMany?
end

#umlx_masterEnd?Boolean

Is this property such an extremity of an SQL mapping ?

Returns:

  • (Boolean)


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ontomde-uml2/cardinality.rb', line 112

def umlx_masterEnd?
  assoc = uml_association_one0
  #return false if assoc.nil?
  #return false if assoc.uml_memberEnd.empty? || assoc.uml_memberEnd.size==1
  #return self==assoc.uml_memberEnd.first
  oe=umlx_otherEnd
  return true if oe.nil?
  return true if umlx_isNavigable? && !oe.umlx_isNavigable?
  return false if (!umlx_isNavigable?) && oe.umlx_isNavigable?


  #Bidirectionnal association.
  #First member is arbitrarily chosen as master.
  return self==assoc.uml_memberEnd.first
end

#umlx_oneSide?Boolean

Is this property such an extremity of an SQL mapping ? (lowerValue<=1 && upperValue==1)

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ontomde-uml2/cardinality.rb', line 47

def umlx_oneSide?
  #assoc = uml_association_one
  #return false if assoc.nil?
  lowerValue = self.uml_lowerValue_one0
  if !lowerValue.nil?
    return false if lowerValue.umlx_to_i>1
  end
  upperValue = self.uml_upperValue_one0
  if !upperValue.nil?
    return false if upperValue.umlx_to_i!=1
  end
  return true
end

#umlx_oneToMany?Boolean

Should this SQL mapping used for this association ?

Returns:

  • (Boolean)


72
73
74
75
76
77
78
79
# File 'lib/ontomde-uml2/cardinality.rb', line 72

def umlx_oneToMany?
  assoc = uml_association_one0
  return false if assoc.nil?
  return false if !umlx_manySide?
  otherEnd = umlx_otherEnd
  return false if otherEnd.nil?
  return otherEnd.umlx_oneSide?
end

#umlx_oneToOne?Boolean

Should this SQL mapping used for this association ?

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/ontomde-uml2/cardinality.rb', line 22

def umlx_oneToOne?
  return false if uml_association_one0.nil?
  return false if !umlx_oneSide?
  otherEnd = umlx_otherEnd
  return false if otherEnd.nil?
  return otherEnd.umlx_oneSide?
end

#umlx_otherEndObject

Returns the other end of the association this property is linked to. NOTES:

Returns nil if this class is not part of an association
Returns nil if other en is not navigable.


153
154
155
156
157
158
159
160
# File 'lib/ontomde-uml2/uml2.rb', line 153

def umlx_otherEnd
  self.uml_association.each { |ass|
    ass.uml_memberEnd.each { |p|
      return p if p!=self
    }
  }
  return nil
end

#umlx_owner_one(donotlog = false) ⇒ Object

returns element owner if found, nil otherwise



50
51
52
53
54
55
56
57
58
59
# File 'lib/ontomde-uml2/owner.rb', line 50

def umlx_owner_one(donotlog=false)
  ext_isReferencedBy.each { |res|
    next unless res.kind_of?(Muml_Classifier)
    next if res.kind_of?(Muml_Association)
    next unless res.uml_ownedAttribute.include?(self)
    return res
  }
  log.error("umlx_owner_one not found for #{self.class} #{self}") unless donotlog
  return nil
end

#umlx_unidirectionnel?Boolean

Returns:

  • (Boolean)


104
105
106
107
108
109
# File 'lib/ontomde-uml2/cardinality.rb', line 104

def umlx_unidirectionnel?
  return umlx_otherEnd.nil?
  #assoc = uml_association_one0
  #return false if assoc.nil?
  #return !assoc.uml_ownedEnd.empty?
end