Sha256: 4cc54fbdd5eadf97216db811d8f6e3d2888aadb934109368a452cf9a88ff2b31

Contents?: true

Size: 1.39 KB

Versions: 568

Compression:

Stored size: 1.39 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
  fields = file.fields
  matches.each do |item|
    puts Log.color(:magenta, item)
    if fields.any?
      info = file.fields.zip(file[item])
    else
      info = {}
    end
    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

568 entries across 568 versions & 1 rubygems

Version Path
rbbt-util-5.37.8 share/rbbt_commands/association/subset
rbbt-util-5.37.6 share/rbbt_commands/association/subset
rbbt-util-5.37.4 share/rbbt_commands/association/subset
rbbt-util-5.37.3 share/rbbt_commands/association/subset
rbbt-util-5.37.1 share/rbbt_commands/association/subset
rbbt-util-5.37.0 share/rbbt_commands/association/subset
rbbt-util-5.36.0 share/rbbt_commands/association/subset
rbbt-util-5.35.4 share/rbbt_commands/association/subset
rbbt-util-5.35.3 share/rbbt_commands/association/subset
rbbt-util-5.35.2 share/rbbt_commands/association/subset
rbbt-util-5.35.1 share/rbbt_commands/association/subset
rbbt-util-5.34.27 share/rbbt_commands/association/subset
rbbt-util-5.34.26 share/rbbt_commands/association/subset
rbbt-util-5.34.25 share/rbbt_commands/association/subset
rbbt-util-5.34.24 share/rbbt_commands/association/subset
rbbt-util-5.34.23 share/rbbt_commands/association/subset
rbbt-util-5.34.22 share/rbbt_commands/association/subset
rbbt-util-5.34.21 share/rbbt_commands/association/subset
rbbt-util-5.34.20 share/rbbt_commands/association/subset
rbbt-util-5.34.18 share/rbbt_commands/association/subset