Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
simtexth.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef SIMTEXTH_H
5#define SIMTEXTH_H
6
7const int textSimilarityThreshold = 190;
8
9#include <QString>
10#include <QList>
11
12QT_BEGIN_NAMESPACE
13
14class Translator;
15
17{
19 Candidate(const QString &c, const QString &s, const QString &d, const QString &t,
20 const QString &i, const QString &l)
22 {}
23
30};
31
32inline bool operator==( const Candidate& c, const Candidate& d ) {
33 return c.translation == d.translation && c.source == d.source && c.context == d.context
34 && c.disambiguation == d.disambiguation;
35}
36inline bool operator!=( const Candidate& c, const Candidate& d ) {
37 return !operator==( c, d );
38}
39
41
43{
44 CoMatrix(const QString &str);
46
47 /*
48 The matrix has 20 * 20 = 400 entries. This requires 50 bytes, or 13
49 words. Some operations are performed on words for more efficiency.
50 */
51 union {
52 quint8 b[52];
54 };
55};
56
57/**
58 * This class is more efficient for searching through a large array of candidate strings, since we only
59 * have to construct the CoMatrix for the \a stringToMatch once,
60 * after that we just call getSimilarityScore(strCandidate).
61 * \sa getSimilarityScore
62 */
64public:
65 StringSimilarityMatcher(const QString &stringToMatch);
66 int getSimilarityScore(const QString &strCandidate);
67
68private:
69 CoMatrix m_cm;
70 int m_length;
71};
72
73/**
74 * Checks how similar two strings are.
75 * The return value is the score, and a higher score is more similar
76 * than one with a low score.
77 * Linguist considers a score over 190 to be a good match.
78 * \sa StringSimilarityMatcher
79 */
80static inline int getSimilarityScore(const QString &str1, const QString &str2)
81{
82 return StringSimilarityMatcher(str1).getSimilarityScore(str2);
83}
84
86 const QString &text,
87 int maxCandidates );
88
89QT_END_NAMESPACE
90
91#endif
~MainWindow() override
void writeConfig()
void closeEvent(QCloseEvent *e) override
This event handler is called with the given event when Qt receives a window close request for a top-l...
bool openFiles(const QStringList &names)
bool eventFilter(QObject *obj, QEvent *ev) override
Filters events if this object has been installed as an event filter for the watched object.
void readConfig()
QLocale::Language sourceLanguage() const
Definition phrase.h:74
void append(Phrase *phrase)
Definition phrase.cpp:271
QLocale::Territory territory() const
Definition phrase.h:72
QLocale::Language language() const
Definition phrase.h:71
QString friendlyPhraseBookName() const
Definition phrase.cpp:302
bool isModified() const
Definition phrase.h:68
void setSourceLanguageAndTerritory(QLocale::Language lang, QLocale::Territory territory)
Definition phrase.cpp:188
bool load(const QString &fileName, bool *langGuessed)
Definition phrase.cpp:197
void listChanged()
QList< Phrase * > phrases() const
Definition phrase.h:63
void setLanguageAndTerritory(QLocale::Language lang, QLocale::Territory territory)
Definition phrase.cpp:179
QLocale::Territory sourceTerritory() const
Definition phrase.h:75
QString fileName() const
Definition phrase.h:66
bool save(const QString &fileName)
Definition phrase.cpp:239
void remove(Phrase *phrase)
Definition phrase.cpp:279
void setPhraseBook(PhraseBook *book)
Definition phrase.h:36
PhraseBook * phraseBook() const
Definition phrase.h:35
void setDefinition(const QString &nd)
Definition phrase.cpp:66
void setSource(const QString &ns)
Definition phrase.cpp:48
QString definition() const
Definition phrase.h:31
QString target() const
Definition phrase.h:29
int shortcut() const
Definition phrase.h:33
Phrase()
Definition phrase.cpp:30
Candidate candidate() const
Definition phrase.h:34
Phrase(const QString &source, const QString &target, const QString &definition, PhraseBook *phraseBook)
Definition phrase.cpp:41
Phrase(const QString &source, const QString &target, const QString &definition, const Candidate &candidate, int sc=-1)
Definition phrase.cpp:35
void setTarget(const QString &nt)
Definition phrase.cpp:57
QString source() const
Definition phrase.h:27
int getSimilarityScore(const QString &strCandidate)
Definition simtexth.cpp:152
StringSimilarityMatcher(const QString &stringToMatch)
Definition simtexth.cpp:146
bool operator==(const Phrase &p, const Phrase &q)
Definition phrase.cpp:75
bool operator!=(const Phrase &p, const Phrase &q)
Definition phrase.h:48
static int getSimilarityScore(const QString &str1, const QString &str2)
Definition simtexth.h:80
QList< Candidate > CandidateList
Definition simtexth.h:40
const int textSimilarityThreshold
Definition simtexth.h:7
bool operator!=(const Candidate &c, const Candidate &d)
Definition simtexth.h:36
CandidateList similarTextHeuristicCandidates(const Translator *tor, const QString &text, int maxCandidates)
Definition simtexth.cpp:161
bool operator==(const Candidate &c, const Candidate &d)
Definition simtexth.h:32
int main(int argc, char *argv[])
[ctor_close]
QString id
Definition simtexth.h:27
QString source
Definition simtexth.h:25
Candidate(const QString &c, const QString &s, const QString &d, const QString &t, const QString &i, const QString &l)
Definition simtexth.h:19
Candidate()
Definition simtexth.h:18
QString translation
Definition simtexth.h:29
QString disambiguation
Definition simtexth.h:28
QString context
Definition simtexth.h:24
QString label
Definition simtexth.h:26
quint8 b[52]
Definition simtexth.h:52
CoMatrix()
Definition simtexth.h:45
CoMatrix(const QString &str)
Definition simtexth.cpp:103
quint32 w[13]
Definition simtexth.h:53