From d00118331bbc14f2c6da5193d7d6226f4f96b7eb Mon Sep 17 00:00:00 2001 From: zhangzihao Date: Tue, 29 Dec 2020 16:41:30 +0800 Subject: [PATCH] :zap::zap::zap: add multitone words file name search --- file-utils.cpp | 27 +++++++++++++++++++++++++++ file-utils.h | 1 + index/index-generator.cpp | 20 +++++++++++++++++--- index/test-Inotify-Manager.cpp | 12 ++++++------ src/mainwindow.cpp | 21 ++++++++++----------- 5 files changed, 61 insertions(+), 20 deletions(-) diff --git a/file-utils.cpp b/file-utils.cpp index 5a8aa5e..4d52388 100644 --- a/file-utils.cpp +++ b/file-utils.cpp @@ -184,3 +184,30 @@ QString FileUtils::find(const QString &hanzi) return output; } + +void stitchMultiToneWordsDFS(const QString& hanzi, const QString& result, QStringList& resultList){ + if (hanzi.size() == 0){ + resultList.append(result); + return; + } + if (FileUtils::map_chinese2pinyin.contains(hanzi.at(0))){ + for (auto i : FileUtils::map_chinese2pinyin[hanzi.at(0)]){ + stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), result + i, resultList); + } + } + else{ + stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), result + hanzi.at(0), resultList); + } +} + +QStringList FileUtils::findMultiToneWords(const QString& hanzi) +{ +// QStringList* output = new QStringList(); + QStringList output; + QString temp; + QStringList stringList = hanzi.split(""); + + stitchMultiToneWordsDFS(hanzi, temp, output); +// qDebug() << output; + return output; +} diff --git a/file-utils.h b/file-utils.h index 8b37500..af7fe8e 100644 --- a/file-utils.h +++ b/file-utils.h @@ -26,6 +26,7 @@ public: //chinese character to pinyin static QString find(const QString&); + static QStringList findMultiToneWords(const QString&); static void loadHanziTable(const QString&); private: diff --git a/index/index-generator.cpp b/index/index-generator.cpp index d30fea9..e038490 100644 --- a/index/index-generator.cpp +++ b/index/index-generator.cpp @@ -117,8 +117,18 @@ Document IndexGenerator::GenerateDocument(const QVector &list) QString sourcePath = list.at(1); index_text = index_text.replace(".","").replace(""," "); index_text = index_text.simplified(); - QString pinyin_text = FileUtils::find(index_text.replace(".", "")).replace("", " "); - pinyin_text = pinyin_text.simplified(); + //这个应该是写错了 +// QString pinyin_text = FileUtils::find(index_text.replace(".", "")).replace("", " "); + + //不带多音字版 +// QString pinyin_text = FileUtils::find(QString(list.at(0)).replace(".","")).replace("", " ").simplified(); + + //多音字版 + QStringList pintin_text_list = FileUtils::findMultiToneWords(QString(list.at(0)).replace(".","")); + for (QString& i : pintin_text_list){ + i.replace("", " "); + } + QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(sourcePath)); // QString uniqueterm1 = QString::fromStdString(QCryptographicHash::hash(sourcePath.toUtf8(),QCryptographicHash::Md5).toStdString()); /*--------------------------------------------------------------------*/ @@ -136,7 +146,11 @@ Document IndexGenerator::GenerateDocument(const QVector &list) doc.addValue(list.at(2)); if(list.at(2) == QString("1")) qDebug()<<"value!!!"<getTargetFileAbsolutePath(); - - /*-------------InotyifyRefact Test Start---------------*/ -// QTime t1 = QTime::currentTime(); -// InotifyManagerRefact* imr = new InotifyManagerRefact("/home"); -// imr->start(); -// QTime t2 = QTime::currentTime(); -// qDebug() << t1; -// qDebug() << t2; - /*-------------InotyifyRefact Test End-----------------*/ +// FileUtils::findMultiToneWords("翟康宁test"); + /*-------------Inotify Test Start---------------*/ + QTime t1 = QTime::currentTime(); + InotifyManagerRefact* im = new InotifyManagerRefact("/home"); + im->Traverse(); + QTime t2 = QTime::currentTime(); + qDebug() << t1; + qDebug() << t2; + im->start(); + /*-------------Inotify Test End-----------------*/ this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); this->setAttribute(Qt::WA_TranslucentBackground, true);