16#include <QReadWriteLock>
17#include <QWriteLocker>
30namespace LinguisticProcessing
47 std::shared_ptr<Lima::Common::AbstractAccessByString> access,
48 const std::string& dataFile);
52 std::shared_ptr<Lima::Common::AbstractAccessByString> m_access;
57 QReadWriteLock m_lock;
60EnhancedAnalysisDictionaryPrivate::EnhancedAnalysisDictionaryPrivate() :
67EnhancedAnalysisDictionaryPrivate::EnhancedAnalysisDictionaryPrivate(
69 std::shared_ptr<Lima::Common::AbstractAccessByString> access,
70 const std::string& dataFile) :
72 m_dicoData(new DictionaryData()),
75 QWriteLocker locker(&m_lock);
80EnhancedAnalysisDictionaryPrivate::~EnhancedAnalysisDictionaryPrivate()
92 if (!connect(
this,SIGNAL(
resourceFileChanged(QString)),
this,SLOT(dictionaryFileChanged(QString))))
97 if (!dataFilePath.isEmpty())
100 QWriteLocker locker(&m_d->m_lock);
101 m_d->m_dicoData->
loadBinaryFile(dataFilePath.toUtf8().constData());
107 std::shared_ptr<Lima::Common::AbstractAccessByString> access,
108 const std::string& dataFile) :
113 if (!connect(
this,SIGNAL(
resourceFileChanged(QString)),
this,SLOT(dictionaryFileChanged(QString))))
118 QWriteLocker locker(&m_d->m_lock);
133 LDEBUG <<
"EnhancedAnalysisDictionary::init";
134 MediaId language=manager->getInitializationParameters().language;
140 auto aar = std::dynamic_pointer_cast<AbstractAccessResource>(res);
141 if (!connect(aar.get(), SIGNAL(accessFileReloaded(std::shared_ptr<Common::AbstractAccessByString>)),
142 this, SLOT(slotAccessFileReloaded(std::shared_ptr<Common::AbstractAccessByString>))))
146 m_d->m_isMainKeys=aar->isMainKeys();
147 m_d->m_access=aar->getAccessByString();
151 LERROR <<
"no param 'accessKeys' in EnhancedAnalysisDictionary group for language " << (int) language;
159 QWriteLocker locker(&m_d->m_lock);
160 m_d->m_dicoData->
loadBinaryFile(binaryFilePath.toUtf8().constData());
164 LERROR <<
"no list 'dictionaryValues' in EnhancedAnalysisDictionary group for language " << (int) language;
171void EnhancedAnalysisDictionary::slotAccessFileReloaded(std::shared_ptr<Common::AbstractAccessByString> access)
174 LDEBUG <<
"EnhancedAnalysisDictionary::slotAccessFileReloaded";
175 m_d->m_access = access;
178void EnhancedAnalysisDictionary::dictionaryFileChanged (
const QString & path )
184 if (QFileInfo::exists(path))
186 LINFO <<
"EnhancedAnalysisDictionary::dictionaryFileChanged reload" << path;
187 QWriteLocker locker(&m_d->m_lock);
188 if (m_d->m_dicoData != 0)
189 delete m_d->m_dicoData;
190 m_d->m_dicoData =
new DictionaryData();
195 LINFO <<
"EnhancedAnalysisDictionary::dictionaryFileChanged deleted, ignoring" << path;
202 return m_d->m_dicoData->
getSize();
208 return getEntryData(
static_cast<StringsPoolIndex
>(m_d->m_access->getIndex(word)));
213 return getEntryData(
static_cast<StringsPoolIndex
>(m_d->m_access->getIndex(word)) );
219 return getEntryData(
static_cast<StringsPoolIndex
>(m_d->m_access->getIndex((*m_d->m_sp)[wordId])) );
228 if (wordId >= m_d->m_dicoData->
getSize())
232 std::make_shared<EnhancedAnalysisDictionaryEntry>(
233 static_cast<StringsPoolIndex
>(0),
false,
true,
false,
false,
false,
nullptr,
nullptr, m_d->m_dicoData,
234 m_d->m_isMainKeys, m_d->m_access, m_d->m_sp));
237 StringsPoolIndex strId=wordId;
238 if (!m_d->m_isMainKeys) {
239 strId = (*m_d->m_sp)[m_d->m_access->getSpelling(wordId)];
253 return DictionaryEntry(std::make_shared<EnhancedAnalysisDictionaryEntry>(strId,
final,
true,
false,
false,
false,p,p,m_d->m_dicoData,m_d->m_isMainKeys,m_d->m_access,m_d->m_sp));
255 unsigned char* start=p;
256 unsigned char* end=p+read;
258 bool hasAccented=
false;
259 bool hasConcat=
false;
268 hasAccented=(read != 0);
274 hasConcat=(read != 0);
280 return DictionaryEntry(std::make_shared<EnhancedAnalysisDictionaryEntry>(strId,
final,
false,hasLing,hasConcat,hasAccented,start,end,m_d->m_dicoData,m_d->m_isMainKeys,m_d->m_access,m_d->m_sp));
285 std::pair<AccessSubWordIterator,AccessSubWordIterator> accessItrs=
286 m_d->m_access->getSubWords(offset,key);
287 return std::pair< DictionarySubWordIterator, DictionarySubWordIterator >(
295 std::pair<AccessSuperWordIterator,AccessSuperWordIterator> accessItrs=
296 m_d->m_access->getSuperWords(key);
297 return std::pair< DictionarySuperWordIterator, DictionarySuperWordIterator >(
#define ENHANCEDANALYSISDICTIONARY_CLASSID
#define LIMA_EXCEPTION(X)
This macro writes the message X to a previously configured error stream before throwing a LimaExcepti...
#define ANALYSISDICTLOGINIT
Defines a Factory to create Object of type Base.
std::string & getParamsValueAtKey(const std::string &key)
return a message when a 'list' was not found
return a message when a 'param' was not found
Use this exception to signal an error in one of the configuration files.
void addPath(const QString &path)
LimaFileSystemWatcher & resourceFileWatcher()
Accessor to the file watcher used to register resource files to be watched for changes.
void resourceFileChanged(const QString &path)
Signal triggered whenever one of the registered files changes on disk.
interface for analysis dictionary
static uint64_t readCodedInt(unsigned char *&p)
void loadBinaryFile(const std::string &file)
unsigned char * getEntryAddr(uint64_t index) const
EnhancedAnalysisDictionary(const QString &dataFilePath=QString())
virtual DictionaryEntry getEntry(const Lima::LimaString &word) const override
get dictionary entry for a word
virtual std::pair< DictionarySubWordIterator, DictionarySubWordIterator > getSubWordEntries(const int offset, const LimaString &key) const override
Returns subwords entries.
virtual std::pair< DictionarySuperWordIterator, DictionarySuperWordIterator > getSuperWordEntries(const LimaString &key) const override
return superword entries A superword entry is an entry that begins with the given key
virtual uint64_t getSize() const override
return number of keys in dictionary
DictionaryEntry getEntryData(const StringsPoolIndex entryId) const
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
virtual ~EnhancedAnalysisDictionary()
static const LinguisticResources & single()
const singleton accessor
static MediaticData & changeable()
singleton accessor
QString findFileInPaths(const QString &paths, const QString &fileName, const QChar &separator)
Find the given file in the given paths.
SimpleFactory< AbstractResource, EnhancedAnalysisDictionary > enhancedAnalysisDictionaryFactory(ENHANCEDANALYSISDICTIONARY_CLASSID)
launch exception related to the configuration file parsing