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)
21 {}
22
27};
28
29inline bool operator==( const Candidate& c, const Candidate& d ) {
30 return c.translation == d.translation && c.source == d.source && c.context == d.context
31 && c.disambiguation == d.disambiguation;
32}
33inline bool operator!=( const Candidate& c, const Candidate& d ) {
34 return !operator==( c, d );
35}
36
38
40{
41 CoMatrix(const QString &str);
43
44 /*
45 The matrix has 20 * 20 = 400 entries. This requires 50 bytes, or 13
46 words. Some operations are performed on words for more efficiency.
47 */
48 union {
49 quint8 b[52];
51 };
52};
53
54/**
55 * This class is more efficient for searching through a large array of candidate strings, since we only
56 * have to construct the CoMatrix for the \a stringToMatch once,
57 * after that we just call getSimilarityScore(strCandidate).
58 * \sa getSimilarityScore
59 */
61public:
62 StringSimilarityMatcher(const QString &stringToMatch);
63 int getSimilarityScore(const QString &strCandidate);
64
65private:
66 CoMatrix m_cm;
67 int m_length;
68};
69
70/**
71 * Checks how similar two strings are.
72 * The return value is the score, and a higher score is more similar
73 * than one with a low score.
74 * Linguist considers a score over 190 to be a good match.
75 * \sa StringSimilarityMatcher
76 */
77static inline int getSimilarityScore(const QString &str1, const QString &str2)
78{
79 return StringSimilarityMatcher(str1).getSimilarityScore(str2);
80}
81
83 const QString &text,
84 int maxCandidates );
85
86QT_END_NAMESPACE
87
88#endif
int main(int argc, char *argv[])
[2]
Definition buffer.cpp:77
void closeEvent(QCloseEvent *event) override
[21]
bool openFiles(const QStringList &names, bool readWrite=true)
~MainWindow() override
void writeConfig()
static RecentFiles & recentFiles()
bool eventFilter(QObject *obj, QEvent *ev) override
Filters events if this object has been installed as an event filter for the watched object.
static QString friendlyString(const QString &str)
void readConfig()
QLocale::Language sourceLanguage() const
Definition phrase.h:74
void append(Phrase *phrase)
Definition phrase.cpp:269
QLocale::Territory territory() const
Definition phrase.h:72
QLocale::Language language() const
Definition phrase.h:71
QString friendlyPhraseBookName() const
Definition phrase.cpp:300
bool isModified() const
Definition phrase.h:68
void setSourceLanguageAndTerritory(QLocale::Language lang, QLocale::Territory territory)
Definition phrase.cpp:186
bool load(const QString &fileName, bool *langGuessed)
Definition phrase.cpp:195
void listChanged()
QList< Phrase * > phrases() const
Definition phrase.h:63
void setLanguageAndTerritory(QLocale::Language lang, QLocale::Territory territory)
Definition phrase.cpp:177
QLocale::Territory sourceTerritory() const
Definition phrase.h:75
QString fileName() const
Definition phrase.h:66
bool save(const QString &fileName)
Definition phrase.cpp:237
void remove(Phrase *phrase)
Definition phrase.cpp:277
void setPhraseBook(PhraseBook *book)
Definition phrase.h:36
PhraseBook * phraseBook() const
Definition phrase.h:35
void setDefinition(const QString &nd)
Definition phrase.cpp:64
void setSource(const QString &ns)
Definition phrase.cpp:46
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:28
Candidate candidate() const
Definition phrase.h:34
Phrase(const QString &source, const QString &target, const QString &definition, PhraseBook *phraseBook)
Definition phrase.cpp:39
Phrase(const QString &source, const QString &target, const QString &definition, const Candidate &candidate, int sc=-1)
Definition phrase.cpp:33
void setTarget(const QString &nt)
Definition phrase.cpp:55
QString source() const
Definition phrase.h:27
int getSimilarityScore(const QString &strCandidate)
Definition simtexth.cpp:152
StringSimilarityMatcher(const QString &stringToMatch)
Definition simtexth.cpp:146
Combined button and popup list for selecting options.
bool operator==(const Phrase &p, const Phrase &q)
Definition phrase.cpp:73
bool operator!=(const Phrase &p, const Phrase &q)
Definition phrase.h:48
static int getSimilarityScore(const QString &str1, const QString &str2)
Definition simtexth.h:77
QList< Candidate > CandidateList
Definition simtexth.h:37
const int textSimilarityThreshold
Definition simtexth.h:7
bool operator!=(const Candidate &c, const Candidate &d)
Definition simtexth.h:33
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:29
QString source
Definition simtexth.h:24
Candidate(const QString &c, const QString &s, const QString &d, const QString &t)
Definition simtexth.h:19
Candidate()
Definition simtexth.h:18
QString translation
Definition simtexth.h:26
QString disambiguation
Definition simtexth.h:25
QString context
Definition simtexth.h:23
quint8 b[52]
Definition simtexth.h:49
CoMatrix()
Definition simtexth.h:42
CoMatrix(const QString &str)
Definition simtexth.cpp:103
quint32 w[13]
Definition simtexth.h:50