2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#ifndef __DICTIONARY_HH_INCLUDED__
|
|
|
|
#define __DICTIONARY_HH_INCLUDED__
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2009-03-26 19:00:08 +00:00
|
|
|
#include <QObject>
|
2009-04-21 19:03:16 +00:00
|
|
|
#include <QIcon>
|
2009-01-28 20:55:45 +00:00
|
|
|
#include "sptr.hh"
|
|
|
|
#include "ex.hh"
|
2009-03-26 19:00:08 +00:00
|
|
|
#include "mutex.hh"
|
2009-04-18 17:20:12 +00:00
|
|
|
#include "wstring.hh"
|
2013-07-16 14:23:42 +00:00
|
|
|
#include "langcoder.hh"
|
2014-04-17 14:31:51 +00:00
|
|
|
#include "config.hh"
|
2021-11-27 07:17:33 +00:00
|
|
|
#include "utils.hh"
|
2022-07-31 08:17:57 +00:00
|
|
|
#include <QString>
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// Abstract dictionary-related stuff
|
|
|
|
namespace Dictionary {
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
2009-04-18 17:20:12 +00:00
|
|
|
using gd::wstring;
|
2009-01-28 20:55:45 +00:00
|
|
|
using std::map;
|
|
|
|
|
|
|
|
enum Property
|
|
|
|
{
|
|
|
|
Author,
|
|
|
|
Copyright,
|
|
|
|
Description,
|
|
|
|
Email
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_EX( Ex, "Dictionary error", std::exception )
|
2009-03-26 19:00:08 +00:00
|
|
|
DEF_EX( exIndexOutOfRange, "The supplied index is out of range", Ex )
|
|
|
|
DEF_EX( exSliceOutOfRange, "The requested data slice is out of range", Ex )
|
|
|
|
DEF_EX( exRequestUnfinished, "The request hasn't yet finished", Ex )
|
|
|
|
|
|
|
|
/// When you request a search to be performed in a dictionary, you get
|
|
|
|
/// this structure in return. It accumulates search results over time.
|
|
|
|
/// The finished() signal is emitted when the search has finished and there's
|
|
|
|
/// no more matches to be expected. Note that before connecting to it, check
|
|
|
|
/// the result of isFinished() -- if it's 'true', the search was instantaneous.
|
|
|
|
/// Destroy the object when you are not interested in results anymore.
|
2009-04-21 19:03:16 +00:00
|
|
|
///
|
2009-03-26 19:00:08 +00:00
|
|
|
/// Creating, destroying and calling member functions of the requests is done
|
|
|
|
/// in the GUI thread, however. Therefore, it is important to make sure those
|
|
|
|
/// operations are fast (this is most important for word searches, where
|
|
|
|
/// new requests are created and old ones deleted immediately upon a user
|
|
|
|
/// changing query).
|
|
|
|
class Request: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-09-18 01:00:27 +00:00
|
|
|
Request( QObject * parent = nullptr ) : QObject( parent )
|
|
|
|
{
|
|
|
|
}
|
2009-03-26 19:00:08 +00:00
|
|
|
/// Returns whether the request has been processed in full and finished.
|
|
|
|
/// This means that the data accumulated is final and won't change anymore.
|
|
|
|
bool isFinished();
|
|
|
|
|
|
|
|
/// Either returns an empty string in case there was no error processing
|
|
|
|
/// the request, or otherwise a human-readable string describing the problem.
|
|
|
|
/// Note that an empty result, such as a lack of word or of an article isn't
|
|
|
|
/// an error -- but any kind of failure to connect to, or read the dictionary
|
|
|
|
/// is.
|
|
|
|
QString getErrorString();
|
|
|
|
|
|
|
|
/// Cancels the ongoing request. This may make Request destruct faster some
|
|
|
|
/// time in the future, Use this in preparation to destruct many Requests,
|
|
|
|
/// so that they'd be cancelling in parallel. When the request was fully
|
|
|
|
/// cancelled, it must emit the finished() signal, either as a result of an
|
|
|
|
/// actual finish which has happened just before the cancellation, or solely as
|
|
|
|
/// a result of a request being cancelled (in the latter case, the actual
|
|
|
|
/// request result may be empty or incomplete). That is, finish() must be
|
|
|
|
/// called by a derivative at least once if cancel() was called, either after
|
|
|
|
/// or before it was called.
|
|
|
|
virtual void cancel()=0;
|
|
|
|
|
|
|
|
virtual ~Request()
|
|
|
|
{}
|
2009-04-21 19:03:16 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
/// This signal is emitted when more data becomes available. Local
|
|
|
|
/// dictionaries typically don't call this, since it is preferred that all
|
|
|
|
/// data would be available from them at once, but network dictionaries
|
|
|
|
/// might call that.
|
|
|
|
void updated();
|
2009-04-21 19:03:16 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
/// This signal is emitted when the request has been processed in full and
|
|
|
|
/// finished. That is, it's emitted when isFinished() turns true.
|
|
|
|
void finished();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/// Called by derivatives to signal update().
|
|
|
|
void update();
|
2009-04-21 19:03:16 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
/// Called by derivatives to set isFinished() flag and signal finished().
|
|
|
|
void finish();
|
|
|
|
|
|
|
|
/// Sets the error string to be returned by getErrorString().
|
|
|
|
void setErrorString( QString const & );
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
QAtomicInt isFinishedFlag;
|
|
|
|
|
|
|
|
Mutex errorStringMutex;
|
|
|
|
QString errorString;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// This structure represents the word found. In addition to holding the
|
2009-04-09 15:27:34 +00:00
|
|
|
/// word itself, it also holds its weight. It is 0 by default. Negative
|
|
|
|
/// values should be used to store distance from Levenstein-like matching
|
|
|
|
/// algorithms. Positive values are used by morphology matches.
|
2009-03-26 19:00:08 +00:00
|
|
|
struct WordMatch
|
|
|
|
{
|
|
|
|
wstring word;
|
|
|
|
int weight;
|
|
|
|
|
|
|
|
WordMatch(): weight( 0 ) {}
|
|
|
|
WordMatch( wstring const & word_ ): word( word_ ), weight( 0 ){}
|
|
|
|
WordMatch( wstring const & word_, int weight_ ): word( word_ ),
|
|
|
|
weight( weight_ ) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// This request type corresponds to all types of word searching operations.
|
|
|
|
class WordSearchRequest: public Request
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2009-04-21 19:03:16 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
public:
|
|
|
|
|
2010-06-22 12:43:11 +00:00
|
|
|
WordSearchRequest(): uncertain( false )
|
|
|
|
{}
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
/// Returns the number of matches found. The value can grow over time
|
|
|
|
/// unless isFinished() is true.
|
|
|
|
size_t matchesCount();
|
|
|
|
|
|
|
|
/// Returns the match with the given zero-based index, which should be less
|
|
|
|
/// than matchesCount().
|
2022-01-09 08:35:07 +00:00
|
|
|
WordMatch operator [] ( size_t index ) ;
|
2009-04-17 13:51:50 +00:00
|
|
|
|
|
|
|
/// Returns all the matches found. Since no further locking can or would be
|
|
|
|
/// done, this can only be called after the request has finished.
|
2022-01-09 08:35:07 +00:00
|
|
|
vector< WordMatch > & getAllMatches() ;
|
2009-04-21 19:03:16 +00:00
|
|
|
|
2010-06-22 12:43:11 +00:00
|
|
|
/// Returns true if the match was uncertain -- that is, there may be more
|
|
|
|
/// results in the dictionary itself, the dictionary index isn't good enough
|
|
|
|
/// to tell that.
|
|
|
|
bool isUncertain() const
|
|
|
|
{ return uncertain; }
|
|
|
|
|
2014-05-26 14:06:00 +00:00
|
|
|
/// Add match if one is not presented in matches list
|
|
|
|
void addMatch( WordMatch const & match );
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
protected:
|
2009-04-21 19:03:16 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
// Subclasses should be filling up the 'matches' array, locking the mutex when
|
|
|
|
// whey work with it.
|
|
|
|
Mutex dataMutex;
|
|
|
|
|
|
|
|
vector< WordMatch > matches;
|
2010-06-22 12:43:11 +00:00
|
|
|
bool uncertain;
|
2009-03-26 19:00:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// This request type corresponds to any kinds of data responses where a
|
|
|
|
/// single large blob of binary data is returned. It currently used of article
|
|
|
|
/// bodies and resources.
|
|
|
|
class DataRequest: public Request
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2009-04-21 19:03:16 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
public:
|
|
|
|
/// Returns the number of bytes read, with a -1 meaning that so far it's
|
|
|
|
/// uncertain whether resource even exists or not, and any non-negative value
|
|
|
|
/// meaning that that amount of bytes is not available.
|
|
|
|
/// If -1 is still being returned after the request has finished, that means
|
|
|
|
/// the resource wasn't found.
|
|
|
|
long dataSize();
|
|
|
|
|
|
|
|
/// Writes "size" bytes starting from "offset" of the data read to the given
|
|
|
|
/// buffer. "size + offset" must be <= than dataSize().
|
|
|
|
void getDataSlice( size_t offset, size_t size, void * buffer )
|
2022-01-09 08:35:07 +00:00
|
|
|
;
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
/// Returns all the data read. Since no further locking can or would be
|
|
|
|
/// done, this can only be called after the request has finished.
|
2022-01-09 08:35:07 +00:00
|
|
|
vector< char > & getFullData() ;
|
2009-03-26 19:00:08 +00:00
|
|
|
|
2022-09-18 01:00:27 +00:00
|
|
|
DataRequest( QObject * parent = 0 ) : Request( parent ), hasAnyData( false )
|
|
|
|
{
|
|
|
|
}
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
protected:
|
2009-04-21 19:03:16 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
// Subclasses should be filling up the 'data' array, locking the mutex when
|
|
|
|
// whey work with it.
|
|
|
|
Mutex dataMutex;
|
|
|
|
|
|
|
|
bool hasAnyData; // With this being false, dataSize() always returns -1
|
|
|
|
vector< char > data;
|
|
|
|
};
|
|
|
|
|
2018-07-07 09:33:15 +00:00
|
|
|
/// A helper class for synchronous word search implementations.
|
2009-03-26 19:00:08 +00:00
|
|
|
class WordSearchRequestInstant: public WordSearchRequest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
WordSearchRequestInstant()
|
|
|
|
{ finish(); }
|
|
|
|
|
|
|
|
virtual void cancel()
|
|
|
|
{}
|
|
|
|
|
|
|
|
vector< WordMatch > & getMatches()
|
|
|
|
{ return matches; }
|
2010-06-22 12:43:11 +00:00
|
|
|
|
|
|
|
void setUncertain( bool value )
|
|
|
|
{ uncertain = value; }
|
2009-03-26 19:00:08 +00:00
|
|
|
};
|
2009-04-09 14:15:01 +00:00
|
|
|
|
2018-07-07 09:33:15 +00:00
|
|
|
/// A helper class for synchronous data read implementations.
|
2009-03-26 19:00:08 +00:00
|
|
|
class DataRequestInstant: public DataRequest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
DataRequestInstant( bool succeeded )
|
|
|
|
{ hasAnyData = succeeded; finish(); }
|
|
|
|
|
2009-04-09 18:50:49 +00:00
|
|
|
DataRequestInstant( QString const & errorString )
|
|
|
|
{ setErrorString( errorString ); finish(); }
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
virtual void cancel()
|
|
|
|
{}
|
|
|
|
|
|
|
|
vector< char > & getData()
|
|
|
|
{ return data; }
|
|
|
|
};
|
|
|
|
|
2010-05-29 20:50:16 +00:00
|
|
|
/// Dictionary features. Different dictionaries can possess different features,
|
|
|
|
/// which hint at some of their aspects.
|
|
|
|
enum Feature
|
|
|
|
{
|
|
|
|
/// No features
|
|
|
|
NoFeatures = 0,
|
|
|
|
/// The dictionary is suitable to query when searching for compound expressions.
|
|
|
|
SuitableForCompoundSearching = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_FLAGS( Features, Feature )
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS( Features )
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// A dictionary. Can be used to query words.
|
|
|
|
class Class
|
|
|
|
{
|
|
|
|
string id;
|
|
|
|
vector< string > dictionaryFiles;
|
|
|
|
|
2012-09-07 11:51:42 +00:00
|
|
|
protected:
|
|
|
|
QString dictionaryDescription;
|
2012-12-03 12:47:43 +00:00
|
|
|
QIcon dictionaryIcon, dictionaryNativeIcon;
|
|
|
|
bool dictionaryIconLoaded;
|
2014-05-08 12:38:00 +00:00
|
|
|
bool can_FTS;
|
2014-04-16 16:18:28 +00:00
|
|
|
QAtomicInt FTS_index_completed;
|
2017-03-09 16:11:17 +00:00
|
|
|
bool synonymSearchEnabled;
|
2012-12-03 12:47:43 +00:00
|
|
|
|
|
|
|
// Load user icon if it exist
|
|
|
|
// By default set icon to empty
|
2022-06-03 13:28:41 +00:00
|
|
|
virtual void loadIcon() noexcept;
|
2012-12-03 12:47:43 +00:00
|
|
|
|
|
|
|
// Load icon from filename directly if isFullName == true
|
|
|
|
// else treat filename as name without extension
|
|
|
|
bool loadIconFromFile( QString const & filename, bool isFullName = false );
|
2022-09-07 13:53:19 +00:00
|
|
|
bool loadIconFromText( QString iconUrl, QString const & text );
|
2022-07-31 08:17:57 +00:00
|
|
|
|
|
|
|
QString getAbbrName( QString const & text );
|
2012-09-07 11:51:42 +00:00
|
|
|
|
2013-05-23 14:01:50 +00:00
|
|
|
/// Make css content usable only for articles from this dictionary
|
2013-05-28 07:00:36 +00:00
|
|
|
void isolateCSS( QString & css, QString const & wrapperSelector = QString() );
|
2013-05-23 14:01:50 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/// Creates a dictionary. The id should be made using
|
|
|
|
/// Format::makeDictionaryId(), the dictionaryFiles is the file names the
|
|
|
|
/// dictionary consists of.
|
|
|
|
Class( string const & id, vector< string > const & dictionaryFiles );
|
|
|
|
|
2009-05-17 13:35:19 +00:00
|
|
|
/// Called once after the dictionary is constructed. Usually called for each
|
|
|
|
/// dictionaries once all dictionaries were made. The implementation should
|
|
|
|
/// queue any initialization tasks the dictionary decided to postpone to
|
|
|
|
/// threadpools, network requests etc, so the system could complete them
|
|
|
|
/// in background.
|
|
|
|
/// The default implementation does nothing.
|
|
|
|
virtual void deferredInit();
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Returns the dictionary's id.
|
2022-06-03 13:28:41 +00:00
|
|
|
string getId() noexcept
|
2009-01-28 20:55:45 +00:00
|
|
|
{ return id; }
|
|
|
|
|
|
|
|
/// Returns the list of file names the dictionary consists of.
|
2022-06-03 13:28:41 +00:00
|
|
|
vector< string > const & getDictionaryFilenames() noexcept
|
2009-01-28 20:55:45 +00:00
|
|
|
{ return dictionaryFiles; }
|
|
|
|
|
|
|
|
/// Returns the dictionary's full name, utf8.
|
2022-06-03 13:28:41 +00:00
|
|
|
virtual string getName() noexcept=0;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// Returns all the available properties, like the author's name, copyright,
|
|
|
|
/// description etc. All strings are in utf8.
|
2022-06-03 13:28:41 +00:00
|
|
|
virtual map< Property, string > getProperties() noexcept=0;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2010-05-29 20:50:16 +00:00
|
|
|
/// Returns the features the dictionary possess. See the Feature enum for
|
|
|
|
/// their list.
|
2022-06-03 13:28:41 +00:00
|
|
|
virtual Features getFeatures() const noexcept
|
2010-05-29 20:50:16 +00:00
|
|
|
{ return NoFeatures; }
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Returns the number of articles in the dictionary.
|
2022-06-03 13:28:41 +00:00
|
|
|
virtual unsigned long getArticleCount() noexcept=0;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// Returns the number of words in the dictionary. This can be equal to
|
|
|
|
/// the number of articles, or can be larger if some synonyms are present.
|
2022-06-03 13:28:41 +00:00
|
|
|
virtual unsigned long getWordCount() noexcept=0;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-21 19:03:16 +00:00
|
|
|
/// Returns the dictionary's icon.
|
2022-06-03 13:28:41 +00:00
|
|
|
virtual QIcon const & getIcon() noexcept;
|
2009-04-21 19:03:16 +00:00
|
|
|
|
2009-09-21 17:50:03 +00:00
|
|
|
/// Returns the dictionary's native icon. Dsl icons are usually rectangular,
|
|
|
|
/// and are adapted by getIcon() to be square. This function allows getting
|
|
|
|
/// the original icon with no geometry transformations applied.
|
2022-06-03 13:28:41 +00:00
|
|
|
virtual QIcon const & getNativeIcon() noexcept;
|
2009-09-21 17:50:03 +00:00
|
|
|
|
2009-04-22 21:37:32 +00:00
|
|
|
/// Returns the dictionary's source language.
|
|
|
|
virtual quint32 getLangFrom() const
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
/// Returns the dictionary's target language.
|
|
|
|
virtual quint32 getLangTo() const
|
|
|
|
{ return 0; }
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
/// Looks up a given word in the dictionary, aiming for exact matches and
|
|
|
|
/// prefix matches. If it's not possible to locate any prefix matches, no
|
|
|
|
/// prefix results should be added. Not more than maxResults results should
|
|
|
|
/// be stored. The whole operation is supposed to be fast, though some
|
|
|
|
/// dictionaries, the network ones particularly, may of course be slow.
|
|
|
|
virtual sptr< WordSearchRequest > prefixMatch( wstring const &,
|
2022-01-09 08:35:07 +00:00
|
|
|
unsigned long maxResults ) =0;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-17 13:51:50 +00:00
|
|
|
/// Looks up a given word in the dictionary, aiming to find different forms
|
|
|
|
/// of the given word by allowing suffix variations. This means allowing words
|
|
|
|
/// which can be as short as the input word size minus maxSuffixVariation, or as
|
|
|
|
/// long as the input word size plus maxSuffixVariation, which share at least
|
|
|
|
/// the input word size minus maxSuffixVariation initial symbols.
|
|
|
|
/// Since the goal is to find forms of the words, no matches where a word
|
|
|
|
/// in the middle of a phrase got matched should be returned.
|
|
|
|
/// The default implementation does nothing, returning an empty result.
|
|
|
|
virtual sptr< WordSearchRequest > stemmedMatch( wstring const &,
|
|
|
|
unsigned minLength,
|
|
|
|
unsigned maxSuffixVariation,
|
2022-01-09 08:35:07 +00:00
|
|
|
unsigned long maxResults ) ;
|
2009-04-17 13:51:50 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Finds known headwords for the given word, that is, the words for which
|
|
|
|
/// the given word is a synonym. If a dictionary can't perform this operation,
|
|
|
|
/// it should leave the default implementation which always returns an empty
|
2009-03-26 19:00:08 +00:00
|
|
|
/// result.
|
|
|
|
virtual sptr< WordSearchRequest > findHeadwordsForSynonym( wstring const & )
|
2022-01-09 08:35:07 +00:00
|
|
|
;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-05-06 14:39:08 +00:00
|
|
|
/// For a given word, provides alternate writings of it which are to be looked
|
|
|
|
/// up alongside with it. Transliteration dictionaries implement this. The
|
|
|
|
/// default implementation returns an empty list. Note that this function is
|
|
|
|
/// supposed to be very fast and simple, and the results are thus returned
|
2018-07-07 09:33:15 +00:00
|
|
|
/// synchronously.
|
2009-05-06 14:39:08 +00:00
|
|
|
virtual vector< wstring > getAlternateWritings( wstring const & )
|
2022-06-03 13:28:41 +00:00
|
|
|
noexcept;
|
2009-05-06 14:39:08 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Returns a definition for the given word. The definition should
|
|
|
|
/// be an html fragment (without html/head/body tags) in an utf8 encoding.
|
|
|
|
/// The 'alts' vector could contain a list of words the definitions of which
|
|
|
|
/// should be included in the output as well, being treated as additional
|
|
|
|
/// synonyms for the main word.
|
2009-05-29 19:48:50 +00:00
|
|
|
/// context is a dictionary-specific data, currently only used for the
|
|
|
|
/// 'Websites' feature.
|
|
|
|
virtual sptr< DataRequest > getArticle( wstring const &,
|
|
|
|
vector< wstring > const & alts,
|
2018-06-13 16:00:42 +00:00
|
|
|
wstring const & context = wstring(),
|
|
|
|
bool ignoreDiacritics = false )
|
2022-01-09 08:35:07 +00:00
|
|
|
=0;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// Loads contents of a resource named 'name' into the 'data' vector. This is
|
|
|
|
/// usually a picture file referenced in the article or something like that.
|
2009-03-26 19:00:08 +00:00
|
|
|
/// The default implementation always returns the non-existing resource
|
|
|
|
/// response.
|
|
|
|
virtual sptr< DataRequest > getResource( string const & /*name*/ )
|
2022-01-09 08:35:07 +00:00
|
|
|
;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2014-04-16 16:18:28 +00:00
|
|
|
/// Returns a results of full-text search of given string similar getArticle().
|
|
|
|
virtual sptr< DataRequest > getSearchResults( QString const & searchString,
|
|
|
|
int searchMode, bool matchCase,
|
|
|
|
int distanceBetweenWords,
|
2017-07-25 15:28:29 +00:00
|
|
|
int maxArticlesPerDictionary,
|
2018-04-10 14:49:52 +00:00
|
|
|
bool ignoreWordsOrder,
|
|
|
|
bool ignoreDiacritics );
|
2014-04-16 16:18:28 +00:00
|
|
|
|
2012-09-07 11:51:42 +00:00
|
|
|
// Return dictionary description if presented
|
|
|
|
virtual QString const& getDescription();
|
|
|
|
|
2012-11-29 17:12:54 +00:00
|
|
|
// Return dictionary main file name
|
|
|
|
virtual QString getMainFilename();
|
|
|
|
|
2013-07-10 13:48:09 +00:00
|
|
|
/// Check text direction
|
2013-07-16 14:23:42 +00:00
|
|
|
bool isFromLanguageRTL()
|
|
|
|
{ return LangCoder::isLanguageRTL( getLangFrom() ); }
|
|
|
|
bool isToLanguageRTL()
|
|
|
|
{ return LangCoder::isLanguageRTL( getLangTo() ); }
|
2013-07-10 13:48:09 +00:00
|
|
|
|
2013-06-09 13:31:57 +00:00
|
|
|
/// Return true if dictionary is local dictionary
|
|
|
|
virtual bool isLocalDictionary()
|
|
|
|
{ return false; }
|
|
|
|
|
2014-04-16 16:18:28 +00:00
|
|
|
/// Dictionary can full-text search
|
|
|
|
bool canFTS()
|
|
|
|
{ return can_FTS; }
|
|
|
|
|
|
|
|
/// Dictionary have index for full-text search
|
|
|
|
bool haveFTSIndex()
|
2021-11-27 07:17:33 +00:00
|
|
|
{ return Utils::AtomicInt::loadAcquire( FTS_index_completed ) != 0; }
|
2014-04-16 16:18:28 +00:00
|
|
|
|
|
|
|
/// Make index for full-text search
|
|
|
|
virtual void makeFTSIndex( QAtomicInt &, bool )
|
|
|
|
{}
|
|
|
|
|
2014-04-17 14:31:51 +00:00
|
|
|
/// Set full-text search parameters
|
|
|
|
virtual void setFTSParameters( Config::FullTextSearch const & )
|
|
|
|
{}
|
|
|
|
|
2014-02-28 12:36:28 +00:00
|
|
|
/// Retrieve all dictionary headwords
|
|
|
|
virtual bool getHeadwords( QStringList & )
|
|
|
|
{ return false; }
|
2022-09-19 14:19:22 +00:00
|
|
|
virtual void findHeadWordsWithLenth( int &, QSet< QString > * headwords, uint32_t length ){}
|
2014-02-28 12:36:28 +00:00
|
|
|
|
2017-03-09 16:11:17 +00:00
|
|
|
/// Enable/disable search via synonyms
|
|
|
|
void setSynonymSearchEnabled( bool enabled )
|
|
|
|
{ synonymSearchEnabled = enabled; }
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
virtual ~Class()
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Callbacks to be used when the dictionaries are being initialized.
|
|
|
|
class Initializing
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Called by the Format instance to notify the caller that the given
|
|
|
|
/// dictionary is being indexed. Since indexing can take some time, this
|
|
|
|
/// is useful to show in some kind of a splash screen.
|
|
|
|
/// The dictionaryName is in utf8.
|
2022-06-03 13:28:41 +00:00
|
|
|
virtual void indexingDictionary( string const & dictionaryName ) noexcept=0;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
virtual ~Initializing()
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
/// Generates an id based on the set of file names which the dictionary
|
|
|
|
/// consists of. The resulting id is an alphanumeric hex value made by
|
|
|
|
/// hashing the file names. This id should be used to identify dictionary
|
|
|
|
/// and for the index file name, if one is needed.
|
|
|
|
/// This function is supposed to be used by dictionary implementations.
|
2022-06-03 13:28:41 +00:00
|
|
|
string makeDictionaryId( vector< string > const & dictionaryFiles ) noexcept;
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
/// Checks if it is needed to regenerate index file based on its timestamp
|
|
|
|
/// and the timestamps of the dictionary files. If some files are newer than
|
|
|
|
/// the index file, or the index file doesn't exist, returns true. If some
|
|
|
|
/// dictionary files don't exist, returns true, too.
|
|
|
|
/// This function is supposed to be used by dictionary implementations.
|
|
|
|
bool needToRebuildIndex( vector< string > const & dictionaryFiles,
|
2022-06-03 13:28:41 +00:00
|
|
|
string const & indexFile ) noexcept;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2011-05-29 05:08:37 +00:00
|
|
|
/// Returns a random dictionary id useful for interactively created
|
|
|
|
/// dictionaries.
|
|
|
|
QString generateRandomDictionaryId();
|
|
|
|
|
2022-03-13 16:17:34 +00:00
|
|
|
QMap< std::string, sptr< Dictionary::Class > >
|
|
|
|
dictToMap( std::vector< sptr< Dictionary::Class > > const & dicts );
|
2022-03-14 00:22:31 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|