Пример #1
0
def _mkprof(name, skel, logf):
    """Prepare the current profile directory and files."""
    _lognow('\n[preparing profile]', logf)
    _lognow('  Skeleton path: {!s}'.format(skel), logf)

    dest = CURRENT_DIR / name
    _lognow('  Destination: {!s}'.format(dest), logf)

    try:
        mkprof(dest, source=skel, quiet=True)
    except CommandError as exc:
        raise RegressionTestError('Failed to prepare profile.') from exc

    return dest
Пример #2
0
def call_mkprof(args):
    return mkprof(args.DEST,
                  source=args.source or args.input,
                  relations=args.relations,
                  where=args.where,
                  in_place=args.in_place,
                  skeleton=args.skeleton,
                  full=args.full,
                  gzip=args.gzip)
Пример #3
0
def call_mkprof(args):
    return mkprof(args.DEST,
                  source=args.source or args.input,
                  schema=args.relations,
                  where=args.where,
                  delimiter=args.delimiter,
                  refresh=args.refresh,
                  skeleton=args.skeleton,
                  full=args.full,
                  gzip=args.gzip)
Пример #4
0
def _mkskel(name, txt, logf):
    """Prepare the skeleton from the txt-suite."""
    _lognow('\n[preparing skeleton]', logf)
    _lognow('  Txt-suite: {!s}'.format(txt), logf)

    dest = SKELETONS_DIR / name
    _lognow('  Destination: {!s}'.format(dest), logf)
    if not txt:
        raise RegressionTestError(
            f'Did you forget to add the new txt-suite to {TXT_SUITE_DIR!s}?')
    try:
        mkprof(dest,
               source=txt,
               schema=RELATIONS_FILE,
               skeleton=True,
               quiet=True)
    except CommandError as exc:
        raise RegressionTestError('Failed to prepare skeleton.') from exc

    return dest
Пример #5
0
def test_mkprof_issue_273(mini_testsuite, tmp_path):
    # https://github.com/delph-in/pydelphin/issues/273
    from delphin import itsdb
    ts1_ = tmp_path.joinpath('ts1')
    ts1_.mkdir()
    ts1 = str(ts1_)
    ts0 = mini_testsuite
    # this is when the condition occurs on a single row
    mkprof(ts1, source=ts0, full=True, where='mrs ~ "_snow_v_1"')
    item = pathlib.Path(ts1, 'item')
    assert item.read_text() == ('30@It snowed.@1@2018-2-1 (15:00:00)\n')
    # this is when the condition occurs on multiple rows
    _ts0 = itsdb.TestSuite(ts0)
    _ts0['parse'].update(2, {'readings': 2})
    _ts0['result'].append(
        (30, 1, '[ TOP: h0 INDEX e2 [ e TENSE: past ]'
         '  RELS: < [ pronoun_q<0:2> LBL h3 ARG0: x4 RSTR: h5 BODY: h6 ]'
         '          [ pron<0:2> LBL: h7 ARG0: x4 ]'
         '          [ _snow_v_1<3:9> LBL: h1 ARG0: e2 ARG1: x4 ] >'
         '  HCONS: < h0 qeq h1 h5 qeq h7 > ]'))
    _ts0.commit()
    mkprof(ts1, source=ts0, full=True, where='mrs ~ "_snow_v_1"')
    item = pathlib.Path(ts1, 'item')
    assert item.read_text() == ('30@It snowed.@1@2018-2-1 (15:00:00)\n')
Пример #6
0
from delphin import itsdb
from delphin import ace
from delphin import commands

src_path = 'golden'
tgt_path = 'p'

commands.mkprof(tgt_path, source=src_path)
src_ts = itsdb.TestSuite(src_path)
tgt_ts = itsdb.TestSuite(tgt_path)
with ace.ACEGenerator('erg.dat') as cpu:
    tgt_ts.process(cpu, source=src_ts)
Пример #7
0
def test_mkprof(mini_testsuite, empty_alt_testsuite, sentence_file, tmp_path,
                monkeypatch):
    ts1_ = tmp_path.joinpath('ts1')
    ts1_.mkdir()
    ts1 = str(ts1_)
    ts0 = mini_testsuite
    sentence_file = str(sentence_file)

    with pytest.raises(CommandError):
        mkprof(ts1, source=sentence_file)
    with pytest.raises(CommandError):
        mkprof(ts1, source='not a test suite')

    relations = str(pathlib.Path(mini_testsuite, 'relations'))

    mkprof(ts1, source=ts0)
    mkprof(ts1, source=None, refresh=True)
    with monkeypatch.context() as m:
        m.setattr('sys.stdin', io.StringIO('A dog barked.\n'))
        mkprof(ts1, source=None, refresh=False, schema=relations)
    mkprof(ts1, source=sentence_file, schema=relations)

    mkprof(ts1, source=ts0, full=True)
    mkprof(ts1, source=ts0, skeleton=True)
    mkprof(ts1, source=ts0, full=True, gzip=True)

    mkprof(ts1,
           refresh=True,
           schema=pathlib.Path(empty_alt_testsuite, 'relations'))
    item = pathlib.Path(ts1, 'item')
    assert item.read_text() == ('10@It rained.@1-feb-2018 15:00\n'
                                '20@Rained.@01-02-18 15:00:00\n'
                                '30@It snowed.@2018-2-1 (15:00:00)\n')
    mkprof(ts1, refresh=True, gzip=True)
    assert not item.with_suffix('').exists()
    assert item.with_suffix('.gz').is_file()