Sha256: cf8d49120e5090fe2a3fad8267bf01664bd4f6c45d8a8e1580d98eb4be8cc430

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 KB

Contents

module Opener
  class Coreference
    ##
    # CLI wrapper around {Opener::Coreference} using OptionParser.
    #
    # @!attribute [r] options
    #  @return [Hash]
    # @!attribute [r] option_parser
    #  @return [OptionParser]
    #
    class CLI
      attr_reader :options, :option_parser

      ##
      # @param [Hash] options
      #
      def initialize(options = {})
        @options = DEFAULT_OPTIONS.merge(options)

        @option_parser = OptionParser.new do |opts|
          opts.program_name   = 'coreference'
          opts.summary_indent = '  '

          opts.on('-h', '--help', 'Shows this help message') do
            show_help
          end

          opts.on('-v', '--version', 'Shows the current version') do
            show_version
          end

          opts.separator <<-EOF

Examples:

  cat example.kaf | #{opts.program_name}

Supported Languages (taken from kaf lang element):

  * Dutch (nl)
  * English (en)
  * French (fr)
  * German (de)
  * Italian (it)
  * Spanish (es)
          EOF
        end
      end

      ##
      # @param [String] input
      #
      def run(input)
        option_parser.parse!(options[:args])

        tokenizer = Coreference.new(options)

        stdout, stderr, process = tokenizer.run(input)

        puts stdout
      end

      private

      ##
      # Shows the help message and exits the program.
      #
      def show_help
        abort option_parser.to_s
      end

      ##
      # Shows the version and exits the program.
      #
      def show_version
        abort "#{option_parser.program_name} v#{VERSION} on #{RUBY_DESCRIPTION}"
      end
    end # CLI
  end # Ner
end # Opener

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opener-coreference-1.1.2 lib/opener/coreference/cli.rb
opener-coreference-1.1.1 lib/opener/coreference/cli.rb
opener-coreference-1.1.0 lib/opener/coreference/cli.rb
opener-coreference-1.0.5 lib/opener/coreference/cli.rb
opener-coreference-1.0.4 lib/opener/coreference/cli.rb