Class: Termium::TextualSupport

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/termium/textual_support.rb

Overview

For <textualSupport>

Constant Summary collapse

EXAMPLE_REGEX =
/\AEx[ea]mples?\s*:\s*/.freeze
DEFINITION_REGEX =
/\A<(.+?)>\s*/.freeze

Instance Method Summary collapse

Instance Method Details

#domainObject



66
67
68
69
70
# File 'lib/termium/textual_support.rb', line 66

def domain
  return unless has_domain?

  value_cleaned.match(DEFINITION_REGEX)[1]
end

#has_domain?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/termium/textual_support.rb', line 62

def has_domain?
  !value_cleaned.match(DEFINITION_REGEX).nil?
end

#is_definition?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/termium/textual_support.rb', line 40

def is_definition?
  type == "DEF"
end

#is_example?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/termium/textual_support.rb', line 36

def is_example?
  value_cleaned.match(EXAMPLE_REGEX)
end

#is_note?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/termium/textual_support.rb', line 44

def is_note?
  !is_definition? && !is_example?
end

#is_observation?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/termium/textual_support.rb', line 48

def is_observation?
  type == "OBS"
end

#source_from_noteObject

This is an attempt to extract the textual reference within the note. TODO: Use this to correlate the actual term with the source reference, i.e from the following note, the terms “abduction; inférence abductive” come from “ISO-IEC-2382-28-1995”. NOTE: abduction; inférence abductive : termes et définition normalisés par l’ISO/CEI [<<ISO-IEC-2382-28-1995>>].



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/termium/textual_support.rb', line 77

def source_from_note
  x = note.match(/\[.*\]/)
  return nil if x.nil?

  ref = x.match(/\[.*\]/).to_s.gsub(/[\[\]]/, "")

  # "[ISO/IEC 2382-13:1996; ISO/IEC 2382-24:1995]"
  if ref.include?(";")
    ref.split("; ")
  else
    [ref]
  end
end

#value_cleanedObject



20
21
22
# File 'lib/termium/textual_support.rb', line 20

def value_cleaned
  value.gsub(/\n\s+/, " ")
end

#value_definitionObject



58
59
60
# File 'lib/termium/textual_support.rb', line 58

def value_definition
  value_cleaned.gsub(DEFINITION_REGEX, "")
end

#value_exampleObject



52
53
54
# File 'lib/termium/textual_support.rb', line 52

def value_example
  value_cleaned.gsub(EXAMPLE_REGEX, "")
end

#value_typedObject



24
25
26
27
28
29
30
31
32
# File 'lib/termium/textual_support.rb', line 24

def value_typed
  if is_example?
    value_example
  elsif is_definition?
    value_definition
  else
    value_cleaned
  end
end