#!/usr/bin/env ruby #!/usr/bin/env ruby # encoding: UTF-8 # resolve bin path, ignoring symlinks require "pathname" bin_file = Pathname.new(__FILE__).realpath # add self to libpath $:.unshift File.expand_path("../../lib", bin_file) # Fixes https://github.com/rubygems/rubygems/issues/1420 require "rubygems/specification" class Gem::Specification def this; self; end end require 'bundler/setup' require 'stepmod/utils/stepmod_definition_converter' require 'stepmod/utils/bibdata' require 'stepmod/utils/concept' ReverseAsciidoctor.config.unknown_tags = :bypass parsed_terms = [] parsed_bibliography = [] encountered_terms = {} paths = ARGV.map do |path| path = "../iso-10303-stepmod/data" puts "Searching for #{path}/{resource,module,application_protocol,business_object_model}.xml..." Dir[ "#{path}/**/resource.xml", "#{path}/**/application_protocol.xml", "#{path}/**/business_object_model.xml", "#{path}/**/module.xml" ] end.flatten.sort.uniq paths.each do |file_path| puts("Processing XML file #{file_path}") current_document = Nokogiri::XML(File.read(file_path)).root bibdata = nil begin bibdata = Stepmod::Utils::Bibdata.new(document: current_document) rescue puts "WARNING: Unknown file #{file_path}, skipped" next end if bibdata.part.to_s.empty? puts "FATAL: missing `part` attribute: #{file_path}" end # read definitions current_document.xpath('//definition').each.with_index(1) do |definition, index| term_id = definition['id'] unless term_id.nil? if encountered_terms[term_id] puts "FATAL: Duplicated term with id: #{term_id}, #{file_path}" end encountered_terms[term_id] = true end concept = Stepmod::Utils::Concept.parse( definition, reference_anchor: bibdata.anchor, # Assume that definition is located in clause 3 of the ISO document # in order. We really don't have a good reference here. reference_clause: "3.#{index}" ) parsed_terms << concept parsed_bibliography << bibdata end end parsed_bibliography.uniq! File.open('031-generated-terms.adoc', 'w') { |file| file.puts(parsed_terms.map(&:to_mn_adoc).join("\n")) } File.open('991-generated-bibliography.adoc', 'w') { |file| file.puts(parsed_bibliography.map(&:to_mn_adoc).join("\n")) }