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, stdout) ⇒ TermsExtractor

Returns a new instance of TermsExtractor.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/stepmod/utils/terms_extractor.rb', line 32

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

Instance Attribute Details

#cvs_modeObject (readonly)

Returns the value of attribute cvs_mode.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def cvs_mode
  @cvs_mode
end

#encountered_termsObject (readonly)

Returns the value of attribute encountered_terms.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def encountered_terms
  @encountered_terms
end

#general_conceptsObject (readonly)

Returns the value of attribute general_concepts.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def general_concepts
  @general_concepts
end

#parsed_bibliographyObject (readonly)

Returns the value of attribute parsed_bibliography.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def parsed_bibliography
  @parsed_bibliography
end

#part_conceptsObject (readonly)

Returns the value of attribute part_concepts.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def part_concepts
  @part_concepts
end

#part_modulesObject (readonly)

Returns the value of attribute part_modules.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def part_modules
  @part_modules
end

#part_resourcesObject (readonly)

Returns the value of attribute part_resources.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def part_resources
  @part_resources
end

#resource_conceptsObject (readonly)

Returns the value of attribute resource_concepts.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def resource_concepts
  @resource_concepts
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def stdout
  @stdout
end

#stepmod_dirObject (readonly)

Returns the value of attribute stepmod_dir.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def stepmod_dir
  @stepmod_dir
end

#stepmod_pathObject (readonly)

Returns the value of attribute stepmod_path.



16
17
18
# File 'lib/stepmod/utils/terms_extractor.rb', line 16

def stepmod_path
  @stepmod_path
end

Class Method Details

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



28
29
30
# File 'lib/stepmod/utils/terms_extractor.rb', line 28

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

Instance Method Details

#callObject



60
61
62
63
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/stepmod/utils/terms_extractor.rb', line 60

def call
  # If we are using the stepmod CVS repository, provide the revision number per file
  @cvs_mode = if Dir.exists?(stepmod_path.join("CVS"))
                require "ptools"
                # ptools provides File.which
                File.which("cvs")
              end

  log "INFO: STEPmod directory set to #{stepmod_dir}."

  if cvs_mode
    log "INFO: STEPmod directory is a \
      CVS repository and will detect revisions."
    log "INFO: [CVS] Detecting file revisions can be slow, \
      please be patient!"
  else
    log "INFO: STEPmod directory is not a CVS repository, \
      skipping revision detection."
  end

  log "INFO: Detecting paths..."

  repo_index = Nokogiri::XML(File.read(stepmod_path.join("repository_index.xml"))).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



45
46
47
# File 'lib/stepmod/utils/terms_extractor.rb', line 45

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

#term_special_category(bibdata) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/stepmod/utils/terms_extractor.rb', line 49

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