This step-by-step guide describes how custom rank aggregation methods can be implemented and integrated into FLAGR. If you intend to implement fewer than three methods, then several of the steps below are already implemented in FLAGR. For three or more custom methods, additional actions must be performed.
Implementing your own method/s
Custom methods must be implemented as C++ functions in the src/ram/CustomMethods.cpp file. This file already contains two such functions: CustomMethod1() and CustomMethod2(). In case you desire to implement more methods (e.g. CustomMethod3(), etc.), then you must implement them similarly in that file.
Typically, a rank aggregation method assigns scores to the list elements and then, it sorts the elements in either increasing, or decreasing score order. For this reason, the last step in your implementation must be the sorting process of the elements of MergedList. Observe that CustomMethod1() and CustomMethod2() contain a call to qsort (QuickSort) in order to perform the required sorting.
Each algorithm implementation (including the built-in ones) takes three arguments:
- An array of the input preference lists (
class InputList ** inlists). Most rank aggregation methods do not require access to this array, since when the function is called, the input lists have already been merged in theMergedList(i.e. this) object. However, several methods require the computation of list distances (e.g. DIBRA, Agglomerative) and theinlistspointer provides access to this array. - A pointer to a
SimpleScoreStatsobject in case you desire to store score statistics (max, min, mean, etc.). - A pointer to the
InputParamsobject that contains the user-defined input parameters.
The following code example demonstrates an iteration through the elements of the aggregate list. For each element q, an iteration through its individual rankings in each input preference list is performed:
void MergedList::CustomMethod1 (class InputList ** inlists, class SimpleScoreStats * s, class InputParams * prms) {
class MergedItem * q;
class Ranking * r;
for (rank_t i = 0; i < this->num_nodes; i++) {
/// q stores an element of the aggregate list
q = this->item_list[i];
/// Iterate through the individual rankings of q
for (uint32_t j = 0; j < q->get_num_alloc_rankings(); j++) {
r = q->get_ranking(j);
/// Do something with q and r
}
}
/// Sort the list elements in decreasing score order
qsort(this->item_list, this->num_nodes, sizeof(class MergedItem *),
&MergedList::cmp_score_desc);
}
Calling the new method/s
The implementation of the new methods can be immediately used, provided that you have not changed the names of the functions CustomMethod1() and CustomMethod2(). In this case, the following piece of code inside the main() function in cflagr.cpp and dllflagr.cpp invokes the new implementations:
/// Execution of CustomMethod1 Custom1(input_file, qrels_file, 20, "RRA", output_dir); /// Execution of CustomMethod2 Custom2(input_file, qrels_file, 20, "RRA", output_dir);
If you change the aforementioned function names, or you create a new function for a new algorithm implementation, then a sequence of actions must be taken so that it becomes available for usage. More specifically:
- The user must determine an integer identifier for the algorithm. To avoid conflicts with the built-in methods of FLAGR, it is advised that the leading digit of the identifier is
9(e.g.,900). - The user must update the
aggregate()function of theAggregatorto allow the execution of the custom method. More specifically, theifstatement must be appropriately extended. - An exposed C function must be written in both
cflagr.cppanddllflagr.cppwith the aim of including the custom implementation in a shared/dynamic link library. The function can be called in themain()function ofcflagr.cppordllflagr.cpp.
Additional details for custom method implementations
- A custom rank aggregation method must be declared as a public member function of the
MergedListclass. This is performed in the class descriptor, in thesrc/MergedList.hheader file. Notice thatCustomMethod1()andCustomMethod2()are already public members ofMergedList. - The required
.cppfile that contains the implementation of the member function must be stored in thesrc/ramdirectory. - Then, the
.cppfile is imported in the project with an include statement insrc/MergedList.cpp.
