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


Python FileStorage.create_file方法代码示例

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


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

示例1: test_hash

# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import create_file [as 别名]
 def test_hash(self):
     self.make_dir("testindex")
     st = FileStorage("testindex")
     hwf = st.create_file("test.hsh")
     hw = FileHashWriter(hwf)
     hw.add("foo", "bar")
     hw.add("glonk", "baz")
     hw.close()
     
     hrf = st.open_file("test.hsh")
     hr = FileHashReader(hrf)
     self.assertEqual(hr.get("foo"), "bar")
     self.assertEqual(hr.get("baz"), None)
     hr.close()
开发者ID:SpaceAppsXploration,项目名称:whoosh,代码行数:16,代码来源:test_tables.py

示例2: open

# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import create_file [as 别名]
from whoosh import spelling
from whoosh.filedb.filestore import FileStorage

wordfile = open("/Users/amckenzie/Documents/data/scowl-7.1/final/english-words.60")

# Use a Storage object to get a file to write the graph into 
st = FileStorage("/Users/amckenzie/Tools/pythonScripts") 
f = st.create_file("wordgraph") 

# Write a graph of the words into the file 
spelling.wordlist_to_graph_file(wordfile, f) 

# Create a graph reader from the file and wrap it with a corrector 
f = st.open_file("wordgraph") 
gr = fst.GraphReader(f) 
cor = spelling.GraphCorrector(gr) 

# See docs for whoosh.spelling.Corrector.suggest() 
cor.suggest("aple")
开发者ID:ab6,项目名称:pythonScripts,代码行数:21,代码来源:whooshDict.py

示例3: TestReadWrite

# 需要导入模块: from whoosh.filedb.filestore import FileStorage [as 别名]
# 或者: from whoosh.filedb.filestore.FileStorage import create_file [as 别名]
class TestReadWrite(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestReadWrite, self).__init__(*args, **kwargs)
        self.fs = FileStorage(".")
    
    def make_postings(self):
        postings = [(1, 23), (3, 45), (12, 2), (34, 21), (43, 7), (67, 103), (68, 1), (102, 31),
                    (145, 4), (212, 9), (283, 30), (291, 6), (412, 39), (900, 50), (905, 28), (1024, 8),
                    (1800, 13), (2048, 3), (15000, 40)]
        return postings
    
    def make_file(self, name):
        return self.fs.create_file(name+"_test.pst")
    
    def open_file(self, name):
        return self.fs.open_file(name+"_test.pst")
    
    def delete_file(self, name):
        try:
            self.fs.delete_file(name+"_test.pst")
        except OSError:
            pass
    
    def test_readwrite(self):
        format = Frequency(None)
        postings = self.make_postings()
        
        postfile = self.make_file("readwrite")
        try:
            fpw = FilePostingWriter(postfile, blocklimit=8)
            fpw.start(format)
            for id, freq in postings:
                fpw.write(id, format.encode(freq))
            fpw.close()
            
            postfile = self.open_file("readwrite")
            fpr = FilePostingReader(postfile, 0, format)
            #self.assertEqual(postings, list(fpr.items_as("frequency")))
            fpr.close()
        finally:
            self.delete_file("readwrite")
        
    def test_skip(self):
        format = Frequency(None)
        postings = self.make_postings()
        
        postfile = self.make_file("skip")
        try:
            fpw = FilePostingWriter(postfile, blocklimit=8)
            fpw.start(format)
            for id, freq in postings:
                fpw.write(id, format.encode(freq))
            fpw.close()
            
            postfile = self.open_file("skip")
            fpr = FilePostingReader(postfile, 0, format)
            #fpr.skip_to(220)
            #self.assertEqual(postings[10:], list(fpr.items_as("frequency")))
            fpr.close()
        finally:
            self.delete_file("skip")
    
    def roundtrip(self, postings, format, astype):
        postfile = self.make_file(astype)
        readback = None
        try:
            fpw = FilePostingWriter(postfile, blocklimit=8)
            fpw.start(format)
            for id, value in postings:
                fpw.write(id, format.encode(value))
            fpw.close()
            
            postfile = self.open_file(astype)
            fpr = FilePostingReader(postfile, 0, format)
            readback = list(fpr.all_as(astype))
            fpr.close()
        finally:
            self.delete_file(astype)
        return readback
    
    def test_existence_postings(self):
        postings = []
        docnum = 0
        for _ in xrange(0, 20):
            docnum += randint(1, 10)
            postings.append((docnum, 1))
        
        self.assertEqual(postings, self.roundtrip(postings, Existence(None), "frequency"))
    
    def test_docboost_postings(self):
        postings = []
        docnum = 0
        for _ in xrange(0, 20):
            docnum += randint(1, 10)
            freq = randint(1, 1000)
            boost = byte_to_float(float_to_byte(random() * 2))
            postings.append((docnum, (freq, boost)))
        
        self.assertEqual(postings, self.roundtrip(postings, DocBoosts(None), "docboosts"))
        
#.........这里部分代码省略.........
开发者ID:SpaceAppsXploration,项目名称:whoosh,代码行数:103,代码来源:test_postings.py


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