def copy_top_match(querydir, query, ranked_matches, match): topentry = ranked_matches[0] matchedimg = topentry[0] score = topentry[1] dup = "dup" + str(len(ranked_matches) == 1 or score == ranked_matches[1][1]) qlat = float(query.split(',')[1]) qlon = float(query.split(',')[2]) clat = float(matchedimg.split(",")[0]) clon = float(matchedimg.split(",")[1][0:-5]) distance = info.distance(qlat, qlon, clat, clon) queryimgpath = os.path.join(querydir, query + '.pgm') queryoutpath = os.path.join(resultsdir, query + ';query;gt' + str(match) + ';' + dup + ';' + matchedimg + ';' + str(score) + ';' + str(distance) + '.pgm') shutil.copyfile(queryimgpath, queryoutpath) for matchedimg, score in ranked_matches: if score != topentry[1]: break clat = float(matchedimg.split(",")[0]) clon = float(matchedimg.split(",")[1][0:-5]) distance = info.distance(qlat, qlon, clat, clon) matchimgpath = os.path.join(dbdump, '%s.jpg' % matchedimg) matchoutpath = os.path.join(resultsdir, query + ';match;gt' + str(match) + ';' + dup + ';' + matchedimg + ';' + str(score) + ';' + str(distance) + '.jpg') shutil.copy(matchimgpath, matchoutpath)
def copy_top_match(querydir, query, ranked_matches, match): topentry = ranked_matches[0] matchedimg = topentry[0] score = topentry[1] dup = "dup" + str( len(ranked_matches) == 1 or score == ranked_matches[1][1]) qlat = float(query.split(',')[1]) qlon = float(query.split(',')[2]) clat = float(matchedimg.split(",")[0]) clon = float(matchedimg.split(",")[1][0:-5]) distance = info.distance(qlat, qlon, clat, clon) queryimgpath = os.path.join(querydir, query + '.pgm') queryoutpath = os.path.join( resultsdir, query + ';query;gt' + str(match) + ';' + dup + ';' + matchedimg + ';' + str(score) + ';' + str(distance) + '.pgm') shutil.copyfile(queryimgpath, queryoutpath) for matchedimg, score in ranked_matches: if score != topentry[1]: break clat = float(matchedimg.split(",")[0]) clon = float(matchedimg.split(",")[1][0:-5]) distance = info.distance(qlat, qlon, clat, clon) matchimgpath = os.path.join(dbdump, '%s.jpg' % matchedimg) matchoutpath = os.path.join( resultsdir, query + ';match;gt' + str(match) + ';' + dup + ';' + matchedimg + ';' + str(score) + ';' + str(distance) + '.jpg') shutil.copy(matchimgpath, matchoutpath)
def getResultsFrom_QrelsFile(listOfQueryRelsMaping, dictOfQuery): dictOfResult = collections.defaultdict(list) for query in listOfQueryRelsMaping: data = query.split() if data[0] in dictOfQuery: dictOfResult[data[0]].append(data[1]) return dictOfResult
def main(database=None): always_return_json = "false" try: password = get_password("CRAWL_PASSWORD") args = get_args() if database == None: if "database" not in args: database = DEFAULT_URL else: database = args["database"] del args["database"] if "always_return_json" in args: if args["always_return_json"] == "true" or args["always_return_json"] == "false": always_return_json = args["always_return_json"] del args["always_return_json"] if "query" not in args: raise ropy.ServerException( "Please provide a -query argument, e.g. '-query genes/list'.", ropy.ERROR_CODES["UNKOWN_QUERY"], print_classes(), ) else: query = args["query"] del args["query"] if "/" not in query: api = get_api(query) raise ropy.ServerException( "Please provide 2 parts to the -query argument, the path and the function, separated by a '/', e.g. '-query genes/list'.", ropy.ERROR_CODES["UNKOWN_QUERY"], print_methods(api), ) (path, function) = query.split("/", 2) print execute(path, function, args, database, password) except ropy.ServerException, e: if always_return_json == "true": fail_with_json(e.code + 1) # import traceback # logger.error(traceback.format_exc()) # logger.error(e) print "Error:" print e.value print BASIC_USAGE if e.info != None: print e.info sys.exit(e.code + 1)