Class: Osgeo::Termbase::Term
- Inherits:
-
Object
- Object
- Osgeo::Termbase::Term
- Defined in:
- lib/osgeo/termbase/term.rb
Constant Summary collapse
- INPUT_ATTRIBS =
i( id term abbrev synonyms alt domain definition country_code language_code notes examples entry_status type comments classification review_indicator lineage_source lineage_source_similarity date_accepted date_amended review_date review_status review_type review_decision review_decision_date review_decision_event review_decision_notes release )
- OUTPUT_ATTRIBS =
INPUT_ATTRIBS - i(term alt classification) + i(terms)
- STRIP_PUNCTUATION =
[ ":", ":", ".", "–", "\-" ]
- EXAMPLE_PREFIXES =
WARNING Always put the longer Regexp match in front!
{ # TODO: fix this, we should not have "EXAMPLES" eng: ["EXAMPLES", "EXAMPLE"], ara: "مثال", chi: "示例", dan: "EKSEMPEL", dut: ["VOORBEELD", "VOORBEELDEN"], fin: "ESIM", fre: "Exemple", # ger: "", jpn: "例", kor: "보기", pol: "PRZYKŁAD", may: "Contoh", rus: "Пример", spa: "Ejemplo", swe: "Exempel" }
- NOTE_PREFIXES =
WARNING Always put the longer Regexp match in front!
{ eng: ["Note \\d to entry", "NOTE"], ara: "ملاحظة", chi: "注", dan: "Note", dut: "OPMERKING", fin: "HUOM\\.?", # Matches "HUOM", "HUOM.", "HUOM 1." and "HUOM. 1." (numeral added by the method) fre: "A noter", # ger: "", jpn: "備考", kor: "비고", pol: "UWAGA", may: "catatan", rus: "нота", spa: "Nota", swe: ["Anm. \\d till termpost", "Anm. \\d till terpost", "Anm."] }
- ALL_FULL_HALF_WIDTH_NUMBERS =
To match Chinese and Japanese numerals
"[0-90-9]"
Instance Method Summary collapse
- #add_example(example) ⇒ Object
- #add_note(note) ⇒ Object
- #alt_term_hash ⇒ Object
-
#authoritative_source_similarity=(value) ⇒ Object
lineage-source-similarity ## Must be one of the following codes: identical = 1 restyled = 2 context added = 3 generalisation = 4 specialisation = 5 unspecified = 6“,.
-
#classification=(value) ⇒ Object
classification Must be one of the following: preferred admitted deprecated.
- #clean_prefixed_string(string, criterion_map) ⇒ Object
-
#domain=(value) ⇒ Object
OSGEO SPECIFIC domain Must be one of term, abbrev, soft, other, check.
-
#entry_status=(value) ⇒ Object
entry-status Must be one of notValid valid superseded retired.
-
#id=(newid) ⇒ Object
The termid should ALWAYS be an integer.
-
#initialize(options = {}) ⇒ Term
constructor
A new instance of Term.
- #primary_term_hash ⇒ Object
- #retired? ⇒ Boolean
-
#review_decision=(value) ⇒ Object
Must be one of withdrawn, accepted notAccepted.
-
#review_indicator=(value) ⇒ Object
review-indicator Must be one of the following <empty field> Under Review in Source Document“,.
-
#review_status=(value) ⇒ Object
Must be one of pending tentative final.
-
#review_type=(value) ⇒ Object
Must be one of supersession, retirement.
- #terms ⇒ Object
- #to_hash ⇒ Object
-
#type=(value) ⇒ Object
OSGEO SPECIFIC type Must be one of term, abbrev, soft, other, check.
Constructor Details
#initialize(options = {}) ⇒ Term
Returns a new instance of Term.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/osgeo/termbase/term.rb', line 42 def initialize(={}) @examples = [] @notes = [] # puts "options #{options.inspect}" .each_pair do |k, v| key = k.to_s v = v.strip if v.is_a?(String) next unless v case key when /^example/ add_example(v) when /^note/ add_note(v) else # puts"Key #{k}" key = key.gsub("-", "_") self.send("#{key}=", v) end end self end |
Instance Method Details
#add_example(example) ⇒ Object
118 119 120 121 |
# File 'lib/osgeo/termbase/term.rb', line 118 def add_example(example) c = clean_prefixed_string(example, EXAMPLE_PREFIXES) @examples << c unless c.empty? end |
#add_note(note) ⇒ Object
123 124 125 126 |
# File 'lib/osgeo/termbase/term.rb', line 123 def add_note(note) c = clean_prefixed_string(note, NOTE_PREFIXES) @notes << c unless c.empty? end |
#alt_term_hash ⇒ Object
287 288 289 290 291 292 293 |
# File 'lib/osgeo/termbase/term.rb', line 287 def alt_term_hash { "type" => "expression", "designation" => alt, "normative_status" => classification, } if alt end |
#authoritative_source_similarity=(value) ⇒ Object
lineage-source-similarity
## Must be one of the following codes: identical = 1 restyled = 2 context added = 3 generalisation = 4 specialisation = 5 unspecified = 6",
234 235 236 237 238 239 |
# File 'lib/osgeo/termbase/term.rb', line 234 def (value) unless (1..6).include?(value) value = 6 end = value end |
#classification=(value) ⇒ Object
classification Must be one of the following: preferred admitted deprecated
209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/osgeo/termbase/term.rb', line 209 def classification=(value) case value when "" value = "admitted" when "认可的", "допустимый", "admitido" value = "admitted" when "首选的", "suositettava", "suositeltava", "рекомендуемый", "preferente" value = "preferred" when %w(preferred admitted deprecated) # do nothing end @classification = value end |
#clean_prefixed_string(string, criterion_map) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/osgeo/termbase/term.rb', line 128 def clean_prefixed_string(string, criterion_map) carry = string.strip criterion_map.values.flatten.each do |mat| # puts "example string: #{carry}, mat: #{mat}" # puts "note string: #{carry}, mat: #{mat}" # if @id == 318 and mat == "Nota" and string == "NOTA 1 Una operación tiene un nombre y una lista de parámetros." # require "pry" # binding.pry # end # Arabic notes/examples sometimes use parantheses around numbers carry = carry.sub( Regexp.new( "^#{mat}\s*[#{STRIP_PUNCTUATION.join('')}]?" + "\s*\\(?#{ALL_FULL_HALF_WIDTH_NUMBERS}*\\)?\s*"+ "[#{STRIP_PUNCTUATION.join('')}]?\s*", Regexp::IGNORECASE ), '') end carry end |
#domain=(value) ⇒ Object
OSGEO SPECIFIC domain Must be one of term, abbrev, soft, other, check
184 185 186 187 188 189 |
# File 'lib/osgeo/termbase/term.rb', line 184 def domain=(value) @domain = case value.to_s when "concept", "org_acedemic", "org_indus", "org_intl", "org_govt" value.to_s end end |
#entry_status=(value) ⇒ Object
entry-status Must be one of notValid valid superseded retired
193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/osgeo/termbase/term.rb', line 193 def entry_status=(value) case value when "有效的", "käytössä", "действующий", "válido" value = "valid" when "korvattu", "reemplazado" value = "superseded" when "информация отсутствует" # "information absent"!? value = "retired" when %w(notValid valid superseded retired) # do nothing end @entry_status = value end |
#id=(newid) ⇒ Object
The termid should ALWAYS be an integer. github.com/riboseinc/osgeo-termbase/issues/1
156 157 158 |
# File 'lib/osgeo/termbase/term.rb', line 156 def id=(newid) @id = Integer(newid) end |
#primary_term_hash ⇒ Object
279 280 281 282 283 284 285 |
# File 'lib/osgeo/termbase/term.rb', line 279 def primary_term_hash { "type" => "expression", "designation" => term, "normative_status" => classification, } if term end |
#retired? ⇒ Boolean
271 272 273 |
# File 'lib/osgeo/termbase/term.rb', line 271 def retired? release >= 0 end |
#review_decision=(value) ⇒ Object
Must be one of withdrawn, accepted notAccepted
264 265 266 267 268 269 |
# File 'lib/osgeo/termbase/term.rb', line 264 def review_decision=(value) ## Must be one of withdrawn, accepted notAccepted unless ["", "withdrawn", "accepted", "notAccepted"].include?(value) value = "" end @review_decision = value end |
#review_indicator=(value) ⇒ Object
review-indicator Must be one of the following <empty field> Under Review in Source Document“,
225 226 227 228 229 230 |
# File 'lib/osgeo/termbase/term.rb', line 225 def review_indicator=(value) unless ["", "Under Review in Source Document"].include?(value) value = "" end @review_indicator = value end |
#review_status=(value) ⇒ Object
Must be one of pending tentative final
250 251 252 253 254 255 |
# File 'lib/osgeo/termbase/term.rb', line 250 def review_status=(value) ## Must be one of pending tentative final unless ["", "pending", "tentative", "final"].include?(value) value = "" end @review_status = value end |
#review_type=(value) ⇒ Object
Must be one of supersession, retirement
257 258 259 260 261 262 |
# File 'lib/osgeo/termbase/term.rb', line 257 def review_type=(value) ## Must be one of supersession, retirement unless ["", "supersession", "retirement"].include?(value) value = "" end @review_type = value end |
#terms ⇒ Object
275 276 277 |
# File 'lib/osgeo/termbase/term.rb', line 275 def terms [primary_term_hash, alt_term_hash].compact end |
#to_hash ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/osgeo/termbase/term.rb', line 160 def to_hash OUTPUT_ATTRIBS.inject({}) do |acc, attrib| value = self.send(attrib) unless value.nil? acc.merge(attrib.to_s => value) else acc end end end |
#type=(value) ⇒ Object
OSGEO SPECIFIC type Must be one of term, abbrev, soft, other, check
174 175 176 177 178 179 |
# File 'lib/osgeo/termbase/term.rb', line 174 def type=(value) @type = case value.to_s when "term", "abbrev", "soft", "other", "check" value.to_s end end |