本文整理汇总了Python中addok.db.DB.smembers方法的典型用法代码示例。如果您正苦于以下问题:Python DB.smembers方法的具体用法?Python DB.smembers怎么用?Python DB.smembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addok.db.DB
的用法示例。
在下文中一共展示了DB.smembers方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_index_document
# 需要导入模块: from addok.db import DB [as 别名]
# 或者: from addok.db.DB import smembers [as 别名]
def test_index_document():
index_document(DOC.copy())
assert DB.exists('d|xxxx')
assert DB.type('d|xxxx') == b'hash'
assert DB.exists('w|rue')
assert b'd|xxxx' in DB.zrange('w|rue', 0, -1)
assert DB.exists('w|des')
assert DB.exists('w|lilas')
assert DB.exists('w|andresy')
assert DB.exists('w|un') # Housenumber.
assert DB.exists('p|rue')
assert DB.exists('p|des')
assert DB.exists('p|lilas')
assert DB.exists('p|andresy')
assert b'lilas' in DB.smembers('p|andresy')
assert b'andresy' in DB.smembers('p|lilas')
assert DB.exists('p|un')
assert DB.exists('g|u09dgm7')
assert b'd|xxxx' in DB.smembers('g|u09dgm7')
assert DB.exists('n|lil')
assert DB.exists('n|lila')
assert DB.exists('n|and')
assert b'andresy' in DB.smembers('n|and')
assert DB.exists('n|andr')
assert b'andresy' in DB.smembers('n|andr')
assert DB.exists('n|andre')
assert b'andresy' in DB.smembers('n|andre')
assert DB.exists('n|andres')
assert b'andresy' in DB.smembers('n|andres')
assert b'lilas' in DB.smembers('n|lil')
assert DB.exists('f|type|street')
assert b'd|xxxx' in DB.smembers('f|type|street')
assert DB.exists('f|type|housenumber')
assert b'd|xxxx' in DB.smembers('f|type|housenumber')
assert len(DB.keys()) == 20
示例2: test_index_edge_ngrams
# 需要导入模块: from addok.db import DB [as 别名]
# 或者: from addok.db.DB import smembers [as 别名]
def test_index_edge_ngrams():
before = count_keys()
index_edge_ngrams(DB, 'street')
after = count_keys()
assert after - before == 3
assert DB.smembers('n|str') == set([b'street'])
assert DB.smembers('n|stre') == set([b'street'])
assert DB.smembers('n|stree') == set([b'street'])
示例3: pair
# 需要导入模块: from addok.db import DB [as 别名]
# 或者: from addok.db.DB import smembers [as 别名]
def pair(word):
"""See all token associated with a given token.
PAIR lilas"""
word = list(preprocess_query(word))[0]
key = pair_key(word)
tokens = [t.decode() for t in DB.smembers(key)]
tokens.sort()
print(white(tokens))
print(magenta('(Total: {})'.format(len(tokens))))
示例4: test_deindex_document_should_not_affect_other_docs
# 需要导入模块: from addok.db import DB [as 别名]
# 或者: from addok.db.DB import smembers [as 别名]
def test_deindex_document_should_not_affect_other_docs():
DOC2 = {
'id': 'xxxx2',
'type': 'street',
'name': 'rue des Lilas',
'city': 'Paris',
'lat': '49.32545',
'lon': '4.2565',
'housenumbers': {
'1': {
'lat': '48.325451', # Same geohash as DOC.
'lon': '2.25651'
}
}
}
index_document(DOC.copy())
index_document(DOC2)
deindex_document(DOC['id'])
assert not DB.exists('d|xxxx')
assert DB.exists('w|rue')
assert DB.exists('w|des')
assert DB.exists('w|lil')
assert DB.exists('w|un') # Housenumber.
assert b'd|xxxx' not in DB.zrange('w|rue', 0, -1)
assert b'd|xxxx' not in DB.zrange('w|des', 0, -1)
assert b'd|xxxx' not in DB.zrange('w|lil', 0, -1)
assert b'd|xxxx' not in DB.zrange('w|un', 0, -1)
assert DB.exists('g|u09dgm7')
assert b'd|xxxx' not in DB.smembers('g|u09dgm7')
assert b'd|xxxx2' in DB.zrange('w|rue', 0, -1)
assert b'd|xxxx2' in DB.zrange('w|des', 0, -1)
assert b'd|xxxx2' in DB.zrange('w|lil', 0, -1)
assert b'd|xxxx2' in DB.zrange('w|un', 0, -1)
assert b'd|xxxx2' in DB.smembers('g|u09dgm7')
assert b'd|xxxx2' in DB.smembers('g|u0g08g7')
assert DB.exists('f|type|street')
assert b'd|xxxx2' in DB.smembers('f|type|street')
assert DB.exists('f|type|housenumber')
assert b'd|xxxx2' in DB.smembers('f|type|housenumber')
assert len(DB.keys()) == 14
示例5: do_autocomplete
# 需要导入模块: from addok.db import DB [as 别名]
# 或者: from addok.db.DB import smembers [as 别名]
def do_autocomplete(self, s):
"""Shows autocomplete results for a given token."""
s = list(preprocess_query(s))[0]
keys = [k.decode() for k in DB.smembers(edge_ngram_key(s))]
print(white(keys))
print(magenta('({} elements)'.format(len(keys))))