class PROIEL::AnnotationSchema

A representation of the annotation schema found in the header of a PROIEL XML file. This should not be confused with the PROIEL XML schema, which is used for validating the XML in a PROIEL XML file.

Attributes

information_status_tags[R]

@return [Hash<String,InformationStatusTagDefinition>] definition of information status tags

morphology_tags[R]

@return [Hash<Symbol,Hash<String,MorphologyFieldTagDefinition>>] definition of morphology tags

part_of_speech_tags[R]

@return [Hash<String,PartOfSpeechTagDefinition>] definition of part of speech tags

relation_tags[R]

@return [Hash<String,RelationTagDefinition>] definition of relation tags

Public Class Methods

new(xml_object) click to toggle source

Creates a new annotation schema object.

# File lib/proiel/annotation_schema.rb, line 24
def initialize(xml_object)
  if xml_object
    @part_of_speech_tags = make_part_of_speech_tags(xml_object).freeze
    @relation_tags = make_relation_tags(xml_object).freeze
    @morphology_tags = make_morphology_tags(xml_object).freeze
    @information_status_tags = make_information_status_tags(xml_object).freeze
  else
    @part_of_speech_tags = {}.freeze
    @relation_tags = {}.freeze
    @morphology_tags = {}.freeze
    @information_status_tags = {}.freeze
  end
end

Public Instance Methods

==(o) click to toggle source

Tests for equality of two annotation schema objects.

@return [true,false]

# File lib/proiel/annotation_schema.rb, line 52
def ==(o)
  @part_of_speech_tags.sort_by(&:first) == o.part_of_speech_tags.sort_by(&:first) and
    @relation_tags.sort_by(&:first) == o.relation_tags.sort_by(&:first)
end
primary_relations() click to toggle source

@return [Hash<String,RelationTagDefinition>] definition of primary relation tags

# File lib/proiel/annotation_schema.rb, line 39
def primary_relations
  @relation_tags.select { |_, features| features.primary }
end
secondary_relations() click to toggle source

@return [Hash<String,RelationTagDefinition>] definition of secondary relation tags

# File lib/proiel/annotation_schema.rb, line 44
def secondary_relations
  @relation_tags.select { |_, features| features.secondary }
end

Private Instance Methods

make_information_status_tags(xml_object) click to toggle source
# File lib/proiel/annotation_schema.rb, line 85
def make_information_status_tags(xml_object)
  make_tag_hash(xml_object.information_statuses) do |e|
    InformationStatusTagDefinition.new(e.summary)
  end
end
make_morphology_tags(xml_object) click to toggle source
# File lib/proiel/annotation_schema.rb, line 75
def make_morphology_tags(xml_object)
  xml_object.morphology.fields.map do |f|
    v =
      make_tag_hash(f) do |e|
        MorphologyFieldTagDefinition.new(e.summary)
      end
    [f.tag, v]
  end.to_h
end
make_part_of_speech_tags(xml_object) click to toggle source
# File lib/proiel/annotation_schema.rb, line 69
def make_part_of_speech_tags(xml_object)
  make_tag_hash(xml_object.parts_of_speech) do |e|
    PartOfSpeechTagDefinition.new(e.summary)
  end
end
make_relation_tags(xml_object) click to toggle source
# File lib/proiel/annotation_schema.rb, line 63
def make_relation_tags(xml_object)
  make_tag_hash(xml_object.relations) do |e|
    RelationTagDefinition.new(e.summary, e.primary == 'true', e.secondary == 'true')
  end
end
make_tag_hash(element) { |e| ... } click to toggle source
# File lib/proiel/annotation_schema.rb, line 59
def make_tag_hash(element)
  element.values.map { |e| [e.tag, yield(e)] }.compact.to_h
end