Module: HydraPbcore::Conversions

Overview

Methods for converting HydraPbcore 1.x datastreams to HydraPbcore 2.x datastreams

Verion 1.x of the HydraPbcore gem uses two kinds of pbcoreDocuments, one which includes an instantation and one which does not. Version 2 of the gem refactors these so that there is only one kind of pbcoreDocument and two kinds of instatiations. This offers greater flexibility as any number of instantiations may be attached to a document. Instatntiations come in two types, one is physical, meaning it represents a tape or other tangible object on which the video content resides, while the other kind is digital, representing a video file.

These methods attempt to correct invalid or inconsistent xml created using the first version of the gem.

Instance Method Summary collapse

Instance Method Details

#clean_document(xml = self.ng_xml) ⇒ Object

Corrects errors in HydraPbcore::Datastream::Deprecated::Document and HydraPbcore::Datastream::Deprecated::DigitalDocument

  • removes all pbcoreRelation nodes, except those that define event_series

  • removes orphaned pbcoreRelationIdentifier nodes

  • corrects invalid usage of event_place and event_series terms

Note: Since pbcoreRelation is used to indicated archival collection and series, this information should be copied to another kind of datastream using an RDF relationship in Hydra.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/hydra_pbcore/conversions.rb', line 49

def clean_document xml = self.ng_xml
  xml.search("//pbcoreRelation").each do |node|  
    node.remove unless is_event_series?(node)
  end
  xml.search("/pbcoreDescriptionDocument/pbcoreRelationIdentifier").collect {|n| n.remove}
  xml.search("//pbcoreCoverage").each do |node|
    node.children.each do |c|
      if c.attribute("annotation").nil? and c.name == "coverage"
        self.send(("insert_"+coverage_type(node)), c.text)
        c.remove
      end
    end
  end
end

#coverage_type(node) ⇒ Object

Determines if a coverage node that has no annotation attribute should be either an event_date term or an event_date term. Returns the first instance of an annotation attribute, processing it so that may be sent directly to the datastream as a method.



76
77
78
79
80
# File 'lib/hydra_pbcore/conversions.rb', line 76

def coverage_type node
  node.children.each do |c|
    return c.attribute("annotation").to_s.split.last.downcase unless c.attribute("annotation").nil?
  end
end

#is_event_series?(node) ⇒ Boolean

Determines if the given node defines an event_series term

Returns:

  • (Boolean)


65
66
67
68
69
70
71
# File 'lib/hydra_pbcore/conversions.rb', line 65

def is_event_series? node
  unless node.at_xpath("pbcoreRelationIdentifier").nil?
    if node.at_xpath("pbcoreRelationIdentifier").attribute("annotation").to_s == "Event Series"
      return true
    end
  end
end

#to_document(xml = self.ng_xml) ⇒ Object

Converts a HydraPbcore::Datastream::Deprecated::Document to a HydraPbcore::Datastream::Document

  • the existing pbcoreInstantiation node is removed and returned



18
19
20
# File 'lib/hydra_pbcore/conversions.rb', line 18

def to_document xml = self.ng_xml
  xml.search("//pbcoreInstantiation").remove
end

#to_instantiationObject

Converts a HydraPbcore::Datastream::Deprecated::Instantiation to a HydraPbcore::Datastream::Instantiation Modifies the exiting xml to exclude any parent nodes of the pbcoreInstantiation node



38
39
40
# File 'lib/hydra_pbcore/conversions.rb', line 38

def to_instantiation
  self.ng_xml = self.ng_xml.xpath("//pbcoreInstantiation").to_xml
end

#to_physical_instantiation(xml = self.ng_xml) ⇒ Object

Extracts the instantation from a HydraPbcore::Datastream::Deprecated::Document and returns a physical HydraPbcore::Datastream::Instantion

  • removes all instantiationRelation nodes

  • adds source=“PBCore instantiationColors” to instantiationColors node

  • extracts the pbcoreInstantiation node and returns new Instantiation object



27
28
29
30
31
32
33
34
# File 'lib/hydra_pbcore/conversions.rb', line 27

def to_physical_instantiation xml = self.ng_xml 
  xml.search("//instantiationRelation").each do |node|  
    node.remove
  end
  xml.search("//instantiationColors").first["source"] = "PBCore instantiationColors"
  inst_xml = xml.xpath("//pbcoreInstantiation")
  HydraPbcore::Datastream::Instantiation.from_xml(inst_xml.to_xml)
end