<commit_before>require_relative 'base'

module OpenBEL
  module Resource
    module Annotations

      VOCABULARY_RDF = 'http://www.openbel.org/vocabulary/'

      class AnnotationSerializer < BaseSerializer
        adapter Oat::Adapters::HAL
        schema do
          type :annotation
          properties do |p|
            p.name      item.prefLabel
            p.prefix    item.prefix
            p.domain    item.domain
          end

          link :self,       link_self(item.prefix)
          link :collection, link_collection
        end

        private

        def link_self(id)
          {
            :type => :annotation,
            :href => "#{base_url}/api/annotations/#{id}"
          }
        end

        def link_collection
          {
            :type => :'annotation_collection',
            :href => "#{base_url}/api/annotations"
          }
        end
      end

      class AnnotationResourceSerializer < BaseSerializer
        adapter Oat::Adapters::HAL
        schema do
          type :annotation
          properties do |p|
            p.annotations   item
          end
        end
      end

      class AnnotationCollectionSerializer < BaseSerializer
        adapter Oat::Adapters::HAL
        schema do
          type :'annotation_collection'
          properties do |p|
            p.annotations   item
          end

          link :self,       link_self
          link :start,      link_start(item.first[:prefix])
        end

        private

        def link_self
          {
            :type => :'annotation_collection',
            :href => "#{base_url}/api/annotations"
          }
        end

        def link_start(prefix)
          {
            :type => :function,
            :href => "#{base_url}/api/annotations/#{prefix}"
          }
        end
      end

      class AnnotationValueSerializer < BaseSerializer
        adapter Oat::Adapters::HAL
        schema do
          type :annotation_value

          properties do |p|
            p.type           item.type ? item.type.sub(VOCABULARY_RDF, '') : nil
            p.identifier     item.identifier
            p.name           item.prefLabel
          end

          setup(item)
          link :self,           link_self
          link :collection,     link_annotation
        end

        private

        def setup(item)
          parts = URI(item.uri).path.split('/')[3..-1]
          @annotation_id = parts[0]
          @annotation_value_id = parts.join('/')
        end

        def link_self
          {
            :type => :annotation_value,
            :href => "#{base_url}/api/annotations/#{@annotation_value_id}"
          }
        end

        def link_annotation
          {
            :type => :annotation,
            :href => "#{base_url}/api/annotations/#{@annotation_id}"
          }
        end
      end

      class AnnotationValueResourceSerializer < BaseSerializer
        adapter Oat::Adapters::HAL
        schema do
          type :annotation_value
          properties do |p|
            p.annotation_values item<commit_msg>fix "self" computed property for annotation values<commit_after>require_relative 'base'

module OpenBEL
  module Resource
    module Annotations

      VOCABULARY_RDF = 'http://www.openbel.org/vocabulary/'

      class AnnotationSerializer < BaseSerializer
        adapter Oat::Adapters::HAL
        schema do
          type :annotation
          properties do |p|
            p.name      item.prefLabel
            p.prefix    item.prefix
            p.domain    item.domain
          end

          link :self,       link_self(item.prefix)
          link :collection, link_collection
        end

        private

        def link_self(id)
          {
            :type => :annotation,
            :href => "#{base_url}/api/annotations/#{id}"
          }
        end

        def link_collection
          {
            :type => :'annotation_collection',
            :href => "#{base_url}/api/annotations"
          }
        end
      end

      class AnnotationResourceSerializer < BaseSerializer
        adapter Oat::Adapters::HAL
        schema do
          type :annotation
          properties do |p|
            p.annotations   item
          end
        end
      end

      class AnnotationCollectionSerializer < BaseSerializer
        adapter Oat::Adapters::HAL
        schema do
          type :'annotation_collection'
          properties do |p|
            p.annotations   item
          end

          link :self,       link_self
          link :start,      link_start(item.first[:prefix])
        end

        private

        def link_self
          {
            :type => :'annotation_collection',
            :href => "#{base_url}/api/annotations"
          }
        end

        def link_start(prefix)
          {
            :type => :function,
            :href => "#{base_url}/api/annotations/#{prefix}"
          }
        end
      end

      class AnnotationValueSerializer < BaseSerializer
        adapter Oat::Adapters::HAL
        schema do
          type :annotation_value

          properties do |p|
            p.type           item.type ? item.type.sub(VOCABULARY_RDF, '') : nil
            p.identifier     item.identifier
            p.name           item.prefLabel
          end

          setup(item)
          link :self,           link_self
          link :collection,     link_annotation
        end

        private

        def setup(item)
          @annotation_id, @annotation_value_id = URI(item.uri).path.split('/')[3..-1]
        end

        def link_self
          {
            :type => :annotation_value,
            :href => "#{base_url}/api/annotations/#{@annotation_id}/values/#{@annotation_value_id}"
          }
        end

        def link_annotation
          {
            :type => :annotation,
            :href => "#{base_url}/api/annotations/#{@annotation_id}"
          }
        end
      end

      class AnnotationValueResourceSerializer < BaseSerializer
        adapter Oat::Adapters::HAL
        schema do
          type :annotation_value
          properties do |p|
            p.annotation_values item
{'fraction_non_alphanumeric': 0.08517915309446254, 'fraction_numerical': 0.0008143322475570033, 'mean_word_length': 1.4215299684542586, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2458860', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1559, 'n_words': 352}