Class: When::Events::DataSets
- Inherits:
-
Object
- Object
- When::Events::DataSets
- Includes:
- Parts::Resource
- Defined in:
- lib/when_exe/events.rb
Overview
多言語対応データセット群
言語ごとに異なるデータセットを保持する
Constant Summary
Constants included from Parts::Resource
Parts::Resource::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIDecode, Parts::Resource::IRIDecodeTable, Parts::Resource::IRIEncode, Parts::Resource::IRIEncodeTable, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty
Constants included from Namespace
Namespace::DC, Namespace::DCQ, Namespace::DCT, Namespace::FOAF, Namespace::OWL, Namespace::RDF, Namespace::RDFC, Namespace::RDFS, Namespace::RSS, Namespace::XSD
Instance Attribute Summary collapse
-
#datasets ⇒ Hash<String=>When::Events::DataSet>
readonly
各言語用のデータセットの Hash.
-
#label ⇒ When::BasicTypes::M17n
readonly
名前.
Attributes included from Parts::Resource
#_pool, #child, #keys, #locale
Instance Method Summary collapse
-
#dataset(language = '', limit = true) ⇒ When::Events::DataSet
単言語データセットオブジェクトの取得.
-
#event(uri, graph = nil) ⇒ Hash<String(GraphURI)=>RDF:Repository>
指定の URI を主語とする Statement からなる RDF:Repository を生成する.
-
#initialize(uri, rows, &block) ⇒ DataSets
constructor
多言語対応データセットオブジェクトの生成.
-
#namespace(prefix, language) ⇒ Array<String(namespace), String(説明)>
多言語対応 namespace の取得.
-
#repository(events = nil) ⇒ Hash<String(GraphURI)=>RDF:Repository>
指定の Event を主語とする Statement からなる RDF:Repository を生成する.
-
#used_ns ⇒ Hash<String(prefix)=>String(namespace)>
RDF::URI リソースで使用された prefix - namespace 対.
Methods included from Parts::Resource
#[], #^, _abbreviation_to_iri, _decode, _encode, _extract_prefix, _instance, _instantiate, _parse, _path_with_prefix, _replace_tags, _setup_, _setup_info, _simplify_path, base_uri, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #parent, #registered?, root_dir
Methods included from Parts::Resource::Pool
#[], #[]=, #_pool, #_setup_, #pool_keys
Methods included from Parts::Resource::Synchronize
Constructor Details
#initialize(uri, rows, &block) ⇒ DataSets
多言語対応データセットオブジェクトの生成
336 337 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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/when_exe/events.rb', line 336 def initialize(uri, rows, &block) # 定義行を言語ごとに仕分けする definitions = {} @prefixes = {} labels = nil datasets = nil (0...rows.size).to_a.reverse.each do |index| items = rows[index].map {|item| item.strip} prefix, namespace, word = items if /\A(.+?):@\*\z/ =~ prefix rows[index..index] = prefix_wildcard($1, namespace, word) else rows[index] = items end end rows.each do |row| next if row.first =~ /\A\s*#/ name, language= row.shift.split('@', 2) language ||= '' language.sub!('_', '-') if definitions.key?(name) if language == '' definitions[name].values.each do |definition| definition << row end else definitions[name][language] << row end else definitions[name] = Hash.new {|hash,key| hash[key]=[]}.merge({''=>[row]}) definitions[name][language] << row unless language == '' end case extract(name) when LABEL ; labels = filter_for_dataset(definitions[name]) when REFERENCE ; datasets = filter_for_dataset(definitions[name]) when /\A(.+?):\z/; @prefixes[$1] = filter_for_dataset(definitions[name], true) end end # 名前オブジェクトを生成する @label = When::BasicTypes::M17n.new({ 'label'=>labels[''].first, 'names'=>Hash[*(labels.keys.map {|label| [label, labels[label].first ]}).flatten], 'link' =>Hash[*(datasets.keys.map {|dataset| [dataset, datasets[dataset].first]}).flatten] }) @_pool = {'..'=>uri, '.'=>rows, @label.to_s=>@label} @child = [@label] @label._pool['..'] = self # 各言語用のデータセットオブジェクトを生成する if When.multi_thread @thread = Thread.new do begin @datasets = create_datasets(datasets, uri, definitions, &block) rescue => exception puts exception # puts exception.backtrace raise exception end end else @datasets = create_datasets(datasets, uri, definitions, &block) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class When::Parts::Resource
Instance Attribute Details
#datasets ⇒ Hash<String=>When::Events::DataSet> (readonly)
各言語用のデータセットの Hash
234 235 236 |
# File 'lib/when_exe/events.rb', line 234 def datasets @datasets end |
#label ⇒ When::BasicTypes::M17n (readonly)
名前
228 229 230 |
# File 'lib/when_exe/events.rb', line 228 def label @label end |
Instance Method Details
#dataset(language = '', limit = true) ⇒ When::Events::DataSet
単言語データセットオブジェクトの取得
244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/when_exe/events.rb', line 244 def dataset(language='', limit=true) if When.multi_thread joined = case limit when Numeric ; @thread.join(limit) when nil,false ; true else ; @thread.join end return nil unless joined end return nil unless @datasets When::Locale._hash_value(@datasets, language) end |
#event(uri, graph = nil) ⇒ Hash<String(GraphURI)=>RDF:Repository>
指定の URI を主語とする Statement からなる RDF:Repository を生成する
293 294 295 296 297 298 299 |
# File 'lib/when_exe/events.rb', line 293 def event(uri, graph=nil) repositories = {} @datasets.each_pair do |language, dataset| repositories[language] = dataset.event(uri, graph) end _merge_each_graph(repositories) end |
#namespace(prefix, language) ⇒ Array<String(namespace), String(説明)>
多言語対応 namespace の取得
265 266 267 |
# File 'lib/when_exe/events.rb', line 265 def namespace(prefix, language) When::Locale._hash_value(@prefixes[prefix], language) end |
#repository(events = nil) ⇒ Hash<String(GraphURI)=>RDF:Repository>
指定の Event を主語とする Statement からなる RDF:Repository を生成する
276 277 278 279 280 281 282 |
# File 'lib/when_exe/events.rb', line 276 def repository(events=nil) repositories = {} @datasets.each_pair do |language, dataset| repositories[language] = dataset.repository(events) end _merge_each_graph(repositories) end |