Class: Crdf_Repository

Inherits:
Object show all
Includes:
Mmtk_helper, Mrdf_Repository
Defined in:
lib/ontomde-core/resourceSet.rb,
lib/ontomde-core/helper.rb

Overview

Class meant to store every element of a model.

Constant Summary collapse

@@RDF_type =

internal use

['rdf_type']

Constants included from Mmtk_helper

Mmtk_helper::MTK_WRITE_SESSION_FILE_NAMES, Mmtk_helper::NOREVERSE, Mmtk_helper::REVERSE, Mmtk_helper::TEMP_FILE_SUFFIX, Mmtk_helper::WITHOUT_MARKER

Instance Attribute Summary collapse

Attributes included from Mmtk_helper

#fileGenerated

Instance Method Summary collapse

Methods included from Mrdf_Repository

#context, #inspector_start_daemon, #mtk_context, #mtk_default_context, #mtk_object_message, #mtk_related_message

Methods included from Mmtk_helper

#encloseWrite, #mtk_annotation, #mtk_autoNewFileCreationCheck, #mtk_out, #mtk_protected, #mtk_qualifyBlockURI, #mtk_retrieveProtected, #mtk_shouldAlreadyBeenReversed, #mtk_sprotected, #mtk_stringWriteSession, #mtk_stss, #mtk_wprotected, #mtk_writeSession, #mtk_writeSessionNameClashErrorDetection, #notifyFileGenerated, #write

Constructor Details

#initializeCrdf_Repository

Initialize model internal structures.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ontomde-core/resourceSet.rb', line 72

def initialize
  super
  @resourceSet=Hash.new
  #@fileGenerated=Array.new
  @updateCount=0
  @typeIndex=Hash.new
  #@@mtk_out=nil

  #bootstrap
  Crdf_Resource.new(self,'rdf_Resource');
  Crdf_Resource.new(self,'rdfs_Resource'); # le p�re des h�ritages
  Crdf_Resource.new(self,'rdfs_Class');
  Crdf_Resource.new(self,'rdf_Property');
  Crdf_Resource.new(self,'rdfs_Literal');

  #bootstrap pour module kb
  Crdf_Resource.new(self,'kb_UML_METACLASS');
  Crdf_Resource.new(self,'kb_UML_SLOT');

  self.each {|k,c| c.ext_isBootstrap='true'}
end

Instance Attribute Details

#typeIndexObject (readonly)

Returns the value of attribute typeIndex.



16
17
18
# File 'lib/ontomde-core/resourceSet.rb', line 16

def typeIndex
  @typeIndex
end

#updateCountObject (readonly)

Returns the value of attribute updateCount.



14
15
16
# File 'lib/ontomde-core/resourceSet.rb', line 14

def updateCount
  @updateCount
end

Instance Method Details

#[](key) ⇒ Object

Returns the ressource associated to the uri key.



35
36
37
# File 'lib/ontomde-core/resourceSet.rb', line 35

def [](key)
  return @resourceSet[key]
end

#[]=(key, res) ⇒ Object

Internal use



40
41
42
43
44
45
46
47
48
49
# File 'lib/ontomde-core/resourceSet.rb', line 40

def []=(key,res)
  if @resourceSet.include?(key)
    #puts "duplicate key: #{res == @resourceSet[key]}  #{@@zzzz} #{key} --> #{res} #{@resourceSet[key]}"
    #raise Exception.new() if res.to_s.include?("string") #if res != @resourceSet[key] #&& key.include?("get_p1")
  end
  @typeIndex.each { |ti,idx|
    idx.add(res) if res.kind_of?(ti)
  }
  @resourceSet[key]=res
end

#addTypeIndex(idxType) ⇒ Object



21
22
23
# File 'lib/ontomde-core/resourceSet.rb', line 21

def addTypeIndex(idxType)
  @typeIndex[idxType]=Set.new
end

#delete(key) ⇒ Object



18
19
20
# File 'lib/ontomde-core/resourceSet.rb', line 18

def delete(key)
  @resourceSet.delete(key)
end

#dynNewInstance(value_res, about_uri) ⇒ Object

internal use



120
121
122
123
# File 'lib/ontomde-core/resourceSet.rb', line 120

def dynNewInstance(value_res,about_uri)
  cmd=value_res.getRubyClassName+'.new(self,about_uri)'
  return eval(cmd)
end

#each(&block_expr) ⇒ Object

Standard each iterator



52
53
54
# File 'lib/ontomde-core/resourceSet.rb', line 52

def each(&block_expr)
  @resourceSet.each &block_expr
end

#each_value(&block_expr) ⇒ Object

Standard each_value iterator



62
63
64
# File 'lib/ontomde-core/resourceSet.rb', line 62

def each_value(&block_expr)
  @resourceSet.each_value &block_expr
end

#empty?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ontomde-core/resourceSet.rb', line 27

def empty?
  return @resourceSet.empty?
end

#find_all(&block_expr) ⇒ Object

Standard find_all iterator



57
58
59
# File 'lib/ontomde-core/resourceSet.rb', line 57

def find_all(&block_expr)
  @resourceSet.find_all &block_expr
end

#generateClassesFromMetamodel(outRubyModelFileName) ⇒ Object

internal use



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/ontomde-core/resourceSet.rb', line 166

def generateClassesFromMetamodel(outRubyModelFileName)
  #log.debug("ecriture du metamodele dans: #{outRubyModelFileName}")
  mtk_default_context(:logFileWrite => false) { mtk_writeSession(outRubyModelFileName) {
      mtk_addTempFileToDelete(outRubyModelFileName)
      f=self
      f.write <<END
# Start of file #{outRubyModelFileName}
# This file is automaticaly generated
# Generation date:#{Time.now}
END
      self.each_value { |x|
        next unless x.kind_of?(Crdfs_Class)
        ##log.debug "gen -> #{x} #{x.class}"
        #createRubyClassMinimal(model)
        cmd=x.createRubyClass(self)
        f.write(cmd)
      }
      f.write("# End of file #{outRubyModelFileName}\n")
    }}
end

#getRes(uri) ⇒ Object

returns ressource associated to uri stored in model

Raises:



95
96
97
98
99
100
# File 'lib/ontomde-core/resourceSet.rb', line 95

def getRes(uri)
  raise Warning.new,'nil uri' if uri.nil?
  obj=self[uri]
  raise WarningURIundefined.new(uri),"--uri undefined \"#{uri}\" "  if obj.nil?
  return obj
end

#lengthObject



24
25
26
# File 'lib/ontomde-core/resourceSet.rb', line 24

def length
  @resourceSet.length
end

#parseModeData(nt) ⇒ Object

internal use



148
149
150
151
152
153
154
155
156
157
# File 'lib/ontomde-core/resourceSet.rb', line 148

def parseModeData(nt)
  return if predicat_isRDFTYPE(nt.predicat_uri)
  subject=self.getRes(nt.about_uri)
  if nt.valueIsReference?
    subject.set(rubyIdentifier(nt.predicat_uri),self.getRes(nt.value_uri))
  else
    subject.set(rubyIdentifier(nt.predicat_uri),nt.value_litteral)
  end

end

#parseModeResource(nt) ⇒ Object

internal use



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ontomde-core/resourceSet.rb', line 126

def parseModeResource(nt)
  return if !predicat_isRDFTYPE(nt.predicat_uri)

  about_res=self[nt.about_uri]
  if about_res
    about_res.forceReset!()
  else
    value_res=self.getRes(nt.value_uri)
    begin
      about_res=dynNewInstance(value_res,nt.about_uri)
      about_res.rdf_type=value_res
      #about_res.set(rubyIdentifier(predicat_uri),value_res) # ref
    rescue  => e
      log.debug "e-->#{e}"
      #TODO: cause probable
      raise WarningRubyTypeUndefined.new(nt.about_uri,value_res),"Ruby Type #{value_res.getRubyClassName} Undefined (cause probable!)"
    end
    return
  end
end

#parseNT(nt, modeData) ⇒ Object

internal use



103
104
105
106
107
108
109
# File 'lib/ontomde-core/resourceSet.rb', line 103

def parseNT(nt,modeData)
  if modeData # MODE_parseModelStream_POPULATE_FIELDS
    parseModeData(nt)
  else # MODE_parseModelStream_CREATE_INSTANCES
    parseModeResource(nt)
  end
end

#predicat_isRDFTYPE(predicat) ⇒ Object

internal use



115
116
117
# File 'lib/ontomde-core/resourceSet.rb', line 115

def predicat_isRDFTYPE(predicat)
  return @@RDF_type.include?(predicat)
end

#reject(&block_expr) ⇒ Object

Standard reject iterator



67
68
69
# File 'lib/ontomde-core/resourceSet.rb', line 67

def reject(&block_expr)
  @resourceSet.reject &block_expr
end

#rubyIdentifier(str) ⇒ Object

internal use



160
161
162
# File 'lib/ontomde-core/resourceSet.rb', line 160

def rubyIdentifier(str)
  return str.tr('^a-zA-Z0-9','_')
end

#to_sObject



30
31
32
# File 'lib/ontomde-core/resourceSet.rb', line 30

def to_s
  log.debug  'Model'
end