Commit df224864 authored by Manuel Günther's avatar Manuel Günther
Browse files

Adapted output of reverse function to be compatible with new verification...

Adapted output of reverse function to be compatible with new verification utils; added driver API functions for reverse and paths query functions.
parent d37e8fdf
......@@ -9,7 +9,7 @@ from setuptools import setup, find_packages
setup(
name='xbob.db.atnt',
version='1.0.0',
version='1.0.1',
description='ATNT/ORL Database Access API for Bob',
url='http://github.com/bioidiap/bob.db.nuaa',
license='GPLv3',
......@@ -25,7 +25,7 @@ setup(
install_requires=[
'setuptools',
'bob', # base signal proc./machine learning library
'xbob.db.verification.utils' # defines a set of utilities for face verification databases like this one.
'xbob.db.verification.utils>=0.1.4' # defines a set of utilities for face verification databases like this one.
],
namespace_packages = [
......
......@@ -46,6 +46,7 @@ def dumplist(args):
return 0
def checkfiles(args):
"""Checks the existence of the files based on your criteria."""
......@@ -75,6 +76,46 @@ def checkfiles(args):
return 0
def reverse(args):
"""Returns a list of file database identifiers given the path stems"""
from .query import Database
db = Database()
output = sys.stdout
if args.selftest:
from bob.db.utils import null
output = null()
r = db.reverse(args.path)
for f in r: output.write('%s\n' % f.id)
if not r: return 1
return 0
def path(args):
"""Returns a list of fully formed paths or stems given some file id"""
from .query import Database
db = Database()
output = sys.stdout
if args.selftest:
from bob.db.utils import null
output = null()
r = db.paths(args.id, prefix=args.directory, suffix=args.extension)
for path in r: output.write('%s\n' % path)
if not r: return 1
return 0
class Interface(BaseInterface):
def name(self):
......@@ -120,3 +161,17 @@ class Interface(BaseInterface):
check_parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
check_parser.set_defaults(func=checkfiles) #action
# adds the "reverse" command
parser = subparsers.add_parser('reverse', help=reverse.__doc__)
parser.add_argument('path', nargs='+', help="one or more path stems to look up. If you provide more than one, files which cannot be reversed will be omitted from the output.")
parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=reverse) #action
# adds the "path" command
parser = subparsers.add_parser('path', help=path.__doc__)
parser.add_argument('-d', '--directory', help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', help="if given, this extension will be appended to every entry returned.")
parser.add_argument('id', type=int, nargs='+', help="one or more file ids to look up. If you provide more than one, files which cannot be found will be omitted from the output. If you provide a single id to lookup, an error message will be printed if the id does not exist in the database. The exit status will be non-zero in such case.")
parser.add_argument('--self-test', dest="selftest", action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=path) #action
......@@ -180,7 +180,7 @@ class Database(xbob.db.verification.utils.Database):
return retval
def paths(self, file_ids, prefix='', suffix=''):
def paths(self, file_ids, prefix=None, suffix=None, preserve_order=True):
"""Returns a full file paths considering particular file ids, a given
directory and an extension
......@@ -196,6 +196,9 @@ class Database(xbob.db.verification.utils.Database):
The extension determines the suffix that will be appended to the filename
stem.
preserve_order
Ignored since the order is always preserved.
Returns a list (that may be empty) of the fully constructed paths given the
file ids.
"""
......@@ -204,17 +207,21 @@ class Database(xbob.db.verification.utils.Database):
return [f.make_path(prefix, suffix) for f in files]
def reverse(self, paths):
"""Reverses the lookup: from certain stems, returning file ids
def reverse(self, paths, preserve_order=True):
"""Reverses the lookup: from certain paths, return a list of
File objects
Keyword Parameters:
paths
The filename stems I'll query for. This object should be a python
The filename stems to query for. This object should be a python
iterable (such as a tuple or list)
preserve_order
Ignored since the order is always preserved.
Returns a list (that may be empty).
"""
return [File.from_path(p).id for p in paths]
return [File.from_path(p) for p in paths]
......@@ -78,7 +78,7 @@ class ATNTDatabaseTest(unittest.TestCase):
self.assertEqual(os.path.splitext(parts[1])[1], '.tmp')
# test the reverse function
tested_ids = db.reverse(paths)
tested_ids = [f.id for f in db.reverse(paths)]
self.assertEqual(ids, tested_ids)
......@@ -88,5 +88,7 @@ class ATNTDatabaseTest(unittest.TestCase):
self.assertEqual(main('atnt dumplist --self-test'.split()), 0)
self.assertEqual(main('atnt checkfiles -d "." --self-test'.split()), 0)
self.assertEqual(main('atnt reverse s34/1 --self-test'.split()), 0)
self.assertEqual(main('atnt path 331 --self-test'.split()), 0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment