Class: Openphar::Cli::Main
- Inherits:
-
Thor
- Object
- Thor
- Openphar::Cli::Main
- Defined in:
- lib/openphar/cli/main.rb
Overview
Main CLI for the openphar gem
Instance Method Summary collapse
- #compare(monograph_id) ⇒ Object
- #editions ⇒ Object
- #link(file) ⇒ Object
- #publishers ⇒ Object
- #transform(input, output) ⇒ Object
- #validate(file) ⇒ Object
- #version ⇒ Object
Instance Method Details
#compare(monograph_id) ⇒ Object
115 116 117 118 |
# File 'lib/openphar/cli/main.rb', line 115 def compare(monograph_id) puts "Comparing #{monograph_id} across publishers..." puts "Not implemented yet" end |
#editions ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/openphar/cli/main.rb', line 92 def editions edition_dir = File.join(Openphar.data_path, "edition") return puts "No editions found" unless File.directory?(edition_dir) puts "Available Editions:" puts "-" * 60 Dir.glob("#{edition_dir}/*/*.jsonld").each do |file| data = JSON.parse(File.read(file)) next unless data["@graph"] data["@graph"].each do |item| next unless item["@type"] == "Edition" label = item["prefLabel"]&.values&.first || item["editionNumber"] count = item["monographCount"] || "unknown" puts format("%-20s %s monographs", label, count) end end end |
#link(file) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/openphar/cli/main.rb', line 55 def link(file) puts "Linking #{file} to data-herbapedia..." linker = Linkers::HerbapediaLinker.new( herbapedia_data_path: [:herbapedia] ) # Read and parse JSON-LD data = JSON.parse(File.read(file)) # Link each monograph if data["@graph"] data["@graph"].map! do |monograph| linker.link_monograph(monograph) end else data = linker.link_monograph(data) end # Write updated file File.write(file, JSON.pretty_generate(data)) puts "Links added to #{file}" end |
#publishers ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/openphar/cli/main.rb', line 80 def publishers puts "Supported Publishers:" puts "-" * 60 Publisher.all.each do |publisher| puts format("%-10s %s (%s)", publisher.code, publisher.name["en"], publisher.country) end end |
#transform(input, output) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/openphar/cli/main.rb', line 26 def transform(input, output) puts "Transforming #{input} to #{output}..." puts "Publisher: #{[:publisher]}" puts "Edition: #{[:edition]}" if [:edition] # Read input content = File.read(input) # Parse based on publisher parser = parser_for([:publisher], content) monographs = parser.parse puts "Found #{monographs.length} monographs" # Transform to JSON-LD transformer = Transformers::JsonldTransformer.new result = transformer.transform_graph( monographs, publisher: [:publisher], edition: [:edition] ) # Write output File.write(output, JSON.pretty_generate(result)) puts "Output written to #{output}" end |
#validate(file) ⇒ Object
16 17 18 19 20 |
# File 'lib/openphar/cli/main.rb', line 16 def validate(file) puts "Validating #{file}..." # TODO: Implement SHACL validation puts "Validation complete" end |