Sha256: 1803d24d7c067bc3c2241dc819cb0c66b1bcb0c77d61e91f4c2affa22003bfbd
Contents?: true
Size: 1.03 KB
Versions: 13
Compression:
Stored size: 1.03 KB
Contents
#!/usr/bin/env ruby require File.expand_path( File.join(File.dirname(__FILE__), '..', 'lib', 'rmmseg')) require 'getoptlong' def print_usage puts <<EOF #{__FILE__} Segment Chinese text. Read from stdin and print to stdout. Options: -h --help Print this message -s --separator Select the separator of the segmented text. Default is space. EOF exit 0 end separator = " " optparser = GetoptLong.new optparser.set_options(["-s", "--separator", GetoptLong::REQUIRED_ARGUMENT], ["-h", "--help", GetoptLong::NO_ARGUMENT]) loop do begin opt, arg = optparser.get break if not opt case opt when "-h" print_usage when "-s" separator = arg end rescue => err puts err exit 1 end end RMMSeg::Dictionary.load_dictionaries algor = RMMSeg::Algorithm.new(STDIN.read) tok = algor.next_token unless tok.nil? print tok.text loop do tok = algor.next_token break if tok.nil? print separator print tok.text end puts end # EOF
Version data entries
13 entries across 13 versions & 4 rubygems