class AnyStyle::CLI::Commands::Train

Public Instance Methods

check_no_overwrite!(path) click to toggle source
# File lib/anystyle/cli/commands/train.rb, line 31
def check_no_overwrite!(path)
  if !overwrite? && (path.nil? || File.exist?(path))
    raise RuntimeError,
      "file exists, use --overwrite to force saving: #{path}"
  end
end
run(args, params) click to toggle source
# File lib/anystyle/cli/commands/train.rb, line 5
def run(args, params)
  check_no_overwrite! args[1]

  Wapiti.debug!
  model = train(args[0])

  if args[1].nil?
    model.save
  else
    model.save File.expand_path(args[1]).untaint
  end
end
train(path) click to toggle source
# File lib/anystyle/cli/commands/train.rb, line 18
def train(path)
  case
  when File.extname(path) == '.xml'
    AnyStyle.parser.train path.to_s.untaint
    AnyStyle.parser.model
  when File.directory?(path)
    AnyStyle.finder.train Dir[File.join(path, '*.ttx')].map(&:untaint)
    AnyStyle.finder.model
  else
    raise ArgumentError, "cannot train input: #{path}"
  end
end