Version: 9.15.0
SUIT_SentenceMatcher.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2025 CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library 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 GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 #ifndef SUIT_SENTENCEMATCHER_H
24 #define SUIT_SENTENCEMATCHER_H
25 
26 #include "../SUIT.h"
27 
28 #include <QString>
29 #include <QStringList>
30 
31 
32 namespace SUIT_tools {
36  {
37  public:
45 
46  void setUseExactWordOrder(bool theOn);
47  void setUseFuzzyWords(bool theOn);
48  void setCaseSensitive(bool theOn);
49  inline bool isCaseSensitive() const { return myIsCaseSensitive; };
50 
52  void setQuery(QString theQuery);
53 
54  inline const QString& getQuery() const { return myQuery; };
55 
58  double match(const QString& theInputString) const;
59 
61  QString toString() const;
62 
63  private:
64  static bool makePermutatedSentences(const QStringList& theWords, QList<QStringList>& theSentences);
65  static void makeFuzzyWords(const QStringList& theWords, QStringList& theFuzzyWords);
66 
68  static int matchWithSentenceIgnoreEndings(const QString& theInputString, const QStringList& theSentence, bool theCaseSensitive);
70  static int matchWithSentencesIgnoreEndings(const QString& theInputString, const QList<QStringList>& theSentences, bool theCaseSensitive);
71 
73  static int matchAtLeastOneWord(const QString& theInputString, const QStringList& theWords, bool theCaseSensitive);
74 
76  static int match(
77  const QString& theInputString,
78  const QStringList& theSentence,
79  bool theCaseSensitive
80  );
81 
83  static int match(
84  const QString& theInputString,
85  const QList<QStringList>& theSentences,
86  bool theCaseSensitive
87  );
88 
89  bool myUseExactWordOrder; // If false, try to match with sentences, composed of query's words in different orders.
90  bool myUseFuzzyWords; // Try to match with sentences, composed of query's truncated words.
92  QString myQuery;
93 
94  QStringList myWords; // It is also original search sentence.
96 
97  QStringList myFuzzyWords; // Regexes.
99  };
100 
101 } //namespace SUIT_tools
102 
103 #endif //SUIT_SENTENCEMATCHER_H
#define SUIT_EXPORT
Definition: SUIT.h:36
Approximate string matcher, treats strings as sentences composed of words.
Definition: SUIT_SentenceMatcher.h:36
QList< QStringList > myPermutatedSentences
Definition: SUIT_SentenceMatcher.h:95
bool myUseFuzzyWords
Definition: SUIT_SentenceMatcher.h:90
QStringList myFuzzyWords
Definition: SUIT_SentenceMatcher.h:97
QString myQuery
Definition: SUIT_SentenceMatcher.h:92
bool myIsCaseSensitive
Definition: SUIT_SentenceMatcher.h:91
QList< QStringList > myFuzzyPermutatedSentences
Definition: SUIT_SentenceMatcher.h:98
const QString & getQuery() const
Definition: SUIT_SentenceMatcher.h:54
bool isCaseSensitive() const
Definition: SUIT_SentenceMatcher.h:49
bool myUseExactWordOrder
Definition: SUIT_SentenceMatcher.h:89
QStringList myWords
Definition: SUIT_SentenceMatcher.h:94
Definition: SUIT_ShortcutMgr.h:950