Class: AnyStyle::CLI::Commands::Train
- Inherits:
-
Base
- Object
- Base
- AnyStyle::CLI::Commands::Train
show all
- Defined in:
- lib/anystyle/cli/commands/train.rb
Instance Attribute Summary
Attributes inherited from Base
#options, #output_folder
Instance Method Summary
collapse
Methods inherited from Base
#each_format, #extsub, #find, #format, #initialize, #overwrite?, #parse, #report, #say, #set_output_folder, #stdout?, #transpose, #verbose?, #walk, #write
Instance Method Details
#check_no_overwrite!(path) ⇒ Object
31
32
33
34
35
36
|
# 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) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
|
# 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) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# 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 path.to_s.untaint
AnyStyle.finder.model
else
raise ArgumentError, "cannot train input: #{path}"
end
end
|