<commit_before>require 'rubygems'
require 'roxml'

#<identityMetadata>
#     <objectId>druid:rt923jk342</objectId>
#     <objectType>item</objectType>
#     <objectLabel>google download barcode 36105049267078</objectLabel>
#     <objectCreator>DOR</objectCreator>
#     <citationTitle>Squirrels of North America</citationTitle>
#     <citationCreator><NAME>, 1974-</citationCreator>
#     <sourceId source="google">STANFORD_342837261527</sourceId>
#     <otherId name="barcode">342837261527</otherId>
#     <otherId name="catkey">129483625</otherId>
#     <otherId name="uuid">7f3da130-7b02-11de-8a39-0800200c9a66</otherId>
#     <agreementId>druid:yh72ms9133</agreementId>
#     <tag>Google Books : Phase 1</tag>
#     <tag>Google Books : Scan source STANFORD</tag>
#</identityMetadata>

class SourceId
  include ROXML

  xml_name :sourceId
  xml_accessor :source, :from => '@source'
  xml_accessor :value, :from => :content
end

class OtherId
  include ROXML

  xml_name :otherId
  xml_accessor :name, :from => '@name'
  xml_accessor :value, :from => :content
end

class Tag
  include ROXML
  xml_name :tag
  xml_accessor :value, :from => :content
end

class IdentityMetadata
  include ROXML

  xml_name :identityMetadata
  xml_accessor :objectId
  xml_accessor :objectType
  xml_accessor :objectLabel
  xml_accessor :objectCreator
  xml_accessor :citationTitle
  xml_accessor :citationCreator
  xml_accessor :sourceId, :as => SourceId
  xml_accessor :otherIds, :as => [OtherId]
  xml_accessor :agreementId
  xml_accessor :tags, :as => [Tag]

  # Add a new tag to the IdentityMetadata instance
  def add_tag(new_tag_value)
    # Make sure tag is not already present
    for tag in @tags do
      if (tag.value == new_tag_value )
        return
      end
    end
    tag = Tag.new
    tag.value = new_tag_value
    @tags << tag
  end

  # Return the OtherId object for the specified identier name
  def get_other_id(key)
    if (@otherIds != nil)
      for other_id in @otherIds do
        return other_id  if (other_id.name == key)
      end      
    end
    return nil
  end

  # Return the identifier value for the specified identier name
  def get_identifier_value(key)
    other_id = self.get_other_id(key)
    if (other_id != nil)
      return other_id.value
    end
    raise "No #{key} indentifier found for druid #{@objectId}"
  end

  # Add a new name,value pair to the set of identifiers
  def add_identifier(key, value)
    other_id = self.get_other_id(key)
    if (other_id != nil)
      other_id.value = value
    else
      other_id = OtherId.new
      other_id.name = key
      other_id.value = value
      if (@otherIds == nil)
         @otherIds = [other_id]
      else
        @otherIds <<  other_id
      end
    end
  end

  # Return an array of strings where each entry consists of name:value
  def get_id_pairs
    pairs=Array.new
    if (@otherIds != nil)
      @otherIds.each do |other_id|
        pairs << "#{other_id.name}:#{other_id.value}"
      end
    end
    return pairs
  end

end<commit_msg>Part of fix for PHNX-88 = Add objectAdminClass=GoogleBooks to identityMetadata<commit_after>require 'rubygems'
require 'roxml'

#<identityMetadata>
#     <objectId>druid:rt923jk342</objectId>
#     <objectType>item</objectType>
#     <objectLabel>google download barcode 36105049267078</objectLabel>
#     <objectCreator>DOR</objectCreator>
#     <citationTitle>Squirrels of North America</citationTitle>
#     <citationCreator><NAME>, 1974-</citationCreator>
#     <sourceId source="google">STANFORD_342837261527</sourceId>
#     <otherId name="barcode">342837261527</otherId>
#     <otherId name="catkey">129483625</otherId>
#     <otherId name="uuid">7f3da130-7b02-11de-8a39-0800200c9a66</otherId>
#     <agreementId>druid:yh72ms9133</agreementId>
#     <tag>Google Books : Phase 1</tag>
#     <tag>Google Books : Scan source STANFORD</tag>
#</identityMetadata>

class SourceId
  include ROXML

  xml_name :sourceId
  xml_accessor :source, :from => '@source'
  xml_accessor :value, :from => :content
end

class OtherId
  include ROXML

  xml_name :otherId
  xml_accessor :name, :from => '@name'
  xml_accessor :value, :from => :content
end

class Tag
  include ROXML
  xml_name :tag
  xml_accessor :value, :from => :content
end

class IdentityMetadata
  include ROXML

  xml_name :identityMetadata
  xml_accessor :objectId
  xml_accessor :objectType
  xml_accessor :objectAdminClass
  xml_accessor :objectLabel
  xml_accessor :objectCreator
  xml_accessor :citationTitle
  xml_accessor :citationCreator
  xml_accessor :sourceId, :as => SourceId
  xml_accessor :otherIds, :as => [OtherId]
  xml_accessor :agreementId
  xml_accessor :tags, :as => [Tag]

  # Add a new tag to the IdentityMetadata instance
  def add_tag(new_tag_value)
    # Make sure tag is not already present
    for tag in @tags do
      if (tag.value == new_tag_value )
        return
      end
    end
    tag = Tag.new
    tag.value = new_tag_value
    @tags << tag
  end

  # Return the OtherId object for the specified identier name
  def get_other_id(key)
    if (@otherIds != nil)
      for other_id in @otherIds do
        return other_id  if (other_id.name == key)
      end      
    end
    return nil
  end

  # Return the identifier value for the specified identier name
  def get_identifier_value(key)
    other_id = self.get_other_id(key)
    if (other_id != nil)
      return other_id.value
    end
    raise "No #{key} indentifier found for druid #{@objectId}"
  end

  # Add a new name,value pair to the set of identifiers
  def add_identifier(key, value)
    other_id = self.get_other_id(key)
    if (other_id != nil)
      other_id.value = value
    else
      other_id = OtherId.new
      other_id.name = key
      other_id.value = value
      if (@otherIds == nil)
         @otherIds = [other_id]
      else
        @otherIds <<  other_id
      end
    end
  end

  # Return an array of strings where each entry consists of name:value
  def get_id_pairs
    pairs=Array.new
    if (@otherIds != nil)
      @otherIds.each do |other_id|
        pairs << "#{other_id.name}:#{other_id.value}"
      end
    end
    return pairs
  end

end
{'fraction_non_alphanumeric': 0.09346092503987241, 'fraction_numerical': 0.028070175438596492, 'mean_word_length': 3.048418334409296, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 41}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5103750', 'n_tokens_mistral': 2295, 'n_tokens_neox': 2115, 'n_words': 545}