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.44.1 share/rbbt_commands/association/subset
rbbt-util-5.43.0 share/rbbt_commands/association/subset
rbbt-util-5.42.0 share/rbbt_commands/association/subset
rbbt-util-5.41.1 share/rbbt_commands/association/subset
rbbt-util-5.41.0 share/rbbt_commands/association/subset
rbbt-util-5.40.5 share/rbbt_commands/association/subset
rbbt-util-5.40.4 share/rbbt_commands/association/subset
rbbt-util-5.40.3 share/rbbt_commands/association/subset
rbbt-util-5.40.0 share/rbbt_commands/association/subset
rbbt-util-5.39.0 share/rbbt_commands/association/subset
rbbt-util-5.38.1 share/rbbt_commands/association/subset
rbbt-util-5.38.0 share/rbbt_commands/association/subset
rbbt-util-5.37.16 share/rbbt_commands/association/subset
rbbt-util-5.37.15 share/rbbt_commands/association/subset
rbbt-util-5.37.14 share/rbbt_commands/association/subset
rbbt-util-5.37.13 share/rbbt_commands/association/subset
rbbt-util-5.37.12 share/rbbt_commands/association/subset
rbbt-util-5.37.11 share/rbbt_commands/association/subset
rbbt-util-5.37.10 share/rbbt_commands/association/subset
rbbt-util-5.37.9 share/rbbt_commands/association/subset