本文整理汇总了Python中index.Index.search方法的典型用法代码示例。如果您正苦于以下问题:Python Index.search方法的具体用法?Python Index.search怎么用?Python Index.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类index.Index
的用法示例。
在下文中一共展示了Index.search方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from index import Index [as 别名]
# 或者: from index.Index import search [as 别名]
class Kbase:
def init(self, *file):
self.rules = []
self.if_index = Index().init()
self.then_index = Index().init()
if file:
self.load_rules(file[0])
return self
def remove_rule(self, id):
for i in range(len(self.rules)):
if self.rules[i]["rule"] == id:
del self.rules[i]
for if1 in self.rules[i]["if"]:
self.if_index.delete(if1)
for then in self.rules[i]["then"]:
self.then_index.delete(then)
def add_rule(self, rule):
self.index_rule(rule)
self.rules.append(rule)
def index_rule(self, rule):
for if1 in rule["if"]:
self.if_index.store(if1, rule) # fwd: fact/if index tree
for then in rule["then"]:
self.then_index.store(then, rule) # bkwd: goal/then index tree
def match_if(self, fact):
return self.if_index.search(fact)
def match_then(self, goal, dict):
return self.then_index.search(goal, dict)
def load_rules(self, name):
try:
file = open(strip(name), "r")
contents = file.read() # 'rule. rule.'
rules = splitfields(contents, ".") # ['rule','rule','']
del rules[len(rules) - 1] # ['rule','rule']
for rule in rules:
self.add_rule(internal_rule(rule)) # [{rule},{rule}]
file.close()
except IOError, cause:
print "file error:", cause
示例2: exit
# 需要导入模块: from index import Index [as 别名]
# 或者: from index.Index import search [as 别名]
exit()
count = 1
keywords = index.get_keywords()
keywords.sort()
with open(filename) as f:
# Utilize um método eficiente para verificar se uma
# palavra lida do texto pertence ao índice.
# TODO: Improve 2 loops
for line in f:
words = line.split()
for i in keywords:
if index.verify(i, words):
index.add(i, count)
count += 1
word = input(
"\nSet a word to search in this index: "
)
print('------------------------\n')
index.search(word)
print('------------------------\n')
index.show()
print('------------------------\n')
示例3: raw_input
# 需要导入模块: from index import Index [as 别名]
# 或者: from index.Index import search [as 别名]
while 1:
query = raw_input('query> ')
query = unicode(query, 'iso-8859-15')
try:
kw = {'autoexpand' : 'off',
'ranking' : True,
'ranking_maxhits' : 100,
'field' : 'SearchableText',
}
if options.thesaurus:
kw['thesaurus'] = options.thesaurus
ts = time.time()
if options.profile:
prof = hotshot.Profile('query.prof')
result = prof.runcall(I.search, query, **kw)
stats = hotshot.stats.load('query.prof')
stats.strip_dirs()
stats.sort_stats('cumulative', 'calls')
stats.print_stats(25)
else:
result = I.search(query, **kw)
te = time.time()
for docid,score in result.getRankedResults().items():
print ID2FILES[docid], score
print '%2.5lf milli-seconds' % (1000.0*(te-ts))
except:
import traceback
traceback.print_exc()