Sha256: e75e0833a625292d1d6205bfb3387080e9f3f78257eb8d70730a8497caf21362

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

#!/usr/bin/env ruby

require 'rbbt-util'
require 'rbbt/util/simpleopt'
require 'rbbt/association'

$0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands

options = SOPT.setup <<EOF

Subset of matches between entities

$ rbbt association subset [options] <filename>

Indicate the index file (TokyoCabinet BDB with source~target keys) as the <filename> argument

-h--help Print this help
-s--source* Source entities
-t--target* Target entities
-tsv--tsv* Output tsv
EOF
rbbt_usage and exit 0 if options[:help] 
filename = ARGV.shift
raise ParameterException, "No filename specified" if filename.nil?

file = Persist.open_tokyocabinet(filename,false, nil, TokyoCabinet::BDB)

file.extend Association::Index

source = options[:source] ? options[:source].split(/,\|/) : :all
target = options[:target] ? options[:target].split(/,\|/) : :all

matches = file.subset(source, target)

if options[:tsv]
  puts matches.tsv.to_s
else
  matches.each do |item|
    puts Log.color(:magenta, item)
    info = file.fields.zip(file[item])
    source,_sep, target = item.partition "~"
    puts "  " << Misc.format_definition_list_item("source", source)
    puts "  " << Misc.format_definition_list_item("target", target)
    info.each do |key,value|
      puts "  " << Misc.format_definition_list_item(key, value)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rbbt-util-5.14.18 share/rbbt_commands/association/subset
rbbt-util-5.14.17 share/rbbt_commands/association/subset
rbbt-util-5.14.16 share/rbbt_commands/association/subset
rbbt-util-5.14.15 share/rbbt_commands/association/subset
rbbt-util-5.14.14 share/rbbt_commands/association/subset
rbbt-util-5.14.12 share/rbbt_commands/association/subset
rbbt-util-5.14.11 share/rbbt_commands/association/subset
rbbt-util-5.14.10 share/rbbt_commands/association/subset