Class: PhraseKit::Miner
- Inherits:
-
Object
- Object
- PhraseKit::Miner
- Defined in:
- lib/phrasekit/miner.rb
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Class Method Details
.mine(input_path:, output_path:, min_n: 2, max_n: 5, min_count: 10, config_path: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/phrasekit/miner.rb', line 8 def mine(input_path:, output_path:, min_n: 2, max_n: 5, min_count: 10, config_path: nil) binary_path = find_binary # Create temporary config if not provided if config_path.nil? require "tempfile" require "json" config_file = Tempfile.new(["mine_config", ".json"]) config_file.write(JSON.generate({ min_n: min_n, max_n: max_n, min_count: min_count })) config_file.flush config_path = config_file.path end # Run mining cmd = [binary_path, input_path.to_s, config_path.to_s, output_path.to_s] output = `#{cmd.shelljoin} 2>&1` unless $?.success? config_file.close! if config_file raise Error, "Mining failed: #{output}" end config_file.close! if config_file # Parse stats from output parse_stats(output) end |