2014-05-20 13:59:56 +00:00
|
|
|
/* This file is (c) 2014 Abs62
|
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "epwing_book.hh"
|
|
|
|
#include "epwing.hh"
|
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QDir>
|
2014-07-10 13:55:14 +00:00
|
|
|
#include <QRunnable>
|
|
|
|
#include <QSemaphore>
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
#include <map>
|
2022-06-19 12:24:34 +00:00
|
|
|
#include <QtConcurrent>
|
2014-05-20 13:59:56 +00:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
2023-03-12 07:04:49 +00:00
|
|
|
#include <QObject>
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
#include "btreeidx.hh"
|
|
|
|
#include "folding.hh"
|
|
|
|
#include "gddebug.hh"
|
|
|
|
#include "fsencoding.hh"
|
|
|
|
#include "chunkedstorage.hh"
|
|
|
|
#include "wstring.hh"
|
|
|
|
#include "wstring_qt.hh"
|
|
|
|
#include "utf8.hh"
|
|
|
|
#include "filetype.hh"
|
|
|
|
#include "ftshelpers.hh"
|
2023-03-12 07:04:49 +00:00
|
|
|
#include "base/globalregex.hh"
|
2023-04-07 14:20:54 +00:00
|
|
|
#include "sptr.hh"
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
namespace Epwing {
|
|
|
|
|
|
|
|
using BtreeIndexing::WordArticleLink;
|
|
|
|
using BtreeIndexing::IndexedWords;
|
|
|
|
using BtreeIndexing::IndexInfo;
|
|
|
|
|
|
|
|
using std::map;
|
|
|
|
using std::multimap;
|
|
|
|
using std::vector;
|
|
|
|
using std::set;
|
|
|
|
using std::pair;
|
|
|
|
using gd::wstring;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
#pragma pack( push, 1 )
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
Signature = 0x58575045, // EPWX on little-endian, XWPE on big-endian
|
2022-05-22 16:13:24 +00:00
|
|
|
CurrentFormatVersion = 6 + BtreeIndexing::FormatVersion + Folding::Version
|
2014-05-20 13:59:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IdxHeader
|
|
|
|
{
|
|
|
|
quint32 signature; // First comes the signature, EPWX
|
|
|
|
quint32 formatVersion; // File format version (CurrentFormatVersion)
|
|
|
|
quint32 chunksOffset; // The offset to chunks' storage
|
|
|
|
quint32 indexBtreeMaxElements; // Two fields from IndexInfo
|
|
|
|
quint32 indexRootOffset;
|
|
|
|
quint32 wordCount;
|
|
|
|
quint32 articleCount;
|
|
|
|
quint32 nameSize;
|
|
|
|
quint32 langFrom; // Source language
|
|
|
|
quint32 langTo; // Target language
|
|
|
|
}
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
__attribute__((packed))
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
#pragma pack( pop )
|
|
|
|
|
|
|
|
bool indexIsOldOrBad( string const & indexFile )
|
|
|
|
{
|
|
|
|
File::Class idx( indexFile, "rb" );
|
|
|
|
|
|
|
|
IdxHeader header;
|
|
|
|
|
|
|
|
return idx.readRecords( &header, sizeof( header ), 1 ) != 1 ||
|
|
|
|
header.signature != Signature ||
|
|
|
|
header.formatVersion != CurrentFormatVersion;
|
|
|
|
}
|
2023-04-07 14:20:54 +00:00
|
|
|
class EpwingHeadwordsRequest;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
class EpwingDictionary: public BtreeIndexing::BtreeDictionary
|
|
|
|
{
|
2023-03-20 16:48:06 +00:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Epwing::EpwingDictionary)
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
Mutex idxMutex;
|
|
|
|
File::Class idx;
|
|
|
|
IdxHeader idxHeader;
|
|
|
|
string bookName;
|
|
|
|
ChunkedStorage::Reader chunks;
|
|
|
|
Epwing::Book::EpwingBook eBook;
|
|
|
|
QString cacheDirectory;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
EpwingDictionary( string const & id, string const & indexFile,
|
|
|
|
vector< string > const & dictionaryFiles,
|
|
|
|
int subBook );
|
|
|
|
|
|
|
|
~EpwingDictionary();
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
string getName() noexcept override
|
2014-05-20 13:59:56 +00:00
|
|
|
{ return bookName; }
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
map< Dictionary::Property, string > getProperties() noexcept override
|
2014-05-20 13:59:56 +00:00
|
|
|
{ return map< Dictionary::Property, string >(); }
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
unsigned long getArticleCount() noexcept override
|
2014-05-20 13:59:56 +00:00
|
|
|
{ return idxHeader.articleCount; }
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
unsigned long getWordCount() noexcept override
|
2014-05-20 13:59:56 +00:00
|
|
|
{ return idxHeader.wordCount; }
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
inline quint32 getLangFrom() const override
|
2014-05-20 13:59:56 +00:00
|
|
|
{ return idxHeader.langFrom; }
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
inline quint32 getLangTo() const override
|
2014-05-20 13:59:56 +00:00
|
|
|
{ return idxHeader.langTo; }
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
QString const& getDescription() override;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2023-04-07 14:20:54 +00:00
|
|
|
void getHeadwordPos( wstring const & word_, QVector< int > & pg, QVector< int > & off );
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
sptr< Dictionary::DataRequest > getArticle( wstring const &,
|
2014-05-20 13:59:56 +00:00
|
|
|
vector< wstring > const & alts,
|
2018-06-13 16:00:42 +00:00
|
|
|
wstring const &,
|
2022-12-29 07:07:40 +00:00
|
|
|
bool ignoreDiacritics ) override
|
2022-01-09 08:35:07 +00:00
|
|
|
;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
sptr< Dictionary::DataRequest > getResource( string const & name ) override
|
2022-01-09 08:35:07 +00:00
|
|
|
;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
sptr< Dictionary::DataRequest > getSearchResults( QString const & searchString,
|
2014-05-20 13:59:56 +00:00
|
|
|
int searchMode, bool matchCase,
|
|
|
|
int distanceBetweenWords,
|
2017-07-25 15:28:29 +00:00
|
|
|
int maxResults,
|
2018-04-10 14:49:52 +00:00
|
|
|
bool ignoreWordsOrder,
|
2022-12-29 07:07:40 +00:00
|
|
|
bool ignoreDiacritics ) override;
|
|
|
|
void getArticleText( uint32_t articleAddress, QString & headword, QString & text ) override;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration ) override;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
void setFTSParameters( Config::FullTextSearch const & fts ) override
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
|
|
|
if( ensureInitDone().size() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
can_FTS = fts.enabled
|
|
|
|
&& !fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive )
|
|
|
|
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
|
|
|
|
}
|
|
|
|
|
2014-07-08 14:56:24 +00:00
|
|
|
static int japaneseWriting( gd::wchar ch );
|
|
|
|
|
|
|
|
static bool isSign( gd::wchar ch );
|
|
|
|
|
|
|
|
static bool isJapanesePunctiation( gd::wchar ch );
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
sptr< Dictionary::WordSearchRequest > prefixMatch( wstring const &,
|
|
|
|
unsigned long ) override
|
2022-01-09 08:35:07 +00:00
|
|
|
;
|
2014-07-10 13:55:14 +00:00
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
sptr< Dictionary::WordSearchRequest > stemmedMatch( wstring const &,
|
2014-07-10 13:55:14 +00:00
|
|
|
unsigned minLength,
|
|
|
|
unsigned maxSuffixVariation,
|
2022-12-29 07:07:40 +00:00
|
|
|
unsigned long maxResults ) override
|
2022-01-09 08:35:07 +00:00
|
|
|
;
|
2014-07-10 13:55:14 +00:00
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
protected:
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
void loadIcon() noexcept override;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/// Loads the article.
|
2022-10-04 07:07:04 +00:00
|
|
|
void loadArticle( quint32 address,
|
|
|
|
string & articleHeadword,
|
|
|
|
string & articleText,
|
|
|
|
int & articlePage,
|
2022-10-05 08:33:59 +00:00
|
|
|
int & articleOffset );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2023-04-07 14:20:54 +00:00
|
|
|
|
|
|
|
sptr< Dictionary::WordSearchRequest > findHeadwordsForSynonym( wstring const & word ) override;
|
|
|
|
|
|
|
|
void loadArticleNextPage( string & articleHeadword, string & articleText, int & articlePage, int & articleOffset );
|
|
|
|
void loadArticlePreviousPage( string & articleHeadword, string & articleText, int & articlePage, int & articleOffset );
|
2023-03-12 07:04:49 +00:00
|
|
|
|
2014-07-11 13:41:29 +00:00
|
|
|
void loadArticle( int articlePage, int articleOffset, string & articleHeadword,
|
2014-05-20 13:59:56 +00:00
|
|
|
string & articleText );
|
|
|
|
|
|
|
|
void createCacheDirectory();
|
|
|
|
|
|
|
|
void removeDirectory( QString const & directory );
|
|
|
|
|
|
|
|
QString const & getImagesCacheDir()
|
|
|
|
{ return eBook.getImagesCacheDir(); }
|
|
|
|
|
|
|
|
QString const & getSoundsCacheDir()
|
|
|
|
{ return eBook.getSoundsCacheDir(); }
|
|
|
|
|
|
|
|
QString const & getMoviesCacheDir()
|
|
|
|
{ return eBook.getMoviesCacheDir(); }
|
|
|
|
|
|
|
|
friend class EpwingArticleRequest;
|
|
|
|
friend class EpwingResourceRequest;
|
2014-07-10 13:55:14 +00:00
|
|
|
friend class EpwingWordSearchRequest;
|
2023-04-07 14:20:54 +00:00
|
|
|
|
|
|
|
friend class EpwingHeadwordsRequest;
|
2023-04-08 03:50:45 +00:00
|
|
|
string epwing_previous_button( const int& articleOffset, const int& articlePage);
|
|
|
|
string epwing_next_button( const int& articleOffset, const int& articlePage);
|
|
|
|
bool readHeadword( const EB_Position & pos, QString & headword );
|
2014-05-20 13:59:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
EpwingDictionary::EpwingDictionary( string const & id,
|
|
|
|
string const & indexFile,
|
|
|
|
vector< string > const & dictionaryFiles,
|
|
|
|
int subBook ):
|
|
|
|
BtreeDictionary( id, dictionaryFiles ),
|
|
|
|
idx( indexFile, "rb" ),
|
|
|
|
idxHeader( idx.read< IdxHeader >() ),
|
|
|
|
chunks( idx, idxHeader.chunksOffset )
|
|
|
|
{
|
|
|
|
vector< char > data( idxHeader.nameSize );
|
|
|
|
idx.seek( sizeof( idxHeader ) );
|
2019-01-17 14:53:13 +00:00
|
|
|
if( data.size() > 0 )
|
|
|
|
{
|
|
|
|
idx.read( &data.front(), idxHeader.nameSize );
|
|
|
|
bookName = string( &data.front(), idxHeader.nameSize );
|
|
|
|
}
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
// Initialize eBook
|
|
|
|
|
|
|
|
eBook.setBook( dictionaryFiles[ 0 ] );
|
|
|
|
eBook.setSubBook( subBook );
|
|
|
|
|
|
|
|
// Initialize the index
|
|
|
|
|
|
|
|
openIndex( IndexInfo( idxHeader.indexBtreeMaxElements,
|
|
|
|
idxHeader.indexRootOffset ),
|
|
|
|
idx, idxMutex );
|
|
|
|
|
|
|
|
eBook.setDictID( getId() );
|
|
|
|
|
|
|
|
cacheDirectory = QDir::tempPath() + QDir::separator()
|
|
|
|
+ QString::fromUtf8( getId().c_str() )
|
|
|
|
+ ".cache";
|
|
|
|
eBook.setCacheDirectory( cacheDirectory );
|
|
|
|
|
|
|
|
// Full-text search parameters
|
|
|
|
|
|
|
|
can_FTS = true;
|
|
|
|
|
2022-10-06 03:04:48 +00:00
|
|
|
ftsIdxName = indexFile + Dictionary::getFtsSuffix();
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
if( !Dictionary::needToRebuildIndex( dictionaryFiles, ftsIdxName )
|
2014-11-22 14:22:04 +00:00
|
|
|
&& !FtsHelpers::ftsIndexIsOldOrBad( ftsIdxName, this ) )
|
2014-05-20 13:59:56 +00:00
|
|
|
FTS_index_completed.ref();
|
|
|
|
}
|
|
|
|
|
|
|
|
EpwingDictionary::~EpwingDictionary()
|
|
|
|
{
|
|
|
|
removeDirectory( cacheDirectory );
|
|
|
|
}
|
|
|
|
|
2022-06-03 13:28:41 +00:00
|
|
|
void EpwingDictionary::loadIcon() noexcept
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
|
|
|
if ( dictionaryIconLoaded )
|
|
|
|
return;
|
|
|
|
|
2023-04-13 10:08:32 +00:00
|
|
|
QString fileName = QString::fromStdString( getDictionaryFilenames()[ 0 ] ) + QDir::separator()
|
|
|
|
+ eBook.getCurrentSubBookDirectory() + ".";
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2014-05-22 16:53:06 +00:00
|
|
|
if( !fileName.isEmpty() )
|
2014-05-20 13:59:56 +00:00
|
|
|
loadIconFromFile( fileName );
|
|
|
|
|
|
|
|
if( dictionaryIcon.isNull() )
|
|
|
|
{
|
|
|
|
// Load failed -- use default icons
|
|
|
|
dictionaryNativeIcon = dictionaryIcon = QIcon(":/icons/icon32_epwing.png");
|
|
|
|
}
|
|
|
|
|
|
|
|
dictionaryIconLoaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EpwingDictionary::removeDirectory( QString const & directory )
|
|
|
|
{
|
|
|
|
QDir dir( directory );
|
|
|
|
Q_FOREACH( QFileInfo info, dir.entryInfoList( QDir::NoDotAndDotDot
|
|
|
|
| QDir::AllDirs
|
|
|
|
| QDir::Files,
|
|
|
|
QDir::DirsFirst))
|
|
|
|
{
|
|
|
|
if( info.isDir() )
|
|
|
|
removeDirectory( info.absoluteFilePath() );
|
|
|
|
else
|
|
|
|
QFile::remove( info.absoluteFilePath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
dir.rmdir( directory );
|
|
|
|
}
|
|
|
|
|
2022-10-05 08:33:59 +00:00
|
|
|
void EpwingDictionary::loadArticle(
|
|
|
|
quint32 address, string & articleHeadword, string & articleText, int & articlePage, int & articleOffset )
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
|
|
|
vector< char > chunk;
|
|
|
|
|
|
|
|
char * articleProps;
|
|
|
|
|
|
|
|
{
|
|
|
|
Mutex::Lock _( idxMutex );
|
|
|
|
articleProps = chunks.getBlock( address, chunk );
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy( &articlePage, articleProps, sizeof( articlePage ) );
|
|
|
|
memcpy( &articleOffset, articleProps + sizeof( articlePage ),
|
|
|
|
sizeof( articleOffset ) );
|
|
|
|
|
|
|
|
QString headword, text;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Mutex::Lock _( eBook.getLibMutex() );
|
2022-10-05 08:33:59 +00:00
|
|
|
eBook.getArticle( headword, text, articlePage, articleOffset, false);
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
catch( std::exception & e )
|
|
|
|
{
|
|
|
|
text = QString( "Article reading error: %1")
|
|
|
|
.arg( QString::fromUtf8( e.what() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
articleHeadword = string( headword.toUtf8().data() );
|
|
|
|
articleText = string( text.toUtf8().data() );
|
|
|
|
|
|
|
|
string prefix( "<div class=\"epwing_text\">" );
|
|
|
|
|
|
|
|
articleText = prefix + articleText + "</div>";
|
|
|
|
}
|
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
string Epwing::EpwingDictionary::epwing_previous_button( const int& articlePage, const int& articleOffset)
|
2023-03-12 07:04:49 +00:00
|
|
|
{
|
|
|
|
QString previousButton = QString( "p%1At%2" ).arg( articlePage ).arg( articleOffset );
|
2023-04-08 03:50:45 +00:00
|
|
|
string previousLink = R"(<p><a class="epwing_previous_page" href="gdlookup://localhost/)"
|
2023-03-20 16:48:06 +00:00
|
|
|
+ previousButton.toStdString() + "\">" + tr( "Previous Page" ).toStdString() + "</a></p>";
|
2023-03-12 07:04:49 +00:00
|
|
|
|
|
|
|
return previousLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EpwingDictionary::loadArticleNextPage(string & articleHeadword, string & articleText, int & articlePage, int & articleOffset )
|
|
|
|
{
|
|
|
|
QString headword, text;
|
|
|
|
EB_Position pos;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Mutex::Lock _( eBook.getLibMutex() );
|
|
|
|
pos = eBook.getArticleNextPage( headword, text, articlePage, articleOffset, false );
|
|
|
|
}
|
|
|
|
catch( std::exception & e )
|
|
|
|
{
|
|
|
|
text = QString( "Article reading error: %1")
|
|
|
|
.arg( QString::fromUtf8( e.what() ) );
|
2023-03-20 13:53:02 +00:00
|
|
|
articleText = string( text.toUtf8().data() );
|
|
|
|
return;
|
2023-03-12 07:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
articleHeadword = string( headword.toUtf8().data() );
|
|
|
|
articleText = string( text.toUtf8().data() );
|
|
|
|
|
|
|
|
string prefix( "<div class=\"epwing_text\">" );
|
|
|
|
string previousLink = epwing_previous_button(articlePage, articleOffset);
|
|
|
|
|
|
|
|
articleText = prefix + previousLink + articleText;
|
|
|
|
string nextLink = epwing_next_button(pos.page, pos.offset);
|
|
|
|
articleText = articleText + nextLink;
|
|
|
|
articleText = articleText + "</div>";
|
|
|
|
}
|
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
string Epwing::EpwingDictionary::epwing_next_button( const int& articlePage, const int& articleOffset )
|
2023-03-12 07:04:49 +00:00
|
|
|
{
|
|
|
|
QString refLink = QString( "r%1At%2" ).arg( articlePage ).arg( articleOffset );
|
2023-04-08 03:50:45 +00:00
|
|
|
string nextLink = R"(<p><a class="epwing_next_page" href="gdlookup://localhost/)" + refLink.toStdString() + "\">"
|
2023-03-20 16:48:06 +00:00
|
|
|
+ tr( "Next Page" ).toStdString() + "</a></p>";
|
2023-03-12 07:04:49 +00:00
|
|
|
|
|
|
|
return nextLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EpwingDictionary::loadArticlePreviousPage(
|
|
|
|
string & articleHeadword, string & articleText, int & articlePage, int & articleOffset )
|
|
|
|
{
|
|
|
|
QString headword, text;
|
|
|
|
EB_Position pos;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Mutex::Lock _( eBook.getLibMutex() );
|
|
|
|
pos = eBook.getArticlePreviousPage( headword, text, articlePage, articleOffset, false );
|
2023-03-20 13:53:02 +00:00
|
|
|
}
|
|
|
|
catch( std::exception & e ) {
|
|
|
|
text = QString( "Article reading error: %1" ).arg( QString::fromUtf8( e.what() ) );
|
|
|
|
articleText = string( text.toUtf8().data() );
|
|
|
|
return;
|
2023-03-12 07:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
articleHeadword = string( headword.toUtf8().data() );
|
|
|
|
articleText = string( text.toUtf8().data() );
|
|
|
|
|
|
|
|
string prefix( "<div class=\"epwing_text\">" );
|
|
|
|
|
|
|
|
string previousLink = epwing_previous_button(pos.page, pos.offset );
|
|
|
|
articleText = prefix + previousLink + articleText;
|
|
|
|
string nextLink = epwing_next_button( articlePage, articleOffset );
|
|
|
|
articleText = articleText + nextLink;
|
|
|
|
articleText = articleText + "</div>";
|
|
|
|
}
|
|
|
|
|
2014-07-11 13:41:29 +00:00
|
|
|
void EpwingDictionary::loadArticle( int articlePage,
|
|
|
|
int articleOffset,
|
2014-07-10 13:55:14 +00:00
|
|
|
string & articleHeadword,
|
|
|
|
string & articleText )
|
|
|
|
{
|
|
|
|
QString headword, text;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Mutex::Lock _( eBook.getLibMutex() );
|
|
|
|
eBook.getArticle( headword, text, articlePage, articleOffset, false );
|
|
|
|
}
|
|
|
|
catch( std::exception & e )
|
|
|
|
{
|
|
|
|
text = QString( "Article reading error: %1")
|
|
|
|
.arg( QString::fromUtf8( e.what() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
articleHeadword = string( headword.toUtf8().data() );
|
|
|
|
articleText = string( text.toUtf8().data() );
|
|
|
|
|
|
|
|
string prefix( "<div class=\"epwing_text\">" );
|
|
|
|
|
|
|
|
articleText = prefix + articleText + "</div>";
|
|
|
|
}
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
QString const& EpwingDictionary::getDescription()
|
|
|
|
{
|
|
|
|
if( !dictionaryDescription.isEmpty() )
|
|
|
|
return dictionaryDescription;
|
|
|
|
|
|
|
|
dictionaryDescription = "NONE";
|
|
|
|
|
|
|
|
QString str;
|
|
|
|
{
|
|
|
|
Mutex::Lock _( eBook.getLibMutex() );
|
|
|
|
str = eBook.copyright();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !str.isEmpty() )
|
|
|
|
dictionaryDescription = str;
|
|
|
|
|
|
|
|
return dictionaryDescription;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EpwingDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration )
|
|
|
|
{
|
|
|
|
if( !( Dictionary::needToRebuildIndex( getDictionaryFilenames(), ftsIdxName )
|
2014-11-22 14:22:04 +00:00
|
|
|
|| FtsHelpers::ftsIndexIsOldOrBad( ftsIdxName, this ) ) )
|
2014-05-20 13:59:56 +00:00
|
|
|
FTS_index_completed.ref();
|
|
|
|
|
|
|
|
|
|
|
|
if( haveFTSIndex() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( firstIteration && getArticleCount() > FTS::MaxDictionarySizeForFastSearch )
|
|
|
|
return;
|
|
|
|
|
|
|
|
gdDebug( "Epwing: Building the full-text index for dictionary: %s\n",
|
|
|
|
getName().c_str() );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
FtsHelpers::makeFTSIndex( this, isCancelled );
|
|
|
|
FTS_index_completed.ref();
|
|
|
|
}
|
|
|
|
catch( std::exception &ex )
|
|
|
|
{
|
2014-07-15 13:47:19 +00:00
|
|
|
gdWarning( "Epwing: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
|
2023-04-13 10:08:32 +00:00
|
|
|
QFile::remove( QString::fromStdString( ftsIdxName ) );
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EpwingDictionary::getArticleText( uint32_t articleAddress, QString & headword, QString & text )
|
|
|
|
{
|
|
|
|
headword.clear();
|
|
|
|
text.clear();
|
|
|
|
|
|
|
|
vector< char > chunk;
|
|
|
|
char * articleProps;
|
|
|
|
|
|
|
|
{
|
|
|
|
Mutex::Lock _( idxMutex );
|
|
|
|
articleProps = chunks.getBlock( articleAddress, chunk );
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t articlePage, articleOffset;
|
|
|
|
|
|
|
|
memcpy( &articlePage, articleProps, sizeof( articlePage ) );
|
|
|
|
memcpy( &articleOffset, articleProps + sizeof( articlePage ),
|
|
|
|
sizeof( articleOffset ) );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Mutex::Lock _( eBook.getLibMutex() );
|
|
|
|
eBook.getArticle( headword, text, articlePage, articleOffset, true );
|
|
|
|
}
|
|
|
|
catch( std::exception & e )
|
|
|
|
{
|
|
|
|
text = QString( "Article reading error: %1")
|
|
|
|
.arg( QString::fromUtf8( e.what() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-07 14:20:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EpwingHeadwordsRequest: public Dictionary::WordSearchRequest
|
|
|
|
{
|
|
|
|
wstring str;
|
|
|
|
EpwingDictionary & dict;
|
|
|
|
|
|
|
|
QAtomicInt isCancelled;
|
|
|
|
QFuture< void > f;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
EpwingHeadwordsRequest( wstring const & word_, EpwingDictionary & dict_ ):
|
|
|
|
str( word_ ),
|
|
|
|
dict( dict_ )
|
|
|
|
{
|
|
|
|
f = QtConcurrent::run( [ this ]() {
|
|
|
|
this->run();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
void run();
|
|
|
|
|
|
|
|
void cancel() override { isCancelled.ref(); }
|
|
|
|
|
|
|
|
~EpwingHeadwordsRequest()
|
|
|
|
{
|
|
|
|
isCancelled.ref();
|
|
|
|
f.waitForFinished();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void EpwingHeadwordsRequest::run()
|
|
|
|
{
|
|
|
|
if ( Utils::AtomicInt::loadAcquire( isCancelled ) ) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegularExpressionMatch m = RX::Epwing::refWord.match( gd::toQString( str ) );
|
|
|
|
if ( !m.hasMatch() ) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int articlePage = m.captured( 1 ).toInt();
|
|
|
|
int articleOffset = m.captured( 2 ).toInt();
|
|
|
|
EB_Position pos;
|
|
|
|
pos.offset = articleOffset;
|
|
|
|
pos.page = articlePage;
|
|
|
|
QString headword;
|
|
|
|
dict.readHeadword( pos, headword );
|
|
|
|
if ( headword.isEmpty() ) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto parts = headword.split(' ',Qt::SkipEmptyParts);
|
|
|
|
if(parts.empty())
|
|
|
|
{
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVector< int > pg;
|
|
|
|
QVector< int > off;
|
|
|
|
dict.getHeadwordPos( parts[0].toStdU32String(), pg, off );
|
|
|
|
|
|
|
|
for ( unsigned i = 0; i < pg.size(); ++i ) {
|
|
|
|
if ( Utils::AtomicInt::loadAcquire( isCancelled ) ) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pg.at( i ) == articlePage && off.at( i ) == articleOffset ) {
|
|
|
|
|
|
|
|
Mutex::Lock _( dataMutex );
|
|
|
|
|
|
|
|
matches.emplace_back( parts[0].toStdU32String() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
sptr< Dictionary::WordSearchRequest > EpwingDictionary::findHeadwordsForSynonym( wstring const & word )
|
|
|
|
{
|
|
|
|
return synonymSearchEnabled ? std::make_shared< EpwingHeadwordsRequest >( word, *this ) :
|
|
|
|
Class::findHeadwordsForSynonym( word );
|
|
|
|
}
|
2014-05-20 13:59:56 +00:00
|
|
|
/// EpwingDictionary::getArticle()
|
|
|
|
|
|
|
|
class EpwingArticleRequest: public Dictionary::DataRequest
|
|
|
|
{
|
|
|
|
wstring word;
|
|
|
|
vector< wstring > alts;
|
|
|
|
EpwingDictionary & dict;
|
2018-06-13 16:00:42 +00:00
|
|
|
bool ignoreDiacritics;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
QAtomicInt isCancelled;
|
2022-06-19 12:24:34 +00:00
|
|
|
QFuture< void > f;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
EpwingArticleRequest( wstring const & word_,
|
|
|
|
vector< wstring > const & alts_,
|
2018-06-13 16:00:42 +00:00
|
|
|
EpwingDictionary & dict_, bool ignoreDiacritics_ ):
|
|
|
|
word( word_ ), alts( alts_ ), dict( dict_ ), ignoreDiacritics( ignoreDiacritics_ )
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
2022-06-19 12:24:34 +00:00
|
|
|
f = QtConcurrent::run( [ this ]() { this->run(); } );
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 12:26:54 +00:00
|
|
|
void run();
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2022-09-12 06:10:25 +00:00
|
|
|
void getBuiltInArticle(wstring const & word_, QVector< int > & pages,
|
|
|
|
QVector< int > & offsets,
|
|
|
|
multimap< wstring, pair< string, string > > & mainArticles );
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
void cancel() override
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
|
|
|
isCancelled.ref();
|
|
|
|
}
|
|
|
|
|
|
|
|
~EpwingArticleRequest()
|
|
|
|
{
|
|
|
|
isCancelled.ref();
|
2022-06-19 12:24:34 +00:00
|
|
|
f.waitForFinished();
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void EpwingArticleRequest::run()
|
|
|
|
{
|
2021-11-27 07:17:33 +00:00
|
|
|
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-13 16:00:42 +00:00
|
|
|
vector< WordArticleLink > chain = dict.findArticles( word, ignoreDiacritics );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
for ( auto & alt : alts ) {
|
2014-05-20 13:59:56 +00:00
|
|
|
/// Make an additional query for each alt
|
2023-04-08 03:50:45 +00:00
|
|
|
vector< WordArticleLink > altChain = dict.findArticles( alt, ignoreDiacritics );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
chain.insert( chain.end(), altChain.begin(), altChain.end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
multimap< wstring, pair< string, string > > mainArticles, alternateArticles;
|
|
|
|
|
|
|
|
set< quint32 > articlesIncluded; // Some synonims make it that the articles
|
2023-03-22 14:52:49 +00:00
|
|
|
// appear several times. We combat this
|
|
|
|
// by only allowing them to appear once.
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
wstring wordCaseFolded = Folding::applySimpleCaseOnly( word );
|
2018-06-13 16:00:42 +00:00
|
|
|
if( ignoreDiacritics )
|
|
|
|
wordCaseFolded = Folding::applyDiacriticsOnly( wordCaseFolded );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2014-07-11 13:41:29 +00:00
|
|
|
QVector< int > pages, offsets;
|
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
for ( auto & x : chain ) {
|
2021-11-27 07:17:33 +00:00
|
|
|
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
if ( articlesIncluded.find( x.articleOffset ) != articlesIncluded.end() )
|
2014-05-20 13:59:56 +00:00
|
|
|
continue; // We already have this article in the body.
|
|
|
|
|
|
|
|
// Now grab that article
|
|
|
|
|
|
|
|
string headword, articleText;
|
2014-07-11 13:41:29 +00:00
|
|
|
int articlePage, articleOffset;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2023-04-08 03:50:45 +00:00
|
|
|
dict.loadArticle( x.articleOffset, headword, articleText, articlePage, articleOffset );
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-11 13:41:29 +00:00
|
|
|
pages.append( articlePage );
|
|
|
|
offsets.append( articleOffset );
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
// Ok. Now, does it go to main articles, or to alternate ones? We list
|
|
|
|
// main ones first, and alternates after.
|
|
|
|
|
|
|
|
// We do the case-folded comparison here.
|
|
|
|
|
|
|
|
wstring headwordStripped =
|
|
|
|
Folding::applySimpleCaseOnly( Utf8::decode( headword ) );
|
2018-06-13 16:00:42 +00:00
|
|
|
if( ignoreDiacritics )
|
|
|
|
headwordStripped = Folding::applyDiacriticsOnly( headwordStripped );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
multimap< wstring, pair< string, string > > & mapToUse =
|
|
|
|
( wordCaseFolded == headwordStripped ) ?
|
|
|
|
mainArticles : alternateArticles;
|
|
|
|
|
|
|
|
mapToUse.insert( pair< wstring, pair< string, string > >(
|
|
|
|
Folding::applySimpleCaseOnly( Utf8::decode( headword ) ),
|
|
|
|
pair< string, string >( headword, articleText ) ) );
|
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
articlesIncluded.insert( x.articleOffset );
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-12 07:04:49 +00:00
|
|
|
QRegularExpressionMatch m = RX::Epwing::refWord.match( gd::toQString( word ) );
|
|
|
|
bool ref = m.hasMatch();
|
|
|
|
|
2023-04-07 14:20:54 +00:00
|
|
|
// Also try to find word in the built-in dictionary index
|
|
|
|
getBuiltInArticle( word, pages, offsets, mainArticles );
|
2023-04-08 03:50:45 +00:00
|
|
|
for ( auto & alt : alts ) {
|
|
|
|
getBuiltInArticle( alt, pages, offsets, alternateArticles );
|
2023-03-20 13:53:02 +00:00
|
|
|
}
|
|
|
|
|
2023-03-12 07:04:49 +00:00
|
|
|
if ( mainArticles.empty() && alternateArticles.empty() && !ref)
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
|
|
|
// No such word
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-20 14:41:30 +00:00
|
|
|
string result = "<div class=\"epwing_article\">";
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
multimap< wstring, pair< string, string > >::const_iterator i;
|
|
|
|
|
|
|
|
for( i = mainArticles.begin(); i != mainArticles.end(); ++i )
|
|
|
|
{
|
|
|
|
result += "<h3>";
|
|
|
|
result += i->second.first;
|
|
|
|
result += "</h3>";
|
|
|
|
result += i->second.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i = alternateArticles.begin(); i != alternateArticles.end(); ++i )
|
|
|
|
{
|
|
|
|
result += "<h3>";
|
|
|
|
result += i->second.first;
|
|
|
|
result += "</h3>";
|
|
|
|
result += i->second.second;
|
|
|
|
}
|
|
|
|
|
2023-04-07 14:20:54 +00:00
|
|
|
//only load the next/previous page when not hitted.
|
|
|
|
if( mainArticles.empty() && alternateArticles.empty() && ref )
|
2023-03-12 07:04:49 +00:00
|
|
|
{
|
2023-04-07 14:20:54 +00:00
|
|
|
string headword, articleText;
|
|
|
|
int articlePage = m.captured( 1 ).toInt();
|
|
|
|
int articleOffset = m.captured( 2 ).toInt();
|
|
|
|
if( word[ 0 ] =='r' )
|
|
|
|
dict.loadArticleNextPage( headword, articleText, articlePage, articleOffset );
|
|
|
|
else
|
2023-03-12 07:04:49 +00:00
|
|
|
{
|
2023-04-07 14:20:54 +00:00
|
|
|
//starts with p
|
|
|
|
dict.loadArticlePreviousPage( headword, articleText, articlePage, articleOffset );
|
2023-03-12 07:04:49 +00:00
|
|
|
}
|
2023-04-07 14:20:54 +00:00
|
|
|
|
|
|
|
result += articleText;
|
2023-03-12 07:04:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-09 12:38:23 +00:00
|
|
|
result += "</div>";
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
Mutex::Lock _( dataMutex );
|
|
|
|
|
|
|
|
data.resize( result.size() );
|
|
|
|
|
|
|
|
memcpy( &data.front(), result.data(), result.size() );
|
|
|
|
|
|
|
|
hasAnyData = true;
|
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
2022-09-12 06:10:25 +00:00
|
|
|
void EpwingArticleRequest::getBuiltInArticle( wstring const & word_,
|
|
|
|
QVector< int > & pages,
|
|
|
|
QVector< int > & offsets,
|
|
|
|
multimap< wstring, pair< string, string > > & mainArticles )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string headword, articleText;
|
|
|
|
|
|
|
|
QVector< int > pg, off;
|
|
|
|
{
|
|
|
|
Mutex::Lock _( dict.eBook.getLibMutex() );
|
|
|
|
dict.eBook.getArticlePos( gd::toQString( word_ ), pg, off );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int i = 0; i < pg.size(); i++ )
|
|
|
|
{
|
|
|
|
bool already = false;
|
|
|
|
for( int n = 0; n < pages.size(); n++ )
|
|
|
|
{
|
|
|
|
if( pages.at( n ) == pg.at( i ) && abs( offsets.at( n ) - off.at( i ) ) <= 4 )
|
|
|
|
{
|
|
|
|
already = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !already )
|
|
|
|
{
|
|
|
|
dict.loadArticle( pg.at( i ), off.at( i ), headword, articleText );
|
|
|
|
|
|
|
|
mainArticles.insert(
|
|
|
|
pair< wstring, pair< string, string > >( Folding::applySimpleCaseOnly( Utf8::decode( headword ) ),
|
|
|
|
pair< string, string >( headword, articleText ) ) );
|
|
|
|
|
|
|
|
pages.append( pg.at( i ) );
|
|
|
|
offsets.append( off.at( i ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-07 14:20:54 +00:00
|
|
|
void EpwingDictionary::getHeadwordPos( wstring const & word_, QVector< int > & pg, QVector< int > & off )
|
|
|
|
{
|
|
|
|
try {
|
2023-04-08 04:13:41 +00:00
|
|
|
Mutex::Lock _( eBook.getLibMutex() );
|
|
|
|
eBook.getArticlePos( gd::toQString( word_ ), pg, off );
|
2023-04-07 14:20:54 +00:00
|
|
|
}
|
|
|
|
catch ( ... ) {
|
2023-04-08 03:50:45 +00:00
|
|
|
//ignore
|
2023-04-07 14:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
sptr< Dictionary::DataRequest > EpwingDictionary::getArticle( wstring const & word,
|
|
|
|
vector< wstring > const & alts,
|
2018-06-13 16:00:42 +00:00
|
|
|
wstring const &,
|
|
|
|
bool ignoreDiacritics )
|
2022-01-09 08:35:07 +00:00
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
2022-11-29 03:54:31 +00:00
|
|
|
return std::make_shared<EpwingArticleRequest>( word, alts, *this, ignoreDiacritics );
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//// EpwingDictionary::getResource()
|
|
|
|
|
|
|
|
class EpwingResourceRequest: public Dictionary::DataRequest
|
|
|
|
{
|
|
|
|
EpwingDictionary & dict;
|
|
|
|
|
|
|
|
string resourceName;
|
|
|
|
|
|
|
|
QAtomicInt isCancelled;
|
2023-04-08 04:13:41 +00:00
|
|
|
QFuture< void > f;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2023-04-08 04:13:41 +00:00
|
|
|
EpwingResourceRequest( EpwingDictionary & dict_, string const & resourceName_ ):
|
2014-05-20 13:59:56 +00:00
|
|
|
dict( dict_ ),
|
|
|
|
resourceName( resourceName_ )
|
|
|
|
{
|
2023-04-08 04:13:41 +00:00
|
|
|
f = QtConcurrent::run( [ this ]() {
|
|
|
|
this->run();
|
|
|
|
} );
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void run(); // Run from another thread by EpwingResourceRequestRunnable
|
|
|
|
|
2023-04-08 04:13:41 +00:00
|
|
|
void cancel() override { isCancelled.ref(); }
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
~EpwingResourceRequest()
|
|
|
|
{
|
|
|
|
isCancelled.ref();
|
2023-04-08 04:13:41 +00:00
|
|
|
f.waitForFinished();
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void EpwingResourceRequest::run()
|
|
|
|
{
|
|
|
|
// Some runnables linger enough that they are cancelled before they start
|
2021-11-27 07:17:33 +00:00
|
|
|
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString cacheDir;
|
|
|
|
{
|
|
|
|
Mutex::Lock _( dict.eBook.getLibMutex() );
|
|
|
|
if( Filetype::isNameOfPicture( resourceName ) )
|
|
|
|
cacheDir = dict.getImagesCacheDir();
|
|
|
|
else
|
|
|
|
if( Filetype::isNameOfSound( resourceName ) )
|
|
|
|
cacheDir = dict.getSoundsCacheDir();
|
|
|
|
else
|
|
|
|
if( Filetype::isNameOfVideo( resourceName ) )
|
|
|
|
cacheDir = dict.getMoviesCacheDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( cacheDir.isEmpty() )
|
|
|
|
{
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-13 10:08:32 +00:00
|
|
|
QString fullName = cacheDir + QDir::separator() + QString::fromStdString( resourceName );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
QFile f( fullName );
|
|
|
|
if( f.open( QFile::ReadOnly ) )
|
|
|
|
{
|
|
|
|
QByteArray buffer = f.readAll();
|
|
|
|
|
|
|
|
Mutex::Lock _( dataMutex );
|
|
|
|
|
|
|
|
data.resize( buffer.size() );
|
|
|
|
|
|
|
|
memcpy( &data.front(), buffer.data(), data.size() );
|
|
|
|
|
|
|
|
hasAnyData = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( std::exception &ex )
|
|
|
|
{
|
|
|
|
gdWarning( "Epwing: Failed loading resource \"%s\" for \"%s\", reason: %s\n",
|
|
|
|
resourceName.c_str(), dict.getName().c_str(), ex.what() );
|
|
|
|
// Resource not loaded -- we don't set the hasAnyData flag then
|
|
|
|
}
|
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
sptr< Dictionary::DataRequest > EpwingDictionary::getResource( string const & name )
|
2022-01-09 08:35:07 +00:00
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
2022-11-29 03:54:31 +00:00
|
|
|
return std::make_shared<EpwingResourceRequest>( *this, name );
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sptr< Dictionary::DataRequest > EpwingDictionary::getSearchResults( QString const & searchString,
|
|
|
|
int searchMode, bool matchCase,
|
|
|
|
int distanceBetweenWords,
|
2017-07-25 15:28:29 +00:00
|
|
|
int maxResults,
|
2018-04-10 14:49:52 +00:00
|
|
|
bool ignoreWordsOrder,
|
|
|
|
bool ignoreDiacritics )
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
2022-11-29 03:54:31 +00:00
|
|
|
return std::make_shared<FtsHelpers::FTSResultsRequest>( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics );
|
2014-05-20 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 14:56:24 +00:00
|
|
|
int EpwingDictionary::japaneseWriting( gd::wchar ch )
|
|
|
|
{
|
|
|
|
if( ( ch >= 0x30A0 && ch <= 0x30FF )
|
|
|
|
|| ( ch >= 0x31F0 && ch <= 0x31FF )
|
|
|
|
|| ( ch >= 0x3200 && ch <= 0x32FF )
|
|
|
|
|| ( ch >= 0xFF00 && ch <= 0xFFEF )
|
|
|
|
|| ( ch == 0x1B000 ) )
|
|
|
|
return 1; // Katakana
|
|
|
|
else
|
|
|
|
if( ( ch >= 0x3040 && ch <= 0x309F )
|
|
|
|
|| ( ch == 0x1B001 ) )
|
|
|
|
return 2; // Hiragana
|
|
|
|
else
|
|
|
|
if( ( ch >= 0x4E00 && ch <= 0x9FAF )
|
|
|
|
|| ( ch >= 0x3400 && ch <= 0x4DBF ) )
|
|
|
|
return 3; // Kanji
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EpwingDictionary::isSign( gd::wchar ch )
|
|
|
|
{
|
|
|
|
switch( ch )
|
|
|
|
{
|
|
|
|
case 0x002B: // PLUS SIGN
|
|
|
|
case 0x003C: // LESS-THAN SIGN
|
|
|
|
case 0x003D: // EQUALS SIGN
|
|
|
|
case 0x003E: // GREATER-THAN SIGN
|
|
|
|
case 0x00AC: // NOT SIGN
|
|
|
|
case 0xFF0B: // FULLWIDTH PLUS SIGN
|
|
|
|
case 0xFF1C: // FULLWIDTH LESS-THAN SIGN
|
|
|
|
case 0xFF1D: // FULLWIDTH EQUALS SIGN
|
|
|
|
case 0xFF1E: // FULLWIDTH GREATER-THAN SIGN
|
|
|
|
case 0xFFE2: // FULLWIDTH NOT SIGN
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EpwingDictionary::isJapanesePunctiation( gd::wchar ch )
|
|
|
|
{
|
|
|
|
return ch >= 0x3000 && ch <= 0x303F;
|
|
|
|
}
|
|
|
|
|
2014-07-10 13:55:14 +00:00
|
|
|
class EpwingWordSearchRequest;
|
|
|
|
|
|
|
|
class EpwingWordSearchRunnable: public QRunnable
|
|
|
|
{
|
|
|
|
EpwingWordSearchRequest & r;
|
|
|
|
QSemaphore & hasExited;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
EpwingWordSearchRunnable( EpwingWordSearchRequest & r_,
|
|
|
|
QSemaphore & hasExited_ ): r( r_ ),
|
|
|
|
hasExited( hasExited_ )
|
|
|
|
{}
|
|
|
|
|
|
|
|
~EpwingWordSearchRunnable()
|
|
|
|
{
|
|
|
|
hasExited.release();
|
|
|
|
}
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
void run() override;
|
2014-07-10 13:55:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class EpwingWordSearchRequest: public BtreeIndexing::BtreeWordSearchRequest
|
|
|
|
{
|
|
|
|
friend class EpwingWordSearchRunnable;
|
|
|
|
|
|
|
|
EpwingDictionary & edict;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
EpwingWordSearchRequest( EpwingDictionary & dict_,
|
|
|
|
wstring const & str_,
|
|
|
|
unsigned minLength_,
|
|
|
|
int maxSuffixVariation_,
|
|
|
|
bool allowMiddleMatches_,
|
|
|
|
unsigned long maxResults_ ):
|
|
|
|
BtreeWordSearchRequest( dict_, str_, minLength_, maxSuffixVariation_, allowMiddleMatches_, maxResults_, false ),
|
|
|
|
edict( dict_ )
|
|
|
|
{
|
|
|
|
QThreadPool::globalInstance()->start(
|
|
|
|
new EpwingWordSearchRunnable( *this, hasExited ) );
|
|
|
|
}
|
|
|
|
|
2022-12-29 07:07:40 +00:00
|
|
|
void findMatches() override;
|
2014-07-10 13:55:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void EpwingWordSearchRunnable::run()
|
|
|
|
{
|
|
|
|
r.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EpwingWordSearchRequest::findMatches()
|
|
|
|
{
|
|
|
|
BtreeWordSearchRequest::findMatches();
|
2021-11-27 07:17:33 +00:00
|
|
|
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
|
2014-07-10 13:55:14 +00:00
|
|
|
{
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while( matches.size() < maxResults )
|
|
|
|
{
|
|
|
|
QVector< QString > headwords;
|
|
|
|
{
|
|
|
|
Mutex::Lock _( edict.eBook.getLibMutex() );
|
2021-11-27 07:17:33 +00:00
|
|
|
if( Utils::AtomicInt::loadAcquire( isCancelled ) )
|
2014-07-10 13:55:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if( !edict.eBook.getMatches( gd::toQString( str ), headwords ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mutex::Lock _( dataMutex );
|
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
for ( const auto & headword : headwords )
|
|
|
|
addMatch( gd::toWString( headword ) );
|
2014-07-10 13:55:14 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
sptr< Dictionary::WordSearchRequest > EpwingDictionary::prefixMatch(
|
|
|
|
wstring const & str, unsigned long maxResults )
|
2022-01-09 08:35:07 +00:00
|
|
|
|
2014-07-10 13:55:14 +00:00
|
|
|
{
|
2022-11-29 03:54:31 +00:00
|
|
|
return std::make_shared<EpwingWordSearchRequest>( *this, str, 0, -1, true, maxResults );
|
2014-07-10 13:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sptr< Dictionary::WordSearchRequest > EpwingDictionary::stemmedMatch(
|
|
|
|
wstring const & str, unsigned minLength, unsigned maxSuffixVariation,
|
|
|
|
unsigned long maxResults )
|
2022-01-09 08:35:07 +00:00
|
|
|
|
2014-07-10 13:55:14 +00:00
|
|
|
{
|
2022-11-29 03:54:31 +00:00
|
|
|
return std::make_shared<EpwingWordSearchRequest>( *this, str, minLength, (int)maxSuffixVariation,
|
2014-07-10 13:55:14 +00:00
|
|
|
false, maxResults );
|
|
|
|
}
|
2023-04-08 03:50:45 +00:00
|
|
|
bool Epwing::EpwingDictionary::readHeadword( const EB_Position & pos, QString & headword )
|
2023-03-22 14:52:49 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Mutex::Lock _( eBook.getLibMutex() );
|
|
|
|
eBook.readHeadword( pos,headword, true);
|
|
|
|
eBook.fixHeadword( headword );
|
|
|
|
return eBook.isHeadwordCorrect( headword ) ;
|
|
|
|
}
|
2023-04-08 03:50:45 +00:00
|
|
|
catch( std::exception & )
|
2023-03-22 14:52:49 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-07-10 13:55:14 +00:00
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2022-10-04 07:07:04 +00:00
|
|
|
void addWordToChunks( Epwing::Book::EpwingHeadword & head,
|
|
|
|
ChunkedStorage::Writer & chunks,
|
|
|
|
BtreeIndexing::IndexedWords & indexedWords,
|
|
|
|
int & wordCount,
|
|
|
|
int & articleCount )
|
|
|
|
{
|
|
|
|
if( !head.headword.isEmpty() )
|
|
|
|
{
|
|
|
|
uint32_t offset = chunks.startNewBlock();
|
|
|
|
chunks.addToBlock( &head.page, sizeof( head.page ) );
|
|
|
|
chunks.addToBlock( &head.offset, sizeof( head.offset ) );
|
|
|
|
|
|
|
|
wstring hw = gd::toWString( head.headword );
|
|
|
|
|
|
|
|
indexedWords.addWord( hw, offset );
|
|
|
|
wordCount++;
|
|
|
|
articleCount++;
|
|
|
|
|
|
|
|
vector< wstring > words;
|
|
|
|
|
|
|
|
// Parse combined kanji/katakana/hiragana headwords
|
|
|
|
|
|
|
|
int w_prev = 0;
|
|
|
|
wstring word;
|
|
|
|
for( wstring::size_type n = 0; n < hw.size(); n++ )
|
|
|
|
{
|
|
|
|
gd::wchar ch = hw[ n ];
|
|
|
|
|
|
|
|
if( Folding::isPunct( ch ) || Folding::isWhitespace( ch ) || EpwingDictionary::isSign( ch )
|
|
|
|
|| EpwingDictionary::isJapanesePunctiation( ch ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int w = EpwingDictionary::japaneseWriting( ch );
|
|
|
|
|
|
|
|
if( w > 0 )
|
|
|
|
{
|
|
|
|
// Store only separated words
|
|
|
|
gd::wchar ch_prev = 0;
|
|
|
|
if( n )
|
|
|
|
ch_prev = hw[ n - 1 ];
|
|
|
|
bool needStore = ( n == 0 || Folding::isPunct( ch_prev ) || Folding::isWhitespace( ch_prev )
|
|
|
|
|| EpwingDictionary::isJapanesePunctiation( ch ) );
|
|
|
|
|
|
|
|
word.push_back( ch );
|
|
|
|
w_prev = w;
|
|
|
|
wstring::size_type i;
|
|
|
|
for( i = n + 1; i < hw.size(); i++ )
|
|
|
|
{
|
|
|
|
ch = hw[ i ];
|
|
|
|
if( Folding::isPunct( ch ) || Folding::isWhitespace( ch ) || EpwingDictionary::isJapanesePunctiation( ch ) )
|
|
|
|
break;
|
|
|
|
w = EpwingDictionary::japaneseWriting( ch );
|
|
|
|
if( w != w_prev )
|
|
|
|
break;
|
|
|
|
word.push_back( ch );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( needStore )
|
|
|
|
{
|
|
|
|
if( i >= hw.size() || Folding::isPunct( ch ) || Folding::isWhitespace( ch )
|
|
|
|
|| EpwingDictionary::isJapanesePunctiation( ch ) )
|
|
|
|
words.push_back( word );
|
|
|
|
}
|
|
|
|
word.clear();
|
|
|
|
|
|
|
|
if( i < hw.size() )
|
|
|
|
n = i;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( words.size() > 1 )
|
|
|
|
{
|
|
|
|
// Allow only one word in every charset
|
|
|
|
|
|
|
|
size_t n;
|
|
|
|
int writings[ 4 ];
|
|
|
|
memset( writings, 0, sizeof( writings ) );
|
|
|
|
|
|
|
|
for( n = 0; n < words.size(); n++ )
|
|
|
|
{
|
|
|
|
int w = EpwingDictionary::japaneseWriting( words[ n ][ 0 ] );
|
|
|
|
if( writings[ w ] )
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
writings[ w ] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( n >= words.size() )
|
|
|
|
{
|
|
|
|
for( n = 0; n < words.size(); n++ )
|
|
|
|
{
|
|
|
|
indexedWords.addWord( words[ n ], offset );
|
|
|
|
wordCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
vector< sptr< Dictionary::Class > > makeDictionaries(
|
|
|
|
vector< string > const & fileNames,
|
|
|
|
string const & indicesDir,
|
|
|
|
Dictionary::Initializing & initializing )
|
2022-01-09 08:35:07 +00:00
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
{
|
|
|
|
vector< sptr< Dictionary::Class > > dictionaries;
|
|
|
|
|
|
|
|
vector< string > dictFiles;
|
2022-01-08 13:16:22 +00:00
|
|
|
QByteArray catName = QString("%1catalogs").arg(QDir::separator()).toUtf8();
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
for ( const auto & fileName : fileNames ) {
|
2014-05-20 13:59:56 +00:00
|
|
|
// Skip files other than "catalogs" to speed up the scanning
|
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
if ( fileName.size() < (unsigned)catName.size() ||
|
|
|
|
strcasecmp( fileName.c_str() + ( fileName.size() - catName.size() ), catName.data() ) != 0 )
|
2014-05-20 13:59:56 +00:00
|
|
|
continue;
|
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
int ndir = fileName.size() - catName.size();
|
2014-05-20 13:59:56 +00:00
|
|
|
if( ndir < 1 )
|
|
|
|
ndir = 1;
|
|
|
|
|
2023-04-08 03:50:45 +00:00
|
|
|
string mainDirectory = fileName.substr( 0, ndir );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
Epwing::Book::EpwingBook dict;
|
2016-06-30 14:40:20 +00:00
|
|
|
int subBooksNumber = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
subBooksNumber = dict.setBook( mainDirectory );
|
|
|
|
}
|
|
|
|
catch( std::exception & e )
|
|
|
|
{
|
|
|
|
gdWarning( "Epwing dictionary initializing failed: %s, error: %s\n",
|
|
|
|
mainDirectory.c_str(), e.what() );
|
|
|
|
continue;
|
|
|
|
}
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
for( int sb = 0; sb < subBooksNumber; sb++ )
|
|
|
|
{
|
|
|
|
QString dir;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
dictFiles.clear();
|
|
|
|
dictFiles.push_back( mainDirectory );
|
2023-04-08 03:50:45 +00:00
|
|
|
dictFiles.push_back( fileName );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
dict.setSubBook( sb );
|
|
|
|
|
2023-04-13 10:08:32 +00:00
|
|
|
dir = QString::fromStdString( mainDirectory ) + FsEncoding::separator() + dict.getCurrentSubBookDirectory();
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
Epwing::Book::EpwingBook::collectFilenames( dir, dictFiles );
|
|
|
|
|
2023-04-13 10:08:32 +00:00
|
|
|
QString fontSubName =
|
|
|
|
QString::fromStdString( mainDirectory ) + QDir::separator() + "afonts_" + QString::number( sb );
|
2014-05-22 16:53:06 +00:00
|
|
|
QFileInfo info( fontSubName );
|
|
|
|
if( info.exists() && info.isFile() )
|
2023-04-13 10:08:32 +00:00
|
|
|
dictFiles.push_back( fontSubName.toStdString() );
|
2014-05-22 16:53:06 +00:00
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
// Check if we need to rebuid the index
|
|
|
|
|
|
|
|
string dictId = Dictionary::makeDictionaryId( dictFiles );
|
|
|
|
|
|
|
|
string indexFile = indicesDir + dictId;
|
|
|
|
|
|
|
|
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) ||
|
|
|
|
indexIsOldOrBad( indexFile ) )
|
|
|
|
{
|
|
|
|
gdDebug( "Epwing: Building the index for dictionary in directory %s\n", dir.toUtf8().data() );
|
|
|
|
|
|
|
|
QString str = dict.title();
|
|
|
|
QByteArray nameData = str.toUtf8();
|
|
|
|
initializing.indexingDictionary( nameData.data() );
|
|
|
|
|
|
|
|
File::Class idx( indexFile, "wb" );
|
|
|
|
|
|
|
|
IdxHeader idxHeader;
|
|
|
|
|
|
|
|
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
|
|
|
|
|
|
|
// We write a dummy header first. At the end of the process the header
|
|
|
|
// will be rewritten with the right values.
|
|
|
|
|
|
|
|
idx.write( idxHeader );
|
|
|
|
|
|
|
|
idx.write( nameData.data(), nameData.size() );
|
|
|
|
idxHeader.nameSize = nameData.size();
|
|
|
|
|
|
|
|
IndexedWords indexedWords;
|
|
|
|
|
|
|
|
ChunkedStorage::Writer chunks( idx );
|
|
|
|
|
|
|
|
Epwing::Book::EpwingHeadword head;
|
|
|
|
|
|
|
|
dict.getFirstHeadword( head );
|
|
|
|
|
|
|
|
int wordCount = 0;
|
2014-07-08 14:56:24 +00:00
|
|
|
int articleCount = 0;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
for( ; ; )
|
|
|
|
{
|
2022-10-04 07:07:04 +00:00
|
|
|
addWordToChunks( head, chunks, indexedWords, wordCount, articleCount );
|
2014-05-20 13:59:56 +00:00
|
|
|
if( !dict.getNextHeadword( head ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-05-21 19:10:24 +00:00
|
|
|
dict.clearBuffers();
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
// Finish with the chunks
|
|
|
|
|
|
|
|
idxHeader.chunksOffset = chunks.finish();
|
|
|
|
|
|
|
|
// Build index
|
|
|
|
|
|
|
|
IndexInfo idxInfo = BtreeIndexing::buildIndex( indexedWords, idx );
|
|
|
|
|
|
|
|
idxHeader.indexBtreeMaxElements = idxInfo.btreeMaxElements;
|
|
|
|
idxHeader.indexRootOffset = idxInfo.rootOffset;
|
|
|
|
|
|
|
|
indexedWords.clear(); // Release memory -- no need for this data
|
|
|
|
|
|
|
|
// That concludes it. Update the header.
|
|
|
|
|
|
|
|
idxHeader.signature = Signature;
|
|
|
|
idxHeader.formatVersion = CurrentFormatVersion;
|
|
|
|
|
|
|
|
idxHeader.wordCount = wordCount;
|
2014-07-08 14:56:24 +00:00
|
|
|
idxHeader.articleCount = articleCount;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
idx.rewind();
|
|
|
|
|
|
|
|
idx.write( &idxHeader, sizeof( idxHeader ) );
|
|
|
|
|
|
|
|
|
|
|
|
} // If need to rebuild
|
|
|
|
|
2022-11-29 03:54:31 +00:00
|
|
|
dictionaries.push_back( std::make_shared<EpwingDictionary>( dictId,
|
2014-05-20 13:59:56 +00:00
|
|
|
indexFile,
|
|
|
|
dictFiles,
|
|
|
|
sb ) );
|
|
|
|
}
|
|
|
|
catch( std::exception & e )
|
|
|
|
{
|
|
|
|
gdWarning( "Epwing dictionary initializing failed: %s, error: %s\n",
|
|
|
|
dir.toUtf8().data(), e.what() );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return dictionaries;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Epwing
|