def _make_itsdb_actions(items): actions = [] if items is not None: for item in items: data_specifier, function = item.split('=', 1) table, cols = itsdb.get_data_specifier(data_specifier) function = eval('lambda row, x:{}'.format(function)) actions.append((table, cols, function)) return actions
def select(args): """ Select data from [incr tsdb()] profiles. """ in_profile = _prepare_input_profile(args['PROFILE'], filters=args['--filter'], applicators=args['--apply']) if args['--join']: tbl1, tbl2 = map(str.strip, args['--join'].split(',')) rows = in_profile.join(tbl1, tbl2, key_filter=True) # Adding : is just for robustness. We need something like # :table:col@table@col, but may have gotten table:col@table@col if not args['DATASPEC'].startswith(':'): args['DATASPEC'] = ':' + args['DATASPEC'] table, cols = itsdb.get_data_specifier(args['DATASPEC']) else: table, cols = itsdb.get_data_specifier(args['DATASPEC']) rows = in_profile.read_table(table, key_filter=True) for row in itsdb.select_rows(cols, rows, mode='row'): print(row)
def main(): args = docopt.docopt(USAGE) if args['--sem-i']: smi = semi.load(args['--sem-i']) else: smi = semi.SemI() lexmap = {} if args['--lexicon']: for lexicon in args['--lexicon']: lexmap.update(get_lexmap(lexicon)) typemap = json.load(open(args['TYPEMAP'])) entry_generators = [] for prof in args['PROFILE']: table, cols = itsdb.get_data_specifier(args['--data-specifier']) entry_generators.append( prof_entries(prof, typemap, lexmap, table, cols)) for mtr in args['--mtr']: entry_generators.append(mtr_entries(mtr, typemap)) entries = chain.from_iterable(entry_generators) created = set() for (lename, supertype, orth, pred, cv) in entries: # don't create if pred exists or entry already created if (pred.short_form() in smi.predicates or (supertype, orth, pred.string) in created): continue # guess if phonological onset is vocalic or consonant if cv is None: cv = 'voc' if pred.lemma[0] in 'aeiou' else 'con' print(format_lex_entry(lename, supertype, orth, pred, cv)) created.add((supertype, orth, pred.string))
def test_get_data_specifier(): assert itsdb.get_data_specifier('item') == ('item', None) assert itsdb.get_data_specifier('item:i-input') == ('item', ['i-input']) assert itsdb.get_data_specifier('item:i-id@i-input') == ('item', ['i-id', 'i-input']) assert itsdb.get_data_specifier(':i-id') == (None, ['i-id'])
def _make_itsdb_action(data_specifier, function): table, cols = itsdb.get_data_specifier(data_specifier) function = eval('lambda row, x:{}'.format(function)) return (table, cols, function)