Class: Termium::TextualSupport

Inherits:
Shale::Mapper
  • 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



64
65
66
67
68
# File 'lib/termium/textual_support.rb', line 64

def domain
  return unless has_domain?

  value_cleaned.match(DEFINITION_REGEX)[1]
end

#has_domain?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/termium/textual_support.rb', line 60

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

#is_definition?Boolean

Returns:

  • (Boolean)


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

def is_definition?
  type == "DEF"
end

#is_example?Boolean

Returns:

  • (Boolean)


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

def is_example?
  value_cleaned.match(EXAMPLE_REGEX)
end

#is_note?Boolean

Returns:

  • (Boolean)


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

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

#is_observation?Boolean

Returns:

  • (Boolean)


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

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>>].



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

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



56
57
58
# File 'lib/termium/textual_support.rb', line 56

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

#value_exampleObject



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

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