Sha256: 0398b76d7f26b24b177f6434d7b8aa6bbae02f28001455c6cddc845b82d2e92a

Contents?: true

Size: 975 Bytes

Versions: 3

Compression:

Stored size: 975 Bytes

Contents

require 'rexml/document'
require "nokogiri"
require 'yaml'

module Solrizer::Fedora::Extractor

  #
  # Extracts content-model and hydra-type from RELS-EXT datastream
  #
  def extract_rels_ext( text, solr_doc=Hash.new )
    # TODO: only read in this file once
    
    if defined?(RAILS_ROOT)
      config_path = File.join(RAILS_ROOT, "config")
    else
      config_path = File.join(File.dirname(__FILE__), "..", "..", "..", "config")
    end    
    map = YAML.load(File.open(File.join(config_path, "hydra_types.yml")))
    
    doc = Nokogiri::XML(text)
    doc.xpath( '//foo:hasModel', 'foo' => 'info:fedora/fedora-system:def/model#' ).each do |element|
      cmodel = element.attributes['resource'].to_s
      ::Solrizer::Extractor.insert_solr_field_value(solr_doc,  :cmodel_t, cmodel )
      
      if map.has_key?(cmodel)
        ::Solrizer::Extractor.insert_solr_field_value(solr_doc, :hydra_type_t, map[cmodel] )
      end
    end

    return solr_doc
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solrizer-fedora-1.0.3 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.0.2 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.0.1 lib/solrizer/fedora/extractor.rb