Class: When::Events::DataSets

Inherits:
Object
  • Object
show all
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

Attributes included from Parts::Resource

#_pool, #child, #keys, #locale

Instance Method Summary collapse

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

#synchronize

Constructor Details

#initialize(uri, rows, &block) ⇒ DataSets

多言語対応データセットオブジェクトの生成

Parameters:

  • uri (String)

    データセット定義の所在

  • rows (Array<Array<String>>)

    多言語対応データセット定義

  • block (Block)

    キャッシュされたファイルパスの読み替え処理



329
330
331
332
333
334
335
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
# File 'lib/when_exe/events.rb', line 329

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

#datasetsHash<String=>When::Events::DataSet> (readonly)

各言語用のデータセットの Hash

Returns:



227
228
229
# File 'lib/when_exe/events.rb', line 227

def datasets
  @datasets
end

#labelWhen::BasicTypes::M17n (readonly)

名前



221
222
223
# File 'lib/when_exe/events.rb', line 221

def label
  @label
end

Instance Method Details

#dataset(language = '', limit = true) ⇒ When::Events::DataSet

単言語データセットオブジェクトの取得

Parameters:

  • language (String) (defaults to: '')

    言語コード

  • limit (Numeric) (defaults to: true)

    オブジェクト生成待ち時間 / 秒

  • limit (Boolean) (defaults to: true)

    false - 待たない, true - 無限に待つ

Returns:



237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/when_exe/events.rb', line 237

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 を生成する

Parameters:

  • uri (String)

    主語の URI

  • uri (Integer)

    主語のイベントの通し番号

  • graph (String) (defaults to: nil)

    検索対象のグラフ(ダミー)

Returns:

  • (Hash<String(GraphURI)=>RDF:Repository>)

    生成した Repository の Hash



286
287
288
289
290
291
292
# File 'lib/when_exe/events.rb', line 286

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 の取得

Parameters:

  • prefix (String)

    プレフィクス

  • language (String)

    言語コード

Returns:



258
259
260
# File 'lib/when_exe/events.rb', line 258

def namespace(prefix, language)
  When::Locale._hash_value(@prefixes[prefix], language)
end

#repository(events = nil) ⇒ Hash<String(GraphURI)=>RDF:Repository>

指定の Event を主語とする Statement からなる RDF:Repository を生成する

Parameters:

Returns:

  • (Hash<String(GraphURI)=>RDF:Repository>)

    生成した Repository の Hash



269
270
271
272
273
274
275
# File 'lib/when_exe/events.rb', line 269

def repository(events=nil)
  repositories = {}
  @datasets.each_pair do |language, dataset|
    repositories[language] = dataset.repository(events)
  end
  _merge_each_graph(repositories)
end

#used_nsHash<String(prefix)=>String(namespace)>

RDF::URI リソースで使用された prefix - namespace 対

Returns:



299
300
301
302
303
304
305
# File 'lib/when_exe/events.rb', line 299

def used_ns
  pair = {}
  @datasets.each_value do |dataset|
    pair.update(dataset.used_ns)
  end
  pair
end