<filename>feature-table/build_table.py<gh_stars>1-10
from __future__ import print_function
import argparse
import os.path
import csv
import sys
import scipy.sparse
import numpy as np
import table_utils
import shelve
import pickle

dir_path = os.path.dirname(os.path.realpath(__file__))


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', '--features-file', nargs='?', dest='features')
    parser.add_argument('-i', '--input-folder', nargs='?', dest='input_folder')
    parser.add_argument('-o', '--output-table', nargs='?', dest='output_data')
    parser.add_argument('-l', '--label', nargs='?', dest='label', default='B')
    args = parser.parse_args()

    features_file = ""
    output_file = ""
    input_folder = ""
    if args.features is None:
        sys.exit("No features file selected!")
    else:
        features_file = os.path.abspath(args.features)
        if not os.path.exists(features_file):
            sys.exit("Feature file " + args.features + " does not exists!")

    if args.input_folder is None or os.path.isdir(args.input_folder) is False:
        sys.exit("Input folder not valid!")
    else:
        input_folder = os.path.abspath(args.input_folder)

    if args.output_data is None:
        output_file = os.path.basename(features_file) + "_table"
    else:
        out_dir = os.path.dirname(args.output_data)
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        output_file = args.output_data

    return input_folder, features_file, output_file, args.label


def main():
    input_folder, features_file, output_file, label = parse_args()

    # make_table(input_folder, output_file, f_list, label)
    features = table_utils.read_file(features_file)
    table = table_utils.make_table_dict(input_folder, label)

    data_output = shelve.open(output_file, protocol=pickle.HIGHEST_PROTOCOL)

    data_output[table_utils.TABLE] = table
    data_output[table_utils.FEATURE_NAMES] = features

    # with open(output_file, 'wb') as file:
    #    pickle.dump(table, file, protocol=pickle.HIGHEST_PROTOCOL)


if __name__ == "__main__":
    main()

<filename>feature-table/build_table.py<gh_stars>1-10
from __future__ import print_function
import argparse
import os.path
import csv
import sys
import scipy.sparse
import numpy as np
import table_utils
import shelve
import pickle

dir_path = os.path.dirname(os.path.realpath(__file__))


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', '--features-file', nargs='?', dest='features')
    parser.add_argument('-i', '--input-folder', nargs='?', dest='input_folder')
    parser.add_argument('-o', '--output-table', nargs='?', dest='output_data')
    parser.add_argument('-l', '--label', nargs='?', dest='label', default='B')
    args = parser.parse_args()

    features_file = ""
    output_file = ""
    input_folder = ""
    if args.features is None:
        sys.exit("No features file selected!")
    else:
        features_file = os.path.abspath(args.features)
        if not os.path.exists(features_file):
            sys.exit("Feature file " + args.features + " does not exists!")

    if args.input_folder is None or os.path.isdir(args.input_folder) is False:
        sys.exit("Input folder not valid!")
    else:
        input_folder = os.path.abspath(args.input_folder)

    if args.output_data is None:
        output_file = os.path.basename(features_file) + "_table"
    else:
        out_dir = os.path.dirname(args.output_data)
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
        output_file = args.output_data

    return input_folder, features_file, output_file, args.label


def main():
    input_folder, features_file, output_file, label = parse_args()

    # make_table(input_folder, output_file, f_list, label)
    features = table_utils.read_file(features_file)
    table = table_utils.make_table_dict(input_folder, label)

    data_output = shelve.open(output_file, protocol=pickle.HIGHEST_PROTOCOL)

    data_output[table_utils.TABLE] = table
    data_output[table_utils.FEATURE_NAMES] = features

    # with open(output_file, 'wb') as file:
    #    pickle.dump(table, file, protocol=pickle.HIGHEST_PROTOCOL)


if __name__ == "__main__":
    main()

# make_table(input_folder, output_file, f_list, label) # with open(output_file, 'wb') as file: #    pickle.dump(table, file, protocol=pickle.HIGHEST_PROTOCOL)