<commit_before>module GoodData
  class MdObject
    MD_OBJ_CTG = 'obj'
    IDENTIFIERS_CFG = 'instance-identifiers'

    class << self
      def [](id)
        if id.is_a? Integer or id =~ /^\d+$/
          uri = "#{GoodData.project.md.link(MD_OBJ_CTG)}/#{id}"
        elsif id !~ /\//
          uri = identifier_to_uri id
        elsif id =~ /^\//
          uri = id
        else
          raise "Unexpected object id format: expected numeric ID, identifier with no slashes or an URI starting with a slash"
        end
        MdObject.new GoodData.get uri
      end

      private

      def identifier_to_uri(id)
        uri      = GoodData.project.md[IDENTIFIERS_CFG]
        response = GoodData.post uri, { 'identifierToUri' => [id ] }
        response['identifiers'][0]['uri']
      end
    end

    def initialize(json)
      @json = json
    end

    def delete
      raise "Project '#{title}' with id #{uri} is already deleted" if state == :deleted
      GoodData.delete @json['links']['self']
    end

    def uri
      @json['links']['self'] if @json['links'] && @json['links']['self']
    end

    def title
      data['meta']['title']
    end

    def meta
      data['meta']
    end

    def content
      data['content']
    end

    private

    def data
      first_key = @json.keys[0]
      @json[first_key]
    end
  end

  class DataSet < MdObject
    SLI_CTG = 'singleloadinterface'
    DS_SLI_CTG = 'dataset-singleloadinterface'

    def sli
      GoodData.project.md.links(GoodData::Model::LDM_CTG).links(SLI_CTG)[]
    end
  end
end<commit_msg>CODE: MD object's identifier and owning project exposed<commit_after>module GoodData
  class MdObject
    MD_OBJ_CTG = 'obj'
    IDENTIFIERS_CFG = 'instance-identifiers'

    class << self
      def [](id)
        if id.is_a? Integer or id =~ /^\d+$/
          uri = "#{GoodData.project.md.link(MD_OBJ_CTG)}/#{id}"
        elsif id !~ /\//
          uri = identifier_to_uri id
        elsif id =~ /^\//
          uri = id
        else
          raise "Unexpected object id format: expected numeric ID, identifier with no slashes or an URI starting with a slash"
        end
        MdObject.new GoodData.get uri
      end

      private

      def identifier_to_uri(id)
        uri      = GoodData.project.md[IDENTIFIERS_CFG]
        response = GoodData.post uri, { 'identifierToUri' => [id ] }
        response['identifiers'][0]['uri']
      end
    end

    def initialize(json)
      @json = json
    end

    def delete
      raise "Project '#{title}' with id #{uri} is already deleted" if state == :deleted
      GoodData.delete @json['links']['self']
    end

    def uri
      meta['uri']
    end

    def identifier
      meta['identifier']
    end

    def title
      meta['title']
    end

    def meta
      data['meta']
    end

    def content
      data['content']
    end

    def project
      @project ||= GoodData::Project[uri.gsub /\/obj\/\d+$/, '']
    end

    private

    def data
      first_key = @json.keys[0]
      @json[first_key]
    end
  end

  class DataSet < MdObject
    SLI_CTG = 'singleloadinterface'
    DS_SLI_CTG = 'dataset-singleloadinterface'

    def sli
      GoodData.project.md.links(GoodData::Model::LDM_CTG).links(SLI_CTG)[DS_SLI_CTG]
    end
  end
end
{'fraction_non_alphanumeric': 0.11566707466340269, 'fraction_numerical': 0.0012239902080783353, 'mean_word_length': 2.0956439393939394, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '4128404', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1042, 'n_words': 271}