Module: Muml_Property

Defined in:
lib/ontomde-uml2-kb/protege.rb,
lib/ontomde-uml2-kb/protege.rb

Constant Summary collapse

RDF_METACLASS_URI =

Metaclass URI used for a property in Protege

"http://protege.stanford.edu/kb#UML_SLOT"

Instance Method Summary collapse

Instance Method Details

#cardWithSameName(str) ⇒ Object

check model for homonym properties



179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/ontomde-uml2-kb/protege.rb', line 179

def cardWithSameName(str)
  @@otherWithSameName_cache||=nil
  return 	@@otherWithSameName_cache[str] if @@otherWithSameName_cache
  @@otherWithSameName_cache=Hash.new(0)

  rdf_model.uml_Class_all.each {|c| c.uml_ownedAttribute.each {|e|
      str2=e.uml_name.to_s
      @@otherWithSameName_cache[str2]+=1
    }}
  @@otherWithSameName_cache.each { |k,v|
    log.warn "WARNING: UML Model contains homonyms property : #{k} (#{v} times)" if v>1 && !k.include?("$")
  }
  return 	@@otherWithSameName_cache[str]
end

#otherWithSameName?Boolean

returns true if an homonym property exists in model

Returns:

  • (Boolean)


171
172
173
174
175
176
# File 'lib/ontomde-uml2-kb/protege.rb', line 171

def otherWithSameName?
  n= cardWithSameName(uml_name.to_s)
  return false if n==1
  return true if n>1
  log.error "Error: #{n} #{uml_name.to_s}"
end

#prot_labelObject

returns protege label for this property



195
196
197
198
199
200
# File 'lib/ontomde-uml2-kb/protege.rb', line 195

def prot_label
  return "#{prot_safe(uml_name)}" unless uml_name.to_s.empty?
  oe=umlx_otherEnd
  return "inv_#{prot_safe(oe.uml_name)}" unless oe.uml_name.to_s.empty?
  return "#{prot_safe(uri)}"
end

#prot_writeNTripleObject

writes this property as RDF triples



260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/ontomde-uml2-kb/protege.rb', line 260

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



329
330
331
332
333
# File 'lib/ontomde-uml2-kb/protege.rb', line 329

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



275
276
277
278
279
280
281
282
283
284
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
# File 'lib/ontomde-uml2-kb/protege.rb', line 275

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