本文整理汇总了Python中searcher.Searcher.search方法的典型用法代码示例。如果您正苦于以下问题:Python Searcher.search方法的具体用法?Python Searcher.search怎么用?Python Searcher.search使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类searcher.Searcher
的用法示例。
在下文中一共展示了Searcher.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scrape
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
def scrape(self):
self.scrape_results = defaultdict(lambda: defaultdict(list))
for category_of_document_path in self.qd_dict:
for file in self.qd_dict[category_of_document_path]:
s = Searcher(category_of_document_path, file, self.qd_dict)
s.search()
self.scrape_results[os.path.split(category_of_document_path)[1]][os.path.splitext(file)[0]] = s.results
print len(self.scrape_results)
示例2: SearcherTests
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
class SearcherTests(unittest.TestCase):
"""
Test case for SearchEngine class.
"""
def setUp(self):
"""
Setup search engine that will be subjected to the tests.
"""
self.twitter = Twitter(CUR_DIR + "/test_crossfit.tweets", CUR_DIR + "/test_stop_words.txt")
self.twitter.load_tweets_and_build_index()
self.searcher = Searcher(self.twitter.tweets, self.twitter.stop_words)
def test_indexed_doc_count(self):
self.assertEqual(self.searcher.count(), 10)
def test_existent_term_search(self):
"""
Test if search is correctly performed.
"""
results = self.searcher.search("coach")
expected_results = 3
self.assertEqual(results[0].indexable.docid, expected_results)
def test_non_existent_term_search(self):
"""
Test if search is correctly performed.
"""
expected_results = []
results = self.searcher.search("asdasdasdas")
self.assertListEqual(results, expected_results)
def test_search_result_limit(self):
"""
Test if search results can be limited.
"""
results = self.searcher.search("crossfit", 1)
expected_results = 6
self.assertEqual(results[0].indexable.docid, expected_results)
示例3: load
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
def load(self):
if os.path.exists(self.file_path):
f = open(self.file_path, "r")
conn_map = pickle.load(f)
f.close()
return conn_map
conn_maps = {}
for name, conn in self.connections.items():
conn_map = {}
searcher = Searcher(conn)
searcher.search()
conn_map["tables"] = searcher.tables
conn_map["connection"] = searcher.connection
conn_maps[name] = conn_map
f = open(self.file_path, "w")
pickle.dump(conn_maps, f)
f.close()
return conn_maps
示例4: MainWindow
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.setWindowTitle("Search My Workspace")
# List to display search results
self.searchResultsModel = SearchResultsModel()
self.listView_result.setModel(self.searchResultsModel)
searchResultsDelegate = SearchResultsDelegate(self.listView_result)
self.listView_result.setItemDelegate(searchResultsDelegate);
# Tree to display facets
self.facetModel = FacetModel()
self.treeView_facet.setModel(self.facetModel)
self.facetModel.modelReset.connect(self.treeView_facet.expandAll)
# searcher
self.searcher = Searcher()
self.searcher.searchDone.connect(self.searchDone)
# signal slots
self.createConnections()
''' connect signal/slot pairs '''
def createConnections(self):
self.pushButton_search.clicked.connect(self.searchResultsModel.clearMyModel)
self.pushButton_search.clicked.connect(self.facetModel.clearMyModel)
self.pushButton_search.clicked.connect(self.search)
def search(self):
query = self.lineEdit_search.text()
self.searcher.search(query)
def searchDone(self):
self.searchResultsModel.handleSearchResults(self.searcher.getDocs())
self.facetModel.handleSearchResults(self.searcher.getFacets())
self.label_searchResult.setText('About {0} search results for [{1}]'.format(self.searcher.getHits(), self.searcher.getQuery()))
示例5: MainWindow
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.searchResultsView = SearchResultsView(self.listView_result)
self.searchResultsView.viewDetailedContent.connect(self.showDetailedContent)
self.facetView = FacetView(self.treeView_facet)
self.facetView.facetOptionChanged.connect(self.search)
# searcher
self.searcher = Searcher()
self.searcher.searchDone.connect(self.searchDone)
self.createConnections()
def createConnections(self):
self.pushButton_search.clicked.connect(self.searchResultsView.clear)
self.pushButton_search.clicked.connect(self.facetView.clear)
self.pushButton_search.clicked.connect(self.search)
def search(self):
query = self.lineEdit_search.text()
options = self.facetView.getFacetSearchOptions()
self.searcher.search(query, options)
def showDetailedContent(self, fileLocation):
myviewer = viewer.viewerSimpleFactory(fileLocation, self)
myviewer.showDetailedContent()
@QtCore.Slot(int)
def searchDone(self, searchResultCount):
if searchResultCount > 0:
self.searchResultsView.handleSearchResults(self.searcher.getDocs(), self.searcher.getHighlighting())
self.facetView.handleSearchResults(self.searcher.getFacets())
self.label_searchResult.setText('About {0} search results for [{1}]'.format(searchResultCount, self.searcher.getQuery()))
示例6: Match
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
def Match(queryname,k):
folder="static"
queryImage = cv2.imread(os.path.join(folder,queryname))
desc = RGBHistogram([8, 8, 8])
# load the index perform the search
#index = cPickle.loads(open("index.txt").read())
d = min(division(queryImage),7)
folder='indexIMG'
index = shelve.open(os.path.join(folder,'f%d.shelve'%d))
searcher = Searcher(index)
queryFeatures = desc.describe(queryImage)
results = searcher.search(queryFeatures)
l=len(results)
lastRes=results[:min(k,l)]
return lastRes
示例7: search
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
def search(img):
# initialize the image descriptor
cd = ColorDescriptor((8, 12, 3))
# load the query image and describe it
#query = cv2.imread(args["query"])
#query = cv2.imread("queries/2.png")
features = cd.describe(img)
# perform the search
searcher = Searcher("feature.csv")
results = searcher.search(features)
return results
示例8: main_search
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
def main_search(self):
cd = ColorDescriptor((8, 12, 3))
# load the query image and describe it
query = cv2.imread('test_dataset/'+self.name)
features = cd.describe(query)
# perform the search
searcher = Searcher(self.file_path)
results = searcher.search(features)
# display the query
cv2.imshow("Query",query)
# loop over the results
for (score, resultID) in results:
# load the result image and display it
result = cv2.imread(self.data_path + "/" + resultID)
r=300.0/result.shape[1]
dim=(300,int(result.shape[0]*r))
resized = cv2.resize(result, dim, interpolation = cv2.INTER_AREA)
cv2.imshow("RESULT", resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
示例9: mask
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
ap.add_argument("-r", "--result-path", required = True,
help = "Path to the result path")
ap.add_argument("-m", "--mask", required = True,
help = "Path to image mask (same size as images) to break into a grid")
ap.add_argument("-g", "--gridsize", required = True,
help = "Dimension for a single width/height for the square grid mask")
args = vars(ap.parse_args())
# initialize the image descriptor
cd = ColorDescriptor((8, 12, 3),args["mask"],args["gridsize"])
# load the query image and describe it
query = cv2.imread(args["query"])
features = cd.describe(query)
# perform the search
searcher = Searcher(args["index"])
scores,image_names = searcher.search(features)
# display the query
cv2.imshow("Query", query)
# loop over the results
for x in range(0,len(scores)):
resultID = image_names[x]
print "Similar image %s is %s, score: %s" %(x,resultID,scores[x])
# load the result image and display it
result = cv2.imread(args["result_path"] + "/" + resultID)
cv2.imshow("Result", result)
cv2.waitKey(0)
示例10: Twitter
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
class Twitter(object):
"""Class representing a inventory of books.
Args:
tweets_filename (str): File name containing tweets.
stop_words_filename (str): File name containing stop words.
Attributes:
teets(list): List of original tweets.
stop_words (list): List of stop words.
indexer (Indexer): Object responsible for indexing tweets.
searcher (Searcher): Object responsible for searching tweets.
"""
_TWEET_META_TEXT_INDEX = 0
_TWEET_META_SCREEN_NAME_INDEX = 1
_NO_RESULTS_MESSAGE = "Sorry, no results."
def __init__(self, tweets_filename, stop_words_filename):
self.tweets = []
self.tweets_filename = tweets_filename
self.stop_words = self.__load_stop_words(stop_words_filename)
self.indexer = Indexer(self.stop_words)
self.searcher = []
@timed
def load_tweets(self):
"""Load tweets from a file name.
This method leverages the iterable behavior of File objects
that automatically uses buffered IO and memory management handling
effectively large files.
"""
docid = 0
processor = TwitterDataPreprocessor()
with open(self.tweets_filename) as catalog:
for entry in catalog:
# preprocessing
p_entry = processor.preprocess(entry)
text = p_entry[self._TWEET_META_TEXT_INDEX].strip()
screen_name = ''
if len(p_entry) > 1:
screen_name = p_entry[self._TWEET_META_SCREEN_NAME_INDEX].strip()
indexable_data = text + ' ' + screen_name
original_data = entry
tweet = Tweet(docid, indexable_data, original_data)
self.tweets.append(tweet)
docid += 1
@timed
def load_tweets_and_build_index(self):
"""Load tweets from a file name, build index, compute ranking and save them all.
"""
self.load_tweets()
self.indexer.build_and_save(self.tweets)
@timed
def load_tweets_and_load_index(self):
"""Load tweets from a file name and load index from a file name.
"""
self.load_tweets()
self.searcher = Searcher(self.tweets, self.stop_words)
@timed
def search_tweets(self, query, n_results=10):
"""Search tweets according to provided query of terms.
The query is executed against the indexed tweets, and a list of tweets
compatible with the provided terms is return along with their tf-idf
score.
Args:
query (str): Query string with one or more terms.
n_results (int): Desired number of results.
Returns:
list of IndexableResult: List containing tweets and their respective
tf-idf scores.
"""
result = ''
if len(query) > 0:
result = self.searcher.search(query, n_results)
if len(result) > 0:
return "{:,}".format(self.searcher.search_count()) \
+ " results.\n\n" \
+ "".join([str(indexable) for indexable in result])
return self._NO_RESULTS_MESSAGE
def tweets_count(self):
"""Return number of loaded tweets.
#.........这里部分代码省略.........
示例11: matcher
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
def matcher(Dataset,Query):
dataset='uploads'
query_image=Query
index='index.csv'
res=0
res1=0
cd=descriptor((8,12,3))
query=cv2.imread(query_image)
gray=cv2.cvtColor(query,cv2.COLOR_BGR2GRAY)
cv2.imwrite('grey.jpg',gray)
query_grey=cv2.imread('grey.jpg')
features=cd.describe(query)
features_grey=cd.describe(query_grey)
searcher=Searcher(index)
results=searcher.search(features)
results_grey=searcher.search(features_grey)
#cv2.imshow("Query",query)
for (score,resultID) in results:
result=cv2.imread(dataset+resultID)
#m=match(query_image,dataset+resultID)
#cv2.imshow("Result",result)
print(resultID)
if score < 7.95:
print(score)
t=math.floor(score)
res=100-t
print(100-t)
else:
print(score)
t=math.floor(score)
res=t
print(t+t)
#cv2.waitKey(0)
print("---------------grey---------------")
for (score,resultID) in results_grey:
result=cv2.imread(dataset+resultID)
#cv2.imshow("Result",result)
print(resultID)
if score < 7.95:
print(score)
t=math.floor(score)
res1=100-t
print(100-t)
else:
print(score)
t=math.floor(score)
res1=t
print(t+t)
#cv2.waitKey(0)
return (res,res1)
示例12: RGBHistogram
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
# load the query image and show it
queryImage = cv2.imread(args["query"])
cv2.imshow("Query", queryImage)
print "query: %s" % (args["query"])
# describe the query in the same way that we did in
# index.py -- a 3D RGB histogram with 8 bins per
# channel
desc = RGBHistogram([8, 8, 8])
queryFeatures = desc.describe(queryImage)
# load the index perform the search
index = cPickle.loads(open(args["index"]).read())
searcher = Searcher(index)
results = searcher.search(queryFeatures)
# initialize the two montages to display our results --
# we have a total of 25 images in the index, but let's only
# display the top 10 results; 5 images per montage, with
# images that are 400x166 pixels
# montageA = np.zeros((166 * 5, 400, 3), dtype = "uint8")
# montageB = np.zeros((166 * 5, 400, 3), dtype = "uint8")
# montageA = np.zeros((40 * 5, 100, 3), dtype = "uint8")
# montageB = np.zeros((40 * 5, 100, 3), dtype = "uint8")
# loop over the top ten results
for j in xrange(0, 10):
# grab the result (we are using row-major order) and
# load the result image
示例13: GCHDescriptor
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
queryDesc = GCHDescriptor((9, 12, 4))
indexFilepath = "indexes/gchindex.csv"
elif(args["method"].upper() == "LCH"):
queryDesc = LCHDescriptor((9, 12, 3))
indexFilepath = "indexes/lchindex.csv"
else:
sys.exit("\nMetodo descritor invalido!\n")
# carrega a imagem de consulta em memoria e aplica o descritor
query = cv2.imread(args["query"])
queryFeatures = queryDesc.describe(query)
# inicializa um objeto que ira' fazer a comparacao da imagem de consulta com o banco de imagens
searcher = Searcher(indexFilepath)
# realiza a consulta das n-imagens mais semelhantes
results = searcher.search(queryFeatures, int(args["limit"]), args["distance"])
############################## DESCOMENTAR AQUI PRA MANDAR #####################################################
# percorre o vetor com as imagens mais semelhantes e imprime na saida padrao em ordem decrescente de similaridade
#for (score, imageID) in results:
# print imageID
################################################################################################################
t2 = time.time()
print "Tempo: %.2f s" % (t2 - t1)
############################## COMENTAR DAQUI PARA BAIXO SE DESCOMENTAR EM CIMA ######################################################
r = 800.0 / query.shape[1]
dim = (800, int(query.shape[0] * r))
resized = cv2.resize(query, dim, interpolation = cv2.INTER_AREA)
cv2.imshow("Query", resized)
示例14: gen_path
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
'''
used default _date field to generate the file path where the doc is stored
'''
def gen_path(self, doc):
if not doc.has_key('_date'):
doc['_date'] = datetime.now(tz.tzlocal())
dt = doc['_date']
return os.path.sep.join([self.dir, str(dt.year), str(dt.month), \
str(dt.day) + '.sen'])
if __name__ == '__main__':
defi = DefinitionIndexer('/data/personalSite/app/web/static/definition')
defs = Searcher(defi)
with defs.open() as searcher:
r = defs.search(searcher, 'content', u'developing')
found = r.scored_length()
print found
for rr in r:
print rr['id']
'''
si = SenIndexer('sen')
di = DocIndexer('doc')
ss = Searcher(si)
ds = Searcher(di)
di.doc_op({
'content': u'doc',
'tags': [u't'],
'categories': [],
'comments': u'docc',
示例15: vars
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search [as 别名]
import argparse
import cv2
import time
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--index", default='index.csv',
help="Path to where the computed index will be stored")
ap.add_argument("-l", "--limit", default=10,
help="Query result limit")
ap.add_argument("-d", "--dist", default='euclidean',
help="Distance model")
ap.add_argument("-q", "--query", required=True,
help="Path to the query image")
args = vars(ap.parse_args())
# initialize the image descriptor
cd = ColorDescriptor((8, 12, 3))
# load the query image and describe it
query = cv2.imread(args["query"])
features = cd.describe(query)
# perform the search
searcher = Searcher(args["index"])
results = searcher.search(features, int(args["limit"]), args["dist"])
# loop over the results
for (score, resultID) in results:
# load the result image and display it
print resultID