Module: Mrdf_Model

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

Instance Method Summary collapse

Instance Method Details

#generateMetaEditor(targetFile) ⇒ Object

generates Meta editor project for protege 2000



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/ontomde-uml2-kb/protege.rb', line 338

def generateMetaEditor(targetFile)
  #log.debug "targetFile=#{targetFile}"
  s=UML2_RDFS_NT_FILE
  t="#{targetFile}_meta.rdfs.nt"

  FileUtils.copy(s,t)
  if File.exist?(targetFile+"_meta.rdfs")
    log.info "Overwriting existing file: #{targetFile}_meta.rdfs"
  end
  translateToXML(targetFile+"_meta.rdfs.nt",targetFile+"_meta.rdfs")

  if File.exist?(targetFile+"_meta.rdf")
    log.info "Using already existing file: #{targetFile}_meta.rdf"
  else
    translateToXML(targetFile.to_s,targetFile+"_meta.rdf")
  end

  if File.exist?(targetFile+"_meta.pprj")
    log.info "Using already existing file: #{targetFile}_meta.pprj"
  else
    ext="pprj"
    log.info "creating .#{ext}"
    mtk_writeSession(targetFile+"_meta.#{ext}") {
      File.open("#{File.dirname(__FILE__)}/MYMODEL_meta.#{ext}",'r') { |src|
        src.each {|line|
          x=line.gsub(/MYMODEL_meta/,"#{File.basename(targetFile)}_meta")
          write(x)
        }
      }
    }
  end
end

#generateProtegeKbProject(targetFile) ⇒ Object

generates protege 2000 knowledge base project file and RDF file. internal used



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/ontomde-uml2-kb/protege.rb', line 380

def generateProtegeKbProject(targetFile)
  ["pprj","rdf"].each {  |ext|
    if File.exist?(targetFile+"_kb.#{ext}")
      log.debug { "Using already existing file: #{ext}" }
      next
    end
    log.info "creating .#{ext}"
    mtk_writeSession(targetFile+"_kb.#{ext}") {
      File.open("#{File.dirname(__FILE__)}/MYMODEL_kb.#{ext}",'r') { |src|
        src.each {|line|
          x=line.gsub(/MYMODEL_kb/,"#{File.basename(targetFile)}_kb")
          write(x)
        }
      }
    }
  }
end

#generateProtegeKbRDFS(targetFile) ⇒ Object

generates Protege 2000 RDFS file of a knowledge base project.



400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/ontomde-uml2-kb/protege.rb', line 400

def generateProtegeKbRDFS(targetFile)
  targetFileRDFS=targetFile+"_kb.rdfs.nt"
  targetFileXML=targetFile+"_kb.rdfs"
  mtk_writeSession(targetFileRDFS) {
    write(kbRDFS_header)
    uml_Model_all.each { |m|
      m.uml_Class_all.each {|c|
        next if c.kind_of?(Muml_Enumeration)
        c.prot_writeNTriple
        c.uml_ownedAttribute.each {|a|
          a.prot_writeNTriple
        }
      }
      m.uml_UseCase_all.each {|uc|
        uc.prot_writeNTriple
      }
    }
    write(kbRDFS_footer)
  }
  translateToXML(targetFileRDFS.to_s,targetFileXML)
end

#generateRDFS(targetFile) ⇒ Object

generates protege 2000 knowledge base project files



372
373
374
375
376
# File 'lib/ontomde-uml2-kb/protege.rb', line 372

def generateRDFS(targetFile)
  #generateMetaEditor(targetFile)
  generateProtegeKbProject(targetFile)
  generateProtegeKbRDFS(targetFile)
end

Protege 2000 RDFS knowledge base file footer



423
424
425
# File 'lib/ontomde-uml2-kb/protege.rb', line 423

def kbRDFS_footer
  return "# end\n"
end

#kbRDFS_headerObject

Protege 2000 RDFS knowledge base file header



428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/ontomde-uml2-kb/protege.rb', line 428

def kbRDFS_header
  nt_top='# debut\n'
  ['UML_CLASS','UML_TEST_DATA_SET'].each {|c|
    nt_top=nt_top+<<END2
<#{NS_UML_CLASS}##{c}> <http://protege.stanford.edu/system#role> "abstract" .
<#{NS_UML_CLASS}##{c}> <#{NS_RDF_2000}rdf-schema#label> "" .
<#{NS_UML_CLASS}##{c}> <#{NS_RDF_2000}rdf-schema#subClassOf> <#{NS_RDF_2000}rdf-schema#Resource> .
<#{NS_UML_CLASS}##{c}> <#{NS_RDF_2000}rdf-schema#comment> "Cette classe est la racine des classes de type UML. \\nFevrier 2006 - FTRD/BIZZ/CIL\\nStephane Carrie".
<#{NS_UML_CLASS}##{c}> <#{NS_RDF_1999}22-rdf-syntax-ns#type> <http://protege.stanford.edu/kb#UML_METACLASS> .
END2
  }

  nt_top=nt_top+<<END3
<#{NS_UML_CLASS}#UML_METACLASS> <#{NS_RDF_1999}22-rdf-syntax-ns#type> <#{NS_RDF_2000}rdf-schema#Class> .
<#{NS_UML_CLASS}#UML_METACLASS> <#{NS_RDF_2000}rdf-schema#label> "UML_METACLASS" .
<#{NS_UML_CLASS}#UML_METACLASS> <#{NS_RDF_2000}rdf-schema#subClassOf> <#{NS_RDF_2000}rdf-schema#Class> .
<#{NS_UML_CLASS}#UML_METACLASS> <#{NS_RDF_2000}rdf-schema#comment> "Cette classe est la metaclasse des classes de type UML. \\nFevrier 2006 - FTRD/BIZZ/CIL\\nStephane Pierre Carrie".
<http://protege.stanford.edu/kb#UML_SLOT> <#{NS_RDF_1999}22-rdf-syntax-ns#type> <#{NS_RDF_2000}rdf-schema#Class> .
<http://protege.stanford.edu/kb#UML_SLOT> <#{NS_RDF_2000}rdf-schema#subClassOf> <#{NS_RDF_1999}22-rdf-syntax-ns#Property> .
<#{NS_UML_CLASS}##{PROTEGE_INSTANCE_ALIAS_URI_SUFFIX}> <#{NS_RDF_1999}22-rdf-syntax-ns#type> <#{NS_RDF_1999}22-rdf-syntax-ns#Property> .
<#{NS_UML_CLASS}##{PROTEGE_INSTANCE_ALIAS_URI_SUFFIX}> <http://protege.stanford.edu/system#maxCardinality> "1" .
<#{NS_UML_CLASS}##{PROTEGE_INSTANCE_ALIAS_URI_SUFFIX}> <#{NS_RDF_2000}rdf-schema#label> "#{PROTEGE_INSTANCE_ALIAS_URI_SUFFIX}" .
<#{NS_UML_CLASS}##{PROTEGE_INSTANCE_ALIAS_URI_SUFFIX}> <#{NS_RDF_2000}rdf-schema#domain> <http://protege.stanford.edu/kb#UML_CLASS> .
<#{NS_UML_CLASS}##{PROTEGE_INSTANCE_ALIAS_URI_SUFFIX}> <#{NS_RDF_2000}rdf-schema#range> <#{NS_RDF_2000}rdf-schema#Literal> .
<#{NS_UML_CLASS}##{PROTEGE_INSTANCE_ALIAS_URI_SUFFIX}> <#{NS_RDF_2000}rdf-schema#comment> "UML Alias used as key in other tools (xmda java junit, ...)\\n - FTRD/BIZZ/CIL\\nStephane Pierre Carrie".
END3

  nt_top=nt_top+<<END
<#{NS_UML_CLASS}##{PROTEGE_USE_CASE_ENV_URI_SUFFIX}> <#{NS_RDF_1999}22-rdf-syntax-ns#type> <#{NS_RDF_1999}22-rdf-syntax-ns#Property> .
<#{NS_UML_CLASS}##{PROTEGE_USE_CASE_ENV_URI_SUFFIX}> <http://protege.stanford.edu/system#maxCardinality> "1" .
<#{NS_UML_CLASS}##{PROTEGE_USE_CASE_ENV_URI_SUFFIX}> <#{NS_RDF_2000}rdf-schema#label> "#{PROTEGE_USE_CASE_ENV_URI_SUFFIX}" .
<#{NS_UML_CLASS}##{PROTEGE_USE_CASE_ENV_URI_SUFFIX}> <#{NS_RDF_2000}rdf-schema#domain> <http://protege.stanford.edu/kb#UML_TEST_DATA_SET> .
<#{NS_UML_CLASS}##{PROTEGE_USE_CASE_ENV_URI_SUFFIX}> <#{NS_RDF_2000}rdf-schema#range> <#{NS_RDF_2000}rdf-schema#Literal> .
<#{NS_UML_CLASS}##{PROTEGE_USE_CASE_ENV_URI_SUFFIX}> <#{NS_RDF_2000}rdf-schema#comment> "UML Alias used as key in other tools (xmda java junit, ...)\\n - FTRD/BIZZ/CIL\\nStephane Pierre Carrie".
END




  ['UML_LABEL', 'UML_URI'].each{ |k|
    nt_top=nt_top+<<END
<#{NS_UML_CLASS}##{k}> <#{NS_RDF_1999}22-rdf-syntax-ns#type> <#{NS_RDF_1999}22-rdf-syntax-ns#Property> .
<#{NS_UML_CLASS}##{k}> <http://protege.stanford.edu/system#maxCardinality> "1" .
<#{NS_UML_CLASS}##{k}> <#{NS_RDF_2000}rdf-schema#label> "#{k}" .
<#{NS_UML_CLASS}##{k}> <#{NS_RDF_2000}rdf-schema#domain> <http://protege.stanford.edu/kb#UML_METACLASS> .
<#{NS_UML_CLASS}##{k}> <#{NS_RDF_2000}rdf-schema#domain> <http://protege.stanford.edu/kb#UML_SLOT> .
<#{NS_UML_CLASS}##{k}> <#{NS_RDF_2000}rdf-schema#range> <#{NS_RDF_2000}rdf-schema#Literal> .
END
  }
  #<#{NS_UML_CLASS}##{k}> <http://protege.stanford.edu/system#range> "cls" .
  #<#{NS_UML_CLASS}##{k}> <#{NS_RDF_2000}rdf-schema#range> <http://www.w3.org/2000/01/rdf-schema#Class> .
  #<#{NS_UML_CLASS}##{k}> <http://protege.stanford.edu/system#allowedParents> <#{NS_UML_CLASS}#UML_TEST_DATA_SET> .

  ['UML_REFERENCED_USE_CASE'].each{ |k|
    inv="UML_DATA"
    nt_top=nt_top+<<END
<#{NS_UML_CLASS}##{k}> <#{NS_RDF_1999}22-rdf-syntax-ns#type> <#{NS_RDF_1999}22-rdf-syntax-ns#Property> .
<#{NS_UML_CLASS}##{k}> <#{NS_RDF_2000}rdf-schema#label> "#{k}" .
<#{NS_UML_CLASS}##{k}> <#{NS_RDF_2000}rdf-schema#range> <#{NS_UML_CLASS}#UML_TEST_DATA_SET> .
<#{NS_UML_CLASS}##{k}> <#{NS_RDF_2000}rdf-schema#domain> <#{NS_UML_CLASS}#UML_CLASS> .
<#{NS_UML_CLASS}##{k}> <http://protege.stanford.edu/system#inverseProperty> <#{NS_UML_CLASS}##{inv}> .
<#{NS_UML_CLASS}##{inv}> <#{NS_RDF_1999}22-rdf-syntax-ns#type> <#{NS_RDF_1999}22-rdf-syntax-ns#Property> .
<#{NS_UML_CLASS}##{inv}> <#{NS_RDF_2000}rdf-schema#label> "{k}" .
<#{NS_UML_CLASS}##{inv}> <http://protege.stanford.edu/system#inverseProperty> <#{NS_UML_CLASS}##{k}> .
<#{NS_UML_CLASS}##{inv}> <#{NS_RDF_2000}rdf-schema#range> <#{NS_UML_CLASS}#UML_CLASS> .
<#{NS_UML_CLASS}##{inv}> <#{NS_RDF_2000}rdf-schema#domain> <#{NS_UML_CLASS}#UML_TEST_DATA_SET> .
END
  }
  return nt_top
end