Chris@457: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@457: Chris@457: /* Chris@457: Sonic Visualiser Chris@457: An audio file viewer and annotation editor. Chris@457: Centre for Digital Music, Queen Mary, University of London. Chris@457: This file copyright 2008 QMUL. Chris@457: Chris@457: This program is free software; you can redistribute it and/or Chris@457: modify it under the terms of the GNU General Public License as Chris@457: published by the Free Software Foundation; either version 2 of the Chris@457: License, or (at your option) any later version. See the file Chris@457: COPYING included with this distribution for more information. Chris@457: */ Chris@457: Chris@1581: #ifndef SV_TEXT_MATCHER_H Chris@1581: #define SV_TEXT_MATCHER_H Chris@457: Chris@457: #include Chris@457: #include Chris@457: #include "XmlExportable.h" Chris@457: Chris@457: #include Chris@457: Chris@457: /// A rather eccentric interface for matching texts in differently-scored fields Chris@457: Chris@457: class TextMatcher Chris@457: { Chris@457: public: Chris@457: TextMatcher(); Chris@457: virtual ~TextMatcher(); Chris@457: Chris@457: struct Match Chris@457: { Chris@457: QString key; // This field is not used by TextMatcher Chris@457: int score; Chris@457: typedef std::map FragmentMap; // text type -> fragment Chris@457: FragmentMap fragments; Chris@457: Chris@457: Match() : score(0) { } Chris@1733: Chris@1733: Match(const Match &m) =default; Chris@1733: Match &operator=(const Match &m) =default; Chris@457: Chris@457: bool operator<(const Match &m) const; // sort by score first Chris@457: }; Chris@457: Chris@457: void test(Match &match, // existing match record to be augmented Chris@457: QStringList keywords, // search terms Chris@457: QString text, // to search within Chris@457: QString textType, // key to use for fragment map Chris@457: int score); // relative weight for hits within this text type Chris@457: Chris@457: }; Chris@457: Chris@457: Chris@457: #endif