module Myasorubka::Mystem::Binary

A wrapper around mystem's internal binary format.

Constants

GRAMMEMES

github.com/yandex/tomita-parser/blob/master/src/library/lemmer/dictlib/yx_gram_enum.h

Public Instance Methods

to_msd(grammemes) click to toggle source

Convert an array with mystem grammeme codes into a MSD.

# File lib/myasorubka/mystem/binary.rb, line 97
def to_msd(grammemes)
  msd = Myasorubka::MSD.new(Myasorubka::MSD::Russian)

  grammemes.sort.each do |code|
    case GRAMMEMES[code]
    # Nomenus
    when :postposition then msd[:pos] = :adposition
    when :adjective then msd[:pos] = :adjective; msd[:type] = :qualificative; msd[:degree] = :positive
    when :adverb then msd[:pos] = :adverb
    when :conjunction then msd[:pos] = :conjunction
    when :interjunction then msd[:pos] = :interjection
    when :numeral then msd[:pos] = :numeral; msd[:type] = :cardinal
    when :particle then msd[:pos] = :particle
    when :preposition then msd[:pos] = :adposition; msd[:type] = :preposition
    when :substantive then msd[:pos] = :noun; msd[:type] = :common
    when :verb then msd[:pos] = :verb; msd[:type] = :main
    when :adj_numeral then msd[:pos] = :numeral; msd[:type] = :ordinal
    when :adj_pronoun then msd[:pos] = :pronoun; msd[:syntactic_type] = :adjectival
    when :adv_pronoun then msd[:pos] = :pronoun; msd[:syntactic_type] = :adverbial
    when :subst_pronoun then msd[:pos] = :pronoun; msd[:syntactic_type] = :nominal
    when :abbreviation then msd[:pos] = :abbreviation
    when :first_name then msd[:type] = :proper
    when :surname then msd[:type] = :proper
    when :patronymic then msd[:type] = :proper
    when :geo then msd[:type] = :proper
    when :proper then msd[:type] = :proper
    # Tempus
    when :present then msd[:tense] = :present
    # TODO: how to handle :notpast tense?
    when :past then msd[:tense] = :past
    when :future then msd[:tense] = :future
    when :past2 then msd[:tense] = :past
    # Casus
    when :nominative then msd[:case] = :nominative
    when :genitive then msd[:case] = :genitive
    when :dative then msd[:case] = :dative
    when :accusative then msd[:case] = :accusative
    when :instrumental then msd[:case] = :instrumental
    when :ablative then msd[:case] = :genitive
    when :partitive then msd[:case] = :genitive; msd[:case2] = :partitive
    when :locative then msd[:case] = :genitive; msd[:case2] = :locative
    when :vocative then msd[:case] = :vocative
    # Numerus
    when :singular then msd[:number] = :singular
    when :plural then msd[:number] = :plural
    # Modus
    when :gerund then msd[:vform] = :gerund
    when :infinitive then msd[:vform] = :infinitive
    when :participle then msd[:vform] = :participle
    when :indicative then msd[:vform] = :indicative
    when :imperative then msd[:vform] = :imperative
    when :conditional then msd[:vform] = :conditional
    # Gradus
    when :short then msd[:definiteness] = :short_art
    when :full then msd[:definiteness] = :full_art
    when :superlative then msd[:degree] = :superlative
    when :comparative then msd[:degree] = :comparative
    when :possessive then msd[:type] = :possessive
    # Personae
    when :person1 then msd[:person] = :first
    when :person2 then msd[:person] = :second
    when :person3 then msd[:person] = :third
    # Gender
    when :feminine then msd[:gender] = :feminine
    when :masculine then msd[:gender] = :masculine
    when :neuter then msd[:gender] = :neuter
    when :mas_fem then msd[:gender] = :common
    # Perfectum-Imperfectum
    when :perfect then msd[:aspect] = :perfective
    when :imperfect then msd[:aspect] = :progressive
    # Voice
    when :passive then msd[:voice] = :passive
    when :active then msd[:voice] = :active
    when :reflexive then msd[:type] = :reflexive
    # Animated
    when :animated then msd[:animate] = :yes
    when :inanimated then msd[:animate] = :no
    # Transitivity
    when :definite then msd[:definiteness] = :full_art
    when :indefinite then msd[:definiteness] = :short_art
    # Definiteness
    when :sim_conj then msd[:type] = :coordinating
    when :sub_conj then msd[:type] = :subordinating
    when :aux_verb then msd[:type] = :auxiliary
    else
    end
  end

  msd.prune!
end