Mercurial > hg > audiodb
changeset 672:a35ca2d5f238
Extend results structure to include a key for the query.
Fill that key from the query datum, if given, defaulting to ""; patch up
bindings and tests.
This is so that (Instance x Instance) operations such as querying and
sampling can be supported.
author | mas01cr |
---|---|
date | Fri, 05 Mar 2010 16:00:53 +0000 |
parents | 537bfd7e15a1 |
children | e1f7cab30701 |
files | audioDB-internals.h audioDB.cpp audioDB_API.h bindings/pd/adbpd.c bindings/python/pyadbmodule.c bindings/sb-alien/interface.lisp bindings/sb-alien/library.lisp libtests/test_utils_lib.h pertrackaccumulator.h query-indexed.cpp query.cpp |
diffstat | 11 files changed, 36 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/audioDB-internals.h Fri Mar 05 16:00:49 2010 +0000 +++ b/audioDB-internals.h Fri Mar 05 16:00:53 2010 +0000 @@ -123,9 +123,9 @@ typedef struct { bool operator() (const adb_result_t &r1, const adb_result_t &r2) { - return strcmp(r1.key, r2.key) < 0; + return strcmp(r1.ikey, r2.ikey) < 0; } -} adb_result_key_lt; +} adb_result_ikey_lt; typedef struct { bool operator() (const adb_result_t &r1, const adb_result_t &r2) { @@ -150,7 +150,7 @@ return ((r1.ipos < r2.ipos) || ((r1.ipos == r2.ipos) && ((r1.qpos < r2.qpos) || - ((r1.qpos == r2.qpos) && (strcmp(r1.key, r2.key) < 0))))); + ((r1.qpos == r2.qpos) && (strcmp(r1.ikey, r2.ikey) < 0))))); } } adb_result_triple_lt; @@ -168,6 +168,7 @@ std::priority_queue<PointPair> *exact_evaluation_queue; std::set< adb_result_t, adb_result_triple_lt > *set; LSH *lsh; + const char *qkey; } adb_qstate_internal_t; /* We could go gcc-specific here and use typeof() instead of passing
--- a/audioDB.cpp Fri Mar 05 16:00:49 2010 +0000 +++ b/audioDB.cpp Fri Mar 05 16:00:53 2010 +0000 @@ -965,7 +965,7 @@ for(unsigned int k = 0; k < rs->nresults; k++) { adb_result_t r = rs->results[k]; - reporter->add_point(audiodb_key_index(adb, r.key), r.qpos, r.ipos, r.dist); + reporter->add_point(audiodb_key_index(adb, r.ikey), r.qpos, r.ipos, r.dist); } audiodb_query_free_results(adb, &qspec, rs);
--- a/audioDB_API.h Fri Mar 05 16:00:49 2010 +0000 +++ b/audioDB_API.h Fri Mar 05 16:00:53 2010 +0000 @@ -49,10 +49,11 @@ } adb_status_t; typedef struct adb_result { - const char *key; - double dist; + const char *qkey; + const char *ikey; uint32_t qpos; uint32_t ipos; + double dist; } adb_result_t; #define ADB_REFINE_INCLUDE_KEYLIST 1
--- a/bindings/pd/adbpd.c Fri Mar 05 16:00:49 2010 +0000 +++ b/bindings/pd/adbpd.c Fri Mar 05 16:00:53 2010 +0000 @@ -291,7 +291,7 @@ outlet_float(x->x_qpos,r.qpos); outlet_float(x->x_spos,r.ipos); - post("in obj key:%s",r.key); + post("in obj ikey:%s",r.ikey); post("in obj Dist:%f", r.dist); post("in obj qpos:%d", r.qpos); post("in obj ipos:%d", r.ipos);
--- a/bindings/python/pyadbmodule.c Fri Mar 05 16:00:49 2010 +0000 +++ b/bindings/python/pyadbmodule.c Fri Mar 05 16:00:53 2010 +0000 @@ -348,14 +348,14 @@ if(strcmp(resFmt, "dict")==0){ outgoing = PyDict_New(); for (i=0;i<result->nresults;i++){ - thisKey = PyString_FromString(result->results[i].key); + thisKey = PyString_FromString(result->results[i].ikey); if (!PyDict_Contains(outgoing, thisKey)){ newBits = Py_BuildValue("[(dII)]", result->results[i].dist, result->results[i].qpos, result->results[i].ipos); if (PyDict_SetItem(outgoing, thisKey,newBits)){ - printf("key : %s\ndist : %f\nqpos : %i\nipos : %i\n", result->results[i].key, result->results[i].dist, result->results[i].qpos, result->results[i].ipos); + printf("key : %s\ndist : %f\nqpos : %i\nipos : %i\n", result->results[i].ikey, result->results[i].dist, result->results[i].qpos, result->results[i].ipos); PyErr_SetString(PyExc_AttributeError, "Error adding a tuple to the result dict\n"); Py_XDECREF(newBits); return NULL; @@ -388,7 +388,7 @@ }else if(strcmp(resFmt, "list")==0){ outgoing = PyList_New((Py_ssize_t)0); for (i=0;i<result->nresults;i++){ - newBits = Py_BuildValue("sdII",result->results[i].key, + newBits = Py_BuildValue("sdII",result->results[i].ikey, result->results[i].dist, result->results[i].qpos, result->results[i].ipos);
--- a/bindings/sb-alien/interface.lisp Fri Mar 05 16:00:49 2010 +0000 +++ b/bindings/sb-alien/interface.lisp Fri Mar 05 16:00:53 2010 +0000 @@ -143,7 +143,8 @@ datum)))) (defstruct result - (key "" :type string) + (qkey "" :type string) + (ikey "" :type string) (distance 0d0 :type double-float) (qpos 0 :type (and unsigned-byte fixnum)) (ipos 0 :type (and unsigned-byte fixnum))) @@ -163,7 +164,7 @@ (sequence:dosequence (r o) (pprint-pop) (format s "~A ~6,3e ~D ~D~@:_" - (result-key r) (result-distance r) + (result-ikey r) (result-distance r) (result-qpos r) (result-ipos r)))))) (defmethod sequence:length ((o copied-query-results)) @@ -298,7 +299,8 @@ (loop for i below nresults for r = (deref cresults i) collect (make-result - :key (slot r 'key) + :ikey (slot r 'ikey) + :qkey (slot r 'qkey) :distance (slot r 'dist) :qpos (slot r 'qpos) :ipos (slot r 'ipos)))
--- a/bindings/sb-alien/library.lisp Fri Mar 05 16:00:49 2010 +0000 +++ b/bindings/sb-alien/library.lisp Fri Mar 05 16:00:53 2010 +0000 @@ -115,10 +115,11 @@ (define-alien-type adb-result-t (struct adbresult - (key c-string) - (dist double) + (qkey c-string) + (ikey c-string) (qpos (unsigned 32)) - (ipos (unsigned 32)))) + (ipos (unsigned 32)) + (dist double))) (define-alien-type adb-query-results-t (struct adbqueryresults
--- a/libtests/test_utils_lib.h Fri Mar 05 16:00:49 2010 +0000 +++ b/libtests/test_utils_lib.h Fri Mar 05 16:00:53 2010 +0000 @@ -31,7 +31,7 @@ for(uint32_t k = 0; k < r->nresults; k++) { adb_result_t result = r->results[k]; if(close_enough(dist, result.dist, 1e-4) && (qpos == result.qpos) && - (ipos == result.ipos) && !(strcmp(key, result.key))) { + (ipos == result.ipos) && !(strcmp(key, result.ikey))) { return k; } }
--- a/pertrackaccumulator.h Fri Mar 05 16:00:49 2010 +0000 +++ b/pertrackaccumulator.h Fri Mar 05 16:00:53 2010 +0000 @@ -7,17 +7,17 @@ private: unsigned int pointNN; unsigned int trackNN; - std::map<adb_result_t, std::priority_queue< adb_result_t, std::vector<adb_result_t>, T > *, adb_result_key_lt> *queues; + std::map<adb_result_t, std::priority_queue< adb_result_t, std::vector<adb_result_t>, T > *, adb_result_ikey_lt> *queues; }; template <class T> PerTrackAccumulator<T>::PerTrackAccumulator(unsigned int pointNN, unsigned int trackNN) : pointNN(pointNN), trackNN(trackNN), queues(0) { - queues = new std::map<adb_result_t, std::priority_queue< adb_result_t, std::vector<adb_result_t>, T > *, adb_result_key_lt>; + queues = new std::map<adb_result_t, std::priority_queue< adb_result_t, std::vector<adb_result_t>, T > *, adb_result_ikey_lt>; } template <class T> PerTrackAccumulator<T>::~PerTrackAccumulator() { if(queues) { - typename std::map< adb_result_t, std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *, adb_result_key_lt>::iterator it; + typename std::map< adb_result_t, std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *, adb_result_ikey_lt>::iterator it; for(it = queues->begin(); it != queues->end(); it++) { delete (*it).second; } @@ -27,7 +27,7 @@ template <class T> void PerTrackAccumulator<T>::add_point(adb_result_t *r) { if(!isnan(r->dist)) { - typename std::map< adb_result_t, std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *, adb_result_key_lt>::iterator it; + typename std::map< adb_result_t, std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *, adb_result_ikey_lt>::iterator it; std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *queue; it = queues->find(*r); if(it == queues->end()) { @@ -45,9 +45,9 @@ } template <class T> adb_query_results_t *PerTrackAccumulator<T>::get_points() { - typename std::map< adb_result_t, std::vector< adb_result_t >, adb_result_key_lt> points; + typename std::map< adb_result_t, std::vector< adb_result_t >, adb_result_ikey_lt> points; typename std::priority_queue< adb_result_t, std::vector< adb_result_t >, T> queue; - typename std::map< adb_result_t, std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *, adb_result_key_lt>::iterator it; + typename std::map< adb_result_t, std::priority_queue< adb_result_t, std::vector< adb_result_t >, T > *, adb_result_ikey_lt>::iterator it; unsigned int size = 0; for(it = queues->begin(); it != queues->end(); it++) {
--- a/query-indexed.cpp Fri Mar 05 16:00:49 2010 +0000 +++ b/query-indexed.cpp Fri Mar 05 16:00:53 2010 +0000 @@ -26,6 +26,7 @@ } qstate->lsh = audiodb_index_allocate(adb, indexName, corep); + qstate->qkey = spec->qid.datum->key; /* FIXME: it would be nice if the LSH library didn't make me do * this. */ @@ -50,7 +51,8 @@ std::set<std::string>::iterator keys_end = qstate->allowed_keys->end(); if(qstate->allowed_keys->find((*adb->keys)[trackID]) != keys_end) { adb_result_t r; - r.key = (*adb->keys)[trackID].c_str(); + r.ikey = (*adb->keys)[trackID].c_str(); + r.qkey = qstate->qkey; r.dist = dist; r.qpos = qpos; r.ipos = spos;
--- a/query.cpp Fri Mar 05 16:00:49 2010 +0000 +++ b/query.cpp Fri Mar 05 16:00:53 2010 +0000 @@ -293,6 +293,7 @@ } /* initialize d, and mark that nothing needs freeing later. */ d = *datum; + d.key = ""; datum = &d; } else if (datum->key) { uint32_t track_id; @@ -473,7 +474,8 @@ if((!(spec->refine.flags & ADB_REFINE_RADIUS)) || dist <= (spec->refine.radius + ADB_DISTANCE_TOLERANCE)) { adb_result_t r; - r.key = (*adb->keys)[pp.trackID].c_str(); + r.ikey = (*adb->keys)[pp.trackID].c_str(); + r.qkey = spec->qid.datum->key; r.dist = dist; r.qpos = pp.qpos; r.ipos = pp.spos; @@ -587,7 +589,8 @@ if((!(spec->refine.flags & ADB_REFINE_RADIUS)) || thisDist <= (spec->refine.radius + ADB_DISTANCE_TOLERANCE)) { adb_result_t r; - r.key = (*adb->keys)[track].c_str(); + r.ikey = (*adb->keys)[track].c_str(); + r.qkey = spec->qid.datum->key; r.dist = thisDist; if(spec->qid.flags & ADB_QID_FLAG_EXHAUSTIVE) { r.qpos = j;