当前位置: 首页>>代码示例>>Python>>正文


Python RamStorage.create_file方法代码示例

本文整理汇总了Python中whoosh.filedb.filestore.RamStorage.create_file方法的典型用法代码示例。如果您正苦于以下问题:Python RamStorage.create_file方法的具体用法?Python RamStorage.create_file怎么用?Python RamStorage.create_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在whoosh.filedb.filestore.RamStorage的用法示例。


在下文中一共展示了RamStorage.create_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_extras

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_extras():
    st = RamStorage()
    hw = HashWriter(st.create_file("test"))
    hw.extras["test"] = 100
    hw.extras["blah"] = "foo"
    hw.close()

    hr = HashReader(st.open_file("test"), st.file_length("test"))
    assert hr.extras["test"] == 100
    assert hr.extras["blah"] == "foo"
    hr.close()

    hw = OrderedHashWriter(st.create_file("test"))
    hw.extras["test"] = 100
    hw.extras["blah"] = "foo"
    hw.close()

    hr = HashReader(st.open_file("test"), st.file_length("test"))
    assert hr.extras["test"] == 100
    assert hr.extras["blah"] == "foo"
    hr.close()

    hr = OrderedHashReader(st.open_file("test"), st.file_length("test"))
    assert hr.extras["test"] == 100
    assert hr.extras["blah"] == "foo"
    hr.close()
开发者ID:JunjieHu,项目名称:dl,代码行数:28,代码来源:test_tables.py

示例2: test_ondisk

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_ondisk():
    bs = BitSet([10, 11, 30, 50, 80])

    st = RamStorage()
    f = st.create_file("test")
    size = bs.to_disk(f)
    f.close()

    f = st.open_file("test")
    b = OnDiskBitSet(f, 0, size)
    assert list(b) == list(bs)

    assert b.after(0) == 10
    assert b.after(10) == 11
    assert b.after(80) is None
    assert b.after(99) is None

    assert b.before(0) is None
    assert b.before(99) == 80
    assert b.before(80) == 50
    assert b.before(10) is None

    f.seek(0)
    b = BitSet.from_disk(f, size)
    assert list(b) == list(bs)
开发者ID:JunjieHu,项目名称:dl,代码行数:27,代码来源:test_bits.py

示例3: test_wordfile

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_wordfile():
    import os.path

    files = os.listdir(".")
    testdir = "tests"
    fname = "english-words.10.gz"
    if testdir in files:
        path = os.path.join(testdir, fname)
    elif fname in files:
        path = fname
    else:
        return

    if not os.path.exists(path):
        return
    wordfile = gzip.open(path, "r")
    cor = spelling.GraphCorrector.from_word_list(word.decode("latin-1")
                                                 for word in wordfile)
    wordfile.close()

    #dawg.dump_dawg(cor.word_graph)
    assert_equal(cor.suggest("specail"), ["special"])

    st = RamStorage()
    gf = st.create_file("test.dawg")
    cor.to_file(gf)

    gf = st.open_file("test.dawg")
    cor = spelling.GraphCorrector.from_graph_file(gf)

    assert_equal(cor.suggest("specail", maxdist=1), ["special"])
    gf.close()
开发者ID:ChimmyTee,项目名称:oh-mainline,代码行数:34,代码来源:test_spelling.py

示例4: test_hash_single

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_hash_single():
    st = RamStorage()
    hw = HashWriter(st.create_file("test.hsh"))
    hw.add(b("alfa"), b("bravo"))
    hw.close()

    hr = HashReader.open(st, "test.hsh")
    assert hr.get(b("alfa")) == b("bravo")
    assert hr.get(b("foo")) is None
开发者ID:JunjieHu,项目名称:dl,代码行数:11,代码来源:test_tables.py

示例5: _rt

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def _rt(c, values, default):
    # Continuous
    st = RamStorage()
    f = st.create_file("test1")
    f.write(b("hello"))
    w = c.writer(f)
    for docnum, v in enumerate(values):
        w.add(docnum, v)
    w.finish(len(values))
    length = f.tell() - 5
    f.close()

    f = st.open_file("test1")
    r = c.reader(f, 5, length, len(values))
    assert values == list(r)
    for x in range(len(values)):
        assert values[x] == r[x]
    f.close()

    # Sparse
    doccount = len(values) * 7 + 15
    target = [default] * doccount

    f = st.create_file("test2")
    f.write(b("hello"))
    w = c.writer(f)
    for docnum, v in izip(xrange(10, doccount, 7), values):
        target[docnum] = v
        w.add(docnum, v)
    w.finish(doccount)
    length = f.tell() - 5
    f.close()

    f = st.open_file("test2")
    r = c.reader(f, 5, length, doccount)
    assert target == list(r)
    for x in range(doccount):
        assert target[x] == r[x]

    lr = r.load()
    assert target == list(lr)
    f.close()
开发者ID:pombredanne,项目名称:whoosh-clone,代码行数:44,代码来源:test_columns.py

示例6: test_find_self

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_find_self():
    wordlist = sorted(u("book bake bike bone").split())
    st = RamStorage()
    f = st.create_file("test")
    spelling.wordlist_to_graph_file(wordlist, f)

    gr = fst.GraphReader(st.open_file("test"))
    gc = spelling.GraphCorrector(gr)
    assert gc.suggest("book")[0] != "book"
    assert gc.suggest("bake")[0] != "bake"
    assert gc.suggest("bike")[0] != "bike"
    assert gc.suggest("bone")[0] != "bone"
开发者ID:JunjieHu,项目名称:dl,代码行数:14,代码来源:test_spelling.py

示例7: test_insert_bytes

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_insert_bytes():
    # This test is only meaningful on Python 3
    domain = [b("alfa"), b("bravo"), b("charlie")]

    st = RamStorage()
    gw = fst.GraphWriter(st.create_file("test"))
    gw.start_field("test")
    for key in domain:
        gw.insert(key)
    gw.close()

    cur = fst.GraphReader(st.open_file("test")).cursor()
    assert list(cur.flatten()) == domain
开发者ID:JunjieHu,项目名称:dl,代码行数:15,代码来源:test_dawg.py

示例8: test_hash_extras

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_hash_extras():
    st = RamStorage()
    hw = HashWriter(st.create_file("test.hsh"))
    hw.extras["test"] = 100
    hw.add(b("foo"), b("bar"))
    hw.add(b("glonk"), b("baz"))
    hw.close()

    hr = HashReader.open(st, "test.hsh")
    assert hr.extras["test"] == 100
    assert hr.get(b("foo")) == b("bar")
    assert hr.get(b("baz")) is None
    hr.close()
开发者ID:JunjieHu,项目名称:dl,代码行数:15,代码来源:test_tables.py

示例9: test_checksum_file

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_checksum_file():
    from whoosh.filedb.structfile import ChecksumFile
    from zlib import crc32

    def wr(f):
        f.write(b("Testing"))
        f.write_int(-100)
        f.write_varint(10395)
        f.write_string(b("Hello"))
        f.write_ushort(32959)

    st = RamStorage()
    # Write a file normally
    f = st.create_file("control")
    wr(f)
    f.close()
    # Checksum the contents
    f = st.open_file("control")
    target = crc32(f.read()) & 0xffffffff
    f.close()

    # Write a file with checksumming
    f = st.create_file("test")
    cf = ChecksumFile(f)
    wr(cf)
    assert cf.checksum() == target
    f.close()

    # Read the file with checksumming
    f = st.open_file("test")
    cf = ChecksumFile(f)
    assert cf.read(7) == b("Testing")
    assert cf.read_int() == -100
    assert cf.read_varint() == 10395
    assert cf.read_string() == b("Hello")
    assert cf.read_ushort() == 32959
    assert cf.checksum() == target
    cf.close()
开发者ID:JunjieHu,项目名称:dl,代码行数:40,代码来源:test_tables.py

示例10: test_insert_unicode

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_insert_unicode():
    domain = [u("\u280b\u2817\u2801\u281d\u2809\u2811"),
              u("\u65e5\u672c"),
              u("\uc774\uc124\ud76c"),
              ]

    st = RamStorage()
    gw = fst.GraphWriter(st.create_file("test"))
    gw.start_field("test")
    for key in domain:
        gw.insert(key)
    gw.close()

    cur = fst.GraphReader(st.open_file("test")).cursor()
    assert list(cur.flatten_strings()) == domain
开发者ID:JunjieHu,项目名称:dl,代码行数:17,代码来源:test_dawg.py

示例11: test_termindex

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_termindex():
    terms = [("a", "alfa"), ("a", "bravo"), ("a", "charlie"), ("a", "delta"),
             ("b", "able"), ("b", "baker"), ("b", "dog"), ("b", "easy")]
    st = RamStorage()
    
    tw = TermIndexWriter(st.create_file("test.trm"))
    for i, t in enumerate(terms):
        tw.add(t, FileTermInfo(1.0, i))
    tw.close()
    
    tr = TermIndexReader(st.open_file("test.trm"))
    for i, (t1, t2) in enumerate(zip(tr.keys(), terms)):
        assert_equal(t1, t2)
        ti = tr.get(t1)
        assert_equal(ti.weight(), 1.0)
        assert_equal(ti.doc_frequency(), i)
开发者ID:ChimmyTee,项目名称:oh-mainline,代码行数:18,代码来源:test_tables.py

示例12: test_within_unicode

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_within_unicode():
    domain = [u("\u280b\u2817\u2801\u281d\u2809\u2811"),
              u("\u65e5\u672c"),
              u("\uc774\uc124\ud76c"),
              ]

    st = RamStorage()
    gw = fst.GraphWriter(st.create_file("test"))
    gw.start_field("test")
    for key in domain:
        gw.insert(key)
    gw.close()

    gr = fst.GraphReader(st.open_file("test"))
    s = list(fst.within(gr, u("\uc774.\ud76c")))
    assert s == [u("\uc774\uc124\ud76c")]
开发者ID:JunjieHu,项目名称:dl,代码行数:18,代码来源:test_dawg.py

示例13: test_types

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_types():
    st = RamStorage()

    types = ((fst.IntValues, 100, 0),
             (fst.BytesValues, b('abc'), b('')),
             (fst.ArrayValues("i"), array("i", [0, 123, 42]), array("i")),
             (fst.IntListValues, [0, 6, 97], []))

    for t, v, z in types:
        assert t.common(None, v) is None
        assert t.common(v, None) is None
        assert t.common(None, None) is None
        assert t.subtract(v, None) == v
        assert t.subtract(None, v) is None
        assert t.subtract(None, None) is None
        assert t.add(v, None) == v
        assert t.add(None, v) == v
        assert t.add(None, None) is None
        f = st.create_file("test")
        t.write(f, v)
        t.write(f, z)
        f.close()
        f = st.open_file("test")
        assert t.read(f) == v
        assert t.read(f) == z

    assert fst.IntValues.common(100, 20) == 20
    assert fst.IntValues.add(20, 80) == 100
    assert fst.IntValues.subtract(100, 80) == 20

    assert fst.BytesValues.common(b("abc"), b("abc")) == b("abc")
    assert fst.BytesValues.common(b("abcde"), b("abfgh")) == b("ab")
    assert fst.BytesValues.common(b("abcde"), b("ab")) == b("ab")
    assert fst.BytesValues.common(b("ab"), b("abcde")) == b("ab")
    assert fst.BytesValues.common(None, b("abcde")) is None
    assert fst.BytesValues.common(b("ab"), None) is None

    a1 = array("i", [0, 12, 123, 42])
    a2 = array("i", [0, 12, 420])
    cm = array("i", [0, 12])
    assert fst.ArrayValues.common(a1, a1) == a1
    assert fst.ArrayValues.common(a1, a2) == cm
    assert fst.ArrayValues.common(a2, a1) == cm
    assert fst.ArrayValues.common(None, a1) is None
    assert fst.ArrayValues.common(a2, None) is None
开发者ID:JunjieHu,项目名称:dl,代码行数:47,代码来源:test_dawg.py

示例14: test_random_termkeys

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_random_termkeys():
    def random_fieldname():
        return "".join(chr(random.randint(65, 90)) for _ in xrange(1, 20))
    
    def random_token():
        return "".join(unichr(random.randint(0, 0xd7ff)) for _ in xrange(1, 20))
    
    domain = sorted([(random_fieldname(), random_token()) for _ in xrange(1000)])
    
    st = RamStorage()
    tw = TermIndexWriter(st.create_file("test.trm"))
    for term in domain:
        tw.add(term, FileTermInfo(1.0, 1))
    tw.close()
    
    tr = TermIndexReader(st.open_file("test.trm"))
    for term in domain:
        assert term in tr
开发者ID:ChimmyTee,项目名称:oh-mainline,代码行数:20,代码来源:test_tables.py

示例15: test_multistream

# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import create_file [as 别名]
def test_multistream():
    domain = [("a", "12345"), ("b", "abc"), ("c", "AaBbC"),
              ("a", "678"), ("c", "cDdEeF"), ("b", "defgh"),
              ("b", "ijk"), ("c", "fGgHh"), ("a", "9abc")]

    st = RamStorage()
    msw = compound.CompoundWriter(st)
    files = dict((name, msw.create_file(name)) for name in "abc")
    for name, data in domain:
        files[name].write(b(data))
    f = st.create_file("test")
    msw.save_as_compound(f)

    f = st.open_file("test")
    msr = compound.CompoundStorage(f)
    assert msr.open_file("a").read() == b("123456789abc")
    assert msr.open_file("b").read() == b("abcdefghijk")
    assert msr.open_file("c").read() == b("AaBbCcDdEeFfGgHh")
开发者ID:pombredanne,项目名称:whoosh-clone,代码行数:20,代码来源:test_columns.py


注:本文中的whoosh.filedb.filestore.RamStorage.create_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。