Class: Glossarist::Rdf::GlossLocalizedConcept

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Includes:
EmitsExtraTriples
Defined in:
lib/glossarist/rdf/gloss_localized_concept.rb

Constant Summary collapse

SKOS_PREF_LABEL =
RDF::URI("http://www.w3.org/2004/02/skos/core#prefLabel")
SKOS_ALT_LABEL =
RDF::URI("http://www.w3.org/2004/02/skos/core#altLabel")
SKOS_HIDDEN_LABEL =
RDF::URI("http://www.w3.org/2004/02/skos/core#hiddenLabel")
SKOS_DEFINITION =
RDF::URI("http://www.w3.org/2004/02/skos/core#definition")
SKOS_SCOPE_NOTE =
RDF::URI("http://www.w3.org/2004/02/skos/core#scopeNote")
SKOS_EXAMPLE =
RDF::URI("http://www.w3.org/2004/02/skos/core#example")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.rdf_literal(value, lang) ⇒ Object



130
131
132
133
134
135
136
137
138
# File 'lib/glossarist/rdf/gloss_localized_concept.rb', line 130

def rdf_literal(value, lang)
  return RDF::Literal.new("") if value.nil?

  if lang
    RDF::Literal.new(value.to_s, language: lang)
  else
    RDF::Literal.new(value.to_s)
  end
end

.skos_label_predicate(designation) ⇒ Object



121
122
123
124
125
126
127
128
# File 'lib/glossarist/rdf/gloss_localized_concept.rb', line 121

def skos_label_predicate(designation)
  status = designation.normative_status.to_s.split("/").last
  case status
  when "preferred" then SKOS_PREF_LABEL
  when "deprecated" then SKOS_HIDDEN_LABEL
  else SKOS_ALT_LABEL
  end
end

.skosxl_label_for(designation) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/glossarist/rdf/gloss_localized_concept.rb', line 77

def self.skosxl_label_for(designation)
  status = designation.normative_status.to_s.split("/").last
  case status
  when "preferred" then "skosxl:prefLabel"
  when "deprecated" then "skosxl:hiddenLabel"
  else "skosxl:altLabel"
  end
end

Instance Method Details

#emit_extra_triples(subject_uri, _mapping) ⇒ Object

Hook invoked by Glossarist::Rdf::LutamlTurtleTransformExt. Emits direct SKOS predicates alongside the reified SKOS-XL / gloss forms, so consumers that only speak plain SKOS (no SKOS-XL) see the labels, definitions, notes, and examples as plain literals.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/glossarist/rdf/gloss_localized_concept.rb', line 90

def emit_extra_triples(subject_uri, _mapping)
  lang = language_code.to_s if language_code && !language_code.to_s.empty?
  triples = []

  Array(designations).each do |desig|
    predicate = self.class.skos_label_predicate(desig)
    next unless predicate

    triples << RDF::Statement.new(subject_uri, predicate,
                                  self.class.rdf_literal(desig.designation, lang))
  end

  Array(definitions).each do |d|
    triples << RDF::Statement.new(subject_uri, SKOS_DEFINITION,
                                  self.class.rdf_literal(d.content, lang))
  end

  Array(notes).each do |n|
    triples << RDF::Statement.new(subject_uri, SKOS_SCOPE_NOTE,
                                  self.class.rdf_literal(n.content, lang))
  end

  Array(examples).each do |e|
    triples << RDF::Statement.new(subject_uri, SKOS_EXAMPLE,
                                  self.class.rdf_literal(e.content, lang))
  end

  triples
end