コード例 #1
0
ファイル: test_reader.py プロジェクト: pombredanne/zs
def test_ref_loops():
    # Had a bunch of trouble eliminating reference loops in the ZS object.
    # Don't use 'with' statement here b/c that keeps another ref which just
    # confuses things.
    z = ZS(test_data_path("letters-none.zs"))
    try:
        # 1 for 'z', one for the temporary passed to sys.getrefcount
        print(sys.getrefcount(z))
        assert sys.getrefcount(z) == 2
        list(z)
        assert sys.getrefcount(z) == 2
    finally:
        z.close()
コード例 #2
0
ファイル: test_reader.py プロジェクト: pombredanne/zs
def test_zs_close():
    z = ZS(test_data_path("letters-none.zs"))
    z.close()
    for call in [[list, z.search()],
                 [list,
                  z.block_map(_check_raise_helper, AssertionError)],
                 [list, z],
                 [z.dump, BytesIO()],
                 [z.validate],
                 ]:
        print(repr(call))
        assert_raises(ZSError, *call)
    # But calling .close() twice is fine.
    z.close()

    # smoke test for __del__ method
    ZS(test_data_path("letters-none.zs"))
コード例 #3
0
    tmp_bg = line[0].split("_")[0] + "_" + line[1].split("_")[0]
    tmp_tg = line[2].split("_")[0]
    tmp_cnt = int(line[4])
    if tmp_tg not in ix:
        ix[tmp_tg] = {cnt: 0, ix_bg: {}, freq: 0, info: 0, info_g: [], N: 0}
    ix[tmp_tg][cnt] += int(tmp_cnt)
    ix[tmp_tg][N] += tmp_cnt
    if tmp_bg not in ix[tmp_tg][ix_bg]:
        ix[tmp_tg][ix_bg][tmp_bg] = 0
    ix[tmp_tg][ix_bg][tmp_bg] += tmp_cnt
    if tmp_bg not in bg:
        bg[tmp_bg] = int(tmp_cnt)
    else:
        bg[tmp_bg] += int(tmp_cnt)
    total += tmp_cnt
file.close()

fileout1.write(
    "word\tinfo_int\tfreq_int\tinfo_float\tfreq_float\tlen\tcnt\tPOS\tpho\tsyl\td\tp\th\tfunc\n"
)

if args.LOO == True:
    for i in ix:
        if i in replication_word_list:
            b = ix[i][ix_bg]
            for tmp_b in b:
                if b[tmp_b] - 1 == 0 or bg[tmp_b] - 1 == 0:
                    continue
                ix[i][info] += (-m.log(
                    (b[tmp_b] - 1) / (bg[tmp_b] - 1), 2) * b[tmp_b])
                ix[i][info_g].append(-m.log((b[tmp_b] - 1) /