LCOV - code coverage report
Current view: top level - include/xapian - diversify.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 7028d852e609 Lines: 1 1 100.0 %
Date: 2019-02-17 14:59:59 Functions: 4 4 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /** @file diversify.h
       2                 :            :  *  @brief Diversification API
       3                 :            :  */
       4                 :            : /* Copyright (C) 2018 Uppinder Chugh
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2 of the
       9                 :            :  * License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      19                 :            :  * USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef XAPIAN_INCLUDED_DIVERSIFY_H
      23                 :            : #define XAPIAN_INCLUDED_DIVERSIFY_H
      24                 :            : 
      25                 :            : #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
      26                 :            : #error "Never use <xapian/diversify.h> directly; include <xapian.h> instead."
      27                 :            : #endif
      28                 :            : 
      29                 :            : #include <xapian/attributes.h>
      30                 :            : #include <xapian/cluster.h>
      31                 :            : #include <xapian/mset.h>
      32                 :            : #include <xapian/types.h>
      33                 :            : #include <xapian/visibility.h>
      34                 :            : 
      35                 :            : #include <map>
      36                 :            : #include <unordered_map>
      37                 :            : #include <vector>
      38                 :            : 
      39                 :            : namespace Xapian {
      40                 :            : 
      41                 :            : /** Class for diversifying an MSet using GLS-MPT as given
      42                 :            :  *  in the paper: Scalable and Efficient Web Search Result
      43                 :            :  *  Diversification Naini et al. 2016
      44                 :            :  */
      45                 :          8 : class XAPIAN_VISIBILITY_DEFAULT Diversify {
      46                 :            :   public:
      47                 :            :     class Internal;
      48                 :            :     /// @private @internal Reference counted internals.
      49                 :            :     Xapian::Internal::intrusive_ptr_nonnull<Internal> internal;
      50                 :            : 
      51                 :            :     /** Copying is allowed.  The internals are reference counted, so
      52                 :            :      *  copying is cheap.
      53                 :            :      *
      54                 :            :      *  @param other    The object to copy.
      55                 :            :      */
      56                 :            :     Diversify(const Diversify& other);
      57                 :            : 
      58                 :            :     /** Assignment is allowed.  The internals are reference counted,
      59                 :            :      *  so assignment is cheap.
      60                 :            :      *
      61                 :            :      *  @param other    The object to copy.
      62                 :            :      */
      63                 :            :     Diversify& operator=(const Diversify& other);
      64                 :            : 
      65                 :            :     /** Move constructor.
      66                 :            :      *
      67                 :            :      *  @param other    The object to move.
      68                 :            :      */
      69                 :            :     Diversify(Diversify&& other);
      70                 :            : 
      71                 :            :     /** Move assignment operator.
      72                 :            :      *
      73                 :            :      *  @param other    The object to move.
      74                 :            :      */
      75                 :            :     Diversify& operator=(Diversify&& other);
      76                 :            : 
      77                 :            :     /** Constructor specifying the number of diversified search results
      78                 :            :      *
      79                 :            :      *  @param  k_      Number of required diversified documents in the
      80                 :            :      *                  diversified document set
      81                 :            :      *  @param  r_      Number of documents from each cluster used for
      82                 :            :      *                  building topC
      83                 :            :      *  @param  lambda_ Trade-off between relevance of top-k diversified
      84                 :            :      *                  document set and its similarity to the rest of the
      85                 :            :      *                  documents in the document match set. Belongs to the
      86                 :            :      *                  the range [0,1] with '0' meaning no weightage to
      87                 :            :      *                  relevance of the diversified document set and '1'
      88                 :            :      *                  allowing for full weightage to relevance of the
      89                 :            :      *                  diversified document set.
      90                 :            :      *  @param  b_      Parameter for MPT, normally in the range [1,10]
      91                 :            :      *  @param  sigma_sqr_      Parameter for MPT, normally in the range
      92                 :            :      *                          [1e-6,1]
      93                 :            :      */
      94                 :            :     explicit Diversify(Xapian::doccount k_,
      95                 :            :                        Xapian::doccount r_,
      96                 :            :                        double lambda_ = 0.5,
      97                 :            :                        double b_ = 5.0,
      98                 :            :                        double sigma_sqr_ = 1e-3);
      99                 :            : 
     100                 :            :     /// Destructor
     101                 :            :     ~Diversify();
     102                 :            : 
     103                 :            :     /** Implements diversification
     104                 :            :      *
     105                 :            :      *  Performs GLS-MPT and returns documents of which top-k
     106                 :            :      *  are diversified.
     107                 :            :      *
     108                 :            :      *  @param mset     MSet object containing the documents of which
     109                 :            :      *                  top-k are to be diversified
     110                 :            :      */
     111                 :            :     Xapian::DocumentSet get_dmset(const MSet& mset);
     112                 :            : 
     113                 :            :     /// Return a string describing this object
     114                 :            :     std::string get_description() const;
     115                 :            : };
     116                 :            : }
     117                 :            : #endif // XAPIAN_INCLUDED_DIVERSIFY_H

Generated by: LCOV version 1.11