Class: PROIEL::Commands::Dictionary
- Inherits:
-
PROIEL::Command
- Object
- PROIEL::Command
- PROIEL::Commands::Dictionary
- Defined in:
- lib/proiel/cli/commands/dictionary.rb
Class Method Summary collapse
Methods inherited from PROIEL::Command
Class Method Details
.init_with_program(prog) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/proiel/cli/commands/dictionary.rb', line 5 def init_with_program(prog) prog.command(:dictionary) do |c| c.syntax 'dictionary [options] filename(s)' c.description 'Build a dictionary' c.option 'glosses', '--merge-glosses glosses.tsv', 'Merge glosses from an external file' c.option 'gloss-languages', '--merge-gloss-languages eng,rus', 'Merge glosses from selected languages' c.action { |args, | process(args, ) } end end |
.process(args, options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/proiel/cli/commands/dictionary.rb', line 17 def process(args, ) tb = PROIEL::Treebank.new dict = PROIEL::DictionaryBuilder.new args.each do |filename| STDERR.puts "Reading #{filename}...".green if ['verbose'] tb.load_from_xml(filename) end if ['glosses'] languages = (['gloss-languages'] || 'eng').split(',').map(&:to_sym) if File.exist?(['glosses']) dict.add_external_glosses!(['glosses'], languages) else STDERR.puts "#{['glosses']} not found" exit 1 end end tb.sources.each do |source| dict.add_source!(source) end dict.to_xml(STDOUT) end |