<commit_before>#!/bin/env ruby
#
# Copyright (c) 2012, The University of Queensland. (ITEE eResearch Lab)

require_relative '../cornerstone'

module Thales
  module Datamodel
    module EResearch

      # All Collection, Party, Activity and Service record have the following
      # common convenience methods:
      #
      # * subtype
      # * identifier
      # * title
      # * title_alt
      # * description
      # * tag_keyword
      # * tag_FoR
      # * tag_SEO
      # * contact_email
      # * web_page

      class Base < Thales::Datamodel::Cornerstone::Record

        # Default maximum length for property values

        DEFAULT_MAXLENGTH = 255

        # Base URI for the +TYPE+ constants

        TYPE_BASE_URI = 'http://ns.research.data.uq.edu.au/2012/eResearch/type'

        # Base URI for the subtypes

        SUBTYPE_BASE_URI = 'http://ns.research.data.uq.edu.au/2012/eResearch/subtype'

        # Base URI for the property global identifiers

        PROPERTY_BASE_URI = 'http://ns.research.data.uq.edu.au/2012/eResearch/property'

        # Profile definitions that are merged into the Collection,
        # Party, Activity and Service profiles.

        COMMON_PROFILE_ITEMS = {
          
          :subtype => {
            label: 'Subtype',
            singular: true,
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/subtype"
          },

          :identifier => {
            label: 'Identifier',
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/identifier"
          },

          :title => {
            label: 'Title',
            singular: true,
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/title"
          },
          :title_alt => {
            label: 'Alternative title',
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/title_alt"
          },
          :description => {
            label: 'Description',
            singular: true,
            textarea: true,
            maxlength: 2000, # TODO
            gid: "#{PROPERTY_BASE_URI}/description"
          },

          # Tags

          :tag_keyword => {
            label: 'Keyword',
            maxlength: 32,
            gid: "#{PROPERTY_BASE_URI}/tag_keyword",
          },

          :tag_FoR => {
            label: 'Field of Research (FoR)',
            maxlength: 8,
            gid: "#{PROPERTY_BASE_URI}/tag_FoR",
            is_link: true,
          },

          :tag_SEO => {
            label: 'Socio-Economic Outcomes (SEO)',
            maxlength: 8,
            gid: "#{PROPERTY_BASE_URI}/tag_SEO",
            is_link: true,
          },

          # Other

          :contact_email => {
            label: 'Contact email',
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/contact_email",
          },

          :web_page => {
            label: 'Web page',
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/web_page",
          },
        }

        # Returns a string that can be used as a title for the record.
        #
        # ==== Returns
        #
        # This will be derived from the given and family names for a person,
        # or be the primary title for everything else.

        def display_title

          if (subtype &&
              subtype[0] &&
              subtype[0] == "#{SUBTYPE_BASE_URI}/party/person")
            # People have names
            str = nil

            g = name_given
            if g && ! g.empty?
              str = g[0]
            end

            f = name_family
            if f && ! f.empty?
              if str
                str += " #{f[0]}"
              else
                str = f[0]
              end
            end

            if str
              return str
            end

          else
            # All others have titles

            t = title
            if t
              t = title[0]
              if t
                if t && ! t.blank?
                  return t
                end
              end
            end
          end

          return '(untitled)'
        end

        RIFCS_NS = 'http://ands.org.au/standards/rif-cs/registryObjects'

        # Represents the base properties as RIF-CS.
        #
        # This method is used by the subclasses in their +to_rifcs+
        # methods.
        #
        # ==== Parameters
        #
        # +builder+:: Nokogiri XML builder

        protected
        def base_to_rifcs(builder)

          identifier.each { |x| builder.identifier(x, type: 'uri') }

          if (subtype &&
              subtype[0] &&
              subtype[0] == "#{SUBTYPE_BASE_URI}/party/person")
            # People have name components
            builder.name(type: 'primary') {
              name_prefix.each { |x| builder.namePart(x, type: 'title') }
              name_given.each { |x| builder.namePart(x, type: 'given') }
              name_family.each { |x| builder.namePart(x, type: 'family') }
            }<commit_msg>Fixing RIF-CS identifier type attribute.<commit_after>#!/bin/env ruby
#
# Copyright (c) 2012, The University of Queensland. (ITEE eResearch Lab)

require 'uri'
require_relative '../cornerstone'

module Thales
  module Datamodel
    module EResearch

      # All Collection, Party, Activity and Service record have the following
      # common convenience methods:
      #
      # * subtype
      # * identifier
      # * title
      # * title_alt
      # * description
      # * tag_keyword
      # * tag_FoR
      # * tag_SEO
      # * contact_email
      # * web_page

      class Base < Thales::Datamodel::Cornerstone::Record

        # Default maximum length for property values

        DEFAULT_MAXLENGTH = 255

        # Base URI for the +TYPE+ constants

        TYPE_BASE_URI = 'http://ns.research.data.uq.edu.au/2012/eResearch/type'

        # Base URI for the subtypes

        SUBTYPE_BASE_URI = 'http://ns.research.data.uq.edu.au/2012/eResearch/subtype'

        # Base URI for the property global identifiers

        PROPERTY_BASE_URI = 'http://ns.research.data.uq.edu.au/2012/eResearch/property'

        # Profile definitions that are merged into the Collection,
        # Party, Activity and Service profiles.

        COMMON_PROFILE_ITEMS = {
          
          :subtype => {
            label: 'Subtype',
            singular: true,
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/subtype"
          },

          :identifier => {
            label: 'Identifier',
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/identifier"
          },

          :title => {
            label: 'Title',
            singular: true,
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/title"
          },
          :title_alt => {
            label: 'Alternative title',
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/title_alt"
          },
          :description => {
            label: 'Description',
            singular: true,
            textarea: true,
            maxlength: 2000, # TODO
            gid: "#{PROPERTY_BASE_URI}/description"
          },

          # Tags

          :tag_keyword => {
            label: 'Keyword',
            maxlength: 32,
            gid: "#{PROPERTY_BASE_URI}/tag_keyword",
          },

          :tag_FoR => {
            label: 'Field of Research (FoR)',
            maxlength: 8,
            gid: "#{PROPERTY_BASE_URI}/tag_FoR",
            is_link: true,
          },

          :tag_SEO => {
            label: 'Socio-Economic Outcomes (SEO)',
            maxlength: 8,
            gid: "#{PROPERTY_BASE_URI}/tag_SEO",
            is_link: true,
          },

          # Other

          :contact_email => {
            label: 'Contact email',
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/contact_email",
          },

          :web_page => {
            label: 'Web page',
            maxlength: DEFAULT_MAXLENGTH,
            gid: "#{PROPERTY_BASE_URI}/web_page",
          },
        }

        # Returns a string that can be used as a title for the record.
        #
        # ==== Returns
        #
        # This will be derived from the given and family names for a person,
        # or be the primary title for everything else.

        def display_title

          if (subtype &&
              subtype[0] &&
              subtype[0] == "#{SUBTYPE_BASE_URI}/party/person")
            # People have names
            str = nil

            g = name_given
            if g && ! g.empty?
              str = g[0]
            end

            f = name_family
            if f && ! f.empty?
              if str
                str += " #{f[0]}"
              else
                str = f[0]
              end
            end

            if str
              return str
            end

          else
            # All others have titles

            t = title
            if t
              t = title[0]
              if t
                if t && ! t.blank?
                  return t
                end
              end
            end
          end

          return '(untitled)'
        end

        # Derive the type attribute value for a RIF-CS identifier.

        private
        def identifier_type(id)
          id_type = 'local' # until proven otherwise
          if id =~ %r{^http://nla.gov.au/nla.party-\d+$} ||
             id =~ %r{^nla.party-\d+$}
            id_type = 'AU-ANL:PEAU'
          else
            begin
              uri = URI::parse(id)
              if uri.absolute? &&
                  (id.starts_with?('http://') ||
                   id.starts_with?('https://') ||
                   id.starts_with?('ftp:') ||
                   id.starts_with?('mailto:'))
                id_type = 'uri'
              end
            rescue URI::InvalidURIError
            end
          end

          return id_type
        end

        RIFCS_NS = 'http://ands.org.au/standards/rif-cs/registryObjects'

        # Represents the base properties as RIF-CS.
        #
        # This method is used by the subclasses in their +to_rifcs+
        # methods.
        #
        # ==== Parameters
        #
        # +builder+:: Nokogiri XML builder

        protected
        def base_to_rifcs(builder)

          identifier.each do |x|
            builder.identifier(x, type: identifier_type(x))
          end

          if (subtype &&
              subtype[0] &&
              subtype[0] == "#{SUBTYPE_BASE_URI}/party/person")
            # People have name components
            builder.name(type: 'primary') {
              name_prefix.each { |x| builder.namePart(x, type: 'title') }
              name_given.each { |x| builder.namePart(x, type: 'given') }
              name_family.each { |x| builder.namePart(x, type: 'family') }
            }
{'fraction_non_alphanumeric': 0.1024283366806646, 'fraction_numerical': 0.006390359685959467, 'mean_word_length': 1.3508583690987124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1068931', 'n_tokens_mistral': 3174, 'n_tokens_neox': 2982, 'n_words': 736}