Class: Stepmod::Utils::TermsExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/stepmod/utils/terms_extractor.rb

Constant Summary collapse

ACCEPTED_STAGES =

TODO: we may want a command line option to override this in the future

%w(IS DIS FDIS TS).freeze
WITHDRAWN_STATUS =
"withdrawn".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stepmod_dir, index_path, stdout) ⇒ TermsExtractor

Returns a new instance of TermsExtractor.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/stepmod/utils/terms_extractor.rb', line 35

def initialize(stepmod_dir, index_path, stdout)
  @stdout = stdout
  @stepmod_dir = stepmod_dir
  @stepmod_path = Pathname.new(stepmod_dir).realpath
  @index_path = Pathname.new(index_path).to_s
  @general_concepts = Glossarist::Collection.new
  @resource_concepts = Glossarist::Collection.new
  @parsed_bibliography = []
  @part_concepts = []
  @part_resources = []
  @part_modules = []
  @encountered_terms = {}
end

Instance Attribute Details

#encountered_termsObject (readonly)

Returns the value of attribute encountered_terms.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def encountered_terms
  @encountered_terms
end

#general_conceptsObject (readonly)

Returns the value of attribute general_concepts.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def general_concepts
  @general_concepts
end

#index_pathObject (readonly)

Returns the value of attribute index_path.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def index_path
  @index_path
end

#parsed_bibliographyObject (readonly)

Returns the value of attribute parsed_bibliography.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def parsed_bibliography
  @parsed_bibliography
end

#part_conceptsObject (readonly)

Returns the value of attribute part_concepts.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def part_concepts
  @part_concepts
end

#part_modulesObject (readonly)

Returns the value of attribute part_modules.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def part_modules
  @part_modules
end

#part_resourcesObject (readonly)

Returns the value of attribute part_resources.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def part_resources
  @part_resources
end

#resource_conceptsObject (readonly)

Returns the value of attribute resource_concepts.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def resource_concepts
  @resource_concepts
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def stdout
  @stdout
end

#stepmod_dirObject (readonly)

Returns the value of attribute stepmod_dir.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def stepmod_dir
  @stepmod_dir
end

#stepmod_pathObject (readonly)

Returns the value of attribute stepmod_path.



19
20
21
# File 'lib/stepmod/utils/terms_extractor.rb', line 19

def stepmod_path
  @stepmod_path
end

Class Method Details

.call(stepmod_dir, index_path, stdout = $stdout) ⇒ Object



31
32
33
# File 'lib/stepmod/utils/terms_extractor.rb', line 31

def self.call(stepmod_dir, index_path, stdout = $stdout)
  new(stepmod_dir, index_path, stdout).call
end

Instance Method Details

#callObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
# File 'lib/stepmod/utils/terms_extractor.rb', line 64

def call
  log "INFO: STEPmod directory set to #{stepmod_dir}."
  log "INFO: Detecting paths..."

  repo_index = Nokogiri::XML(File.read(@index_path)).root

  files = []

  # add module paths
  repo_index.xpath("//module").each do |x|
    next if x['status'] == WITHDRAWN_STATUS

    path = Pathname.new("#{stepmod_dir}/modules/#{x['name']}/module.xml")
    files << path if File.exists? path
  end

  # add resource_docs paths
  repo_index.xpath("//resource_doc").each do |x|
    next if x['status'] == WITHDRAWN_STATUS

    path = Pathname.new("#{stepmod_dir}/resource_docs/#{x['name']}/resource.xml")
    files << path if File.exists? path
  end

  # add business_object_models paths
  repo_index.xpath("//business_object_model").each do |x|
    next if x['status'] == WITHDRAWN_STATUS

    path = Pathname.new("#{stepmod_dir}/business_object_models/#{x['name']}/business_object_model.xml")
    files << path if File.exists? path
  end

  # add application_protocols paths
  repo_index.xpath("//application_protocol").each do |x|
    next if x['status'] == WITHDRAWN_STATUS

    path = Pathname.new("#{stepmod_dir}/application_protocols/#{x['name']}/application_protocol.xml")
    files << path if File.exists? path
  end

  files.sort!.uniq!
  process_term_files(files)

  [
    general_concepts,
    resource_concepts,
    parsed_bibliography,
    part_concepts,
    part_resources,
    part_modules,
  ]
end

#log(message) ⇒ Object



49
50
51
# File 'lib/stepmod/utils/terms_extractor.rb', line 49

def log(message)
  stdout.puts "[stepmod-utils] #{message}"
end

#term_special_category(bibdata) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/stepmod/utils/terms_extractor.rb', line 53

def term_special_category(bibdata)
  case bibdata.part.to_i
  when 41, 42, 43, 44, 45, 46, 47, 51
    true
  when [56..112]
    true
  else
    false
  end
end