Add Pinyin matching

This commit is contained in:
sunfengsheng 2020-12-30 05:41:00 -08:00
parent d33ea025a4
commit 554fb56bde
4 changed files with 68 additions and 12 deletions

View File

@ -1,6 +1,6 @@
#include "app-match.h" #include "app-match.h"
#include <glib.h> #include <glib.h>
#include "chinesecharacterstopinyin.h" #include "file-utils.h"
AppMatch::AppMatch(QObject *parent) : QObject(parent) AppMatch::AppMatch(QObject *parent) : QObject(parent)
{ {
this->getDesktopFilePath(); this->getDesktopFilePath();
@ -8,7 +8,7 @@ AppMatch::AppMatch(QObject *parent) : QObject(parent)
QStringList AppMatch::startMatchApp(QString input){ QStringList AppMatch::startMatchApp(QString input){
input.replace(" ",""); input.replace(" ","");
m_soureText=input; m_sourceText=input;
m_returnResult.clear(); m_returnResult.clear();
if(input.isEmpty()){ if(input.isEmpty()){
return m_returnResult; return m_returnResult;
@ -19,6 +19,10 @@ QStringList AppMatch::startMatchApp(QString input){
return m_returnResult; return m_returnResult;
} }
/**
* @brief AppMatch::getAllDesktopFilePath desktop文件
* @param path desktop文件夹
*/
void AppMatch::getAllDesktopFilePath(QString path){ void AppMatch::getAllDesktopFilePath(QString path){
GKeyFileFlags flags=G_KEY_FILE_NONE; GKeyFileFlags flags=G_KEY_FILE_NONE;
@ -110,10 +114,13 @@ void AppMatch::getAllDesktopFilePath(QString path){
i++; i++;
} while(i < list.size()); } while(i < list.size());
g_key_file_free(keyfile); g_key_file_free(keyfile);
} }
/**
* @brief AppMatch::getDesktopFilePath
*
*/
void AppMatch::getDesktopFilePath() void AppMatch::getDesktopFilePath()
{ {
m_filePathList.clear(); m_filePathList.clear();
@ -164,6 +171,10 @@ void AppMatch::getDesktopFilePath()
m_filePathList.removeAll("/usr/share/applications/wps-office-misc.desktop"); m_filePathList.removeAll("/usr/share/applications/wps-office-misc.desktop");
} }
/**
* @brief AppMatch::getAppName
*
*/
void AppMatch::getAppName() void AppMatch::getAppName()
{ {
GKeyFileFlags flags=G_KEY_FILE_NONE; GKeyFileFlags flags=G_KEY_FILE_NONE;
@ -188,13 +199,26 @@ void AppMatch::getAppName()
g_key_file_free(keyfile); g_key_file_free(keyfile);
} }
/**
* @brief AppMatch::appNameMatch
*
* @param appname
*
* @param desktoppath
* desktop路径
*/
void AppMatch::appNameMatch(QString appname,QString desktoppath){ void AppMatch::appNameMatch(QString appname,QString desktoppath){
if(appname.contains(m_soureText)){ if(appname.contains(m_sourceText)){
m_midResult.append(desktoppath);
return;
}
QString pinyin=FileUtils::findMultiToneWords(appname).at(0);// 中文转拼音
if(pinyin.contains(m_sourceText,Qt::CaseInsensitive)){
m_midResult.append(desktoppath);
return;
}
QString shouzimu=FileUtils::findMultiToneWords(appname).at(1);// 中文转首字母
if(shouzimu.contains(m_sourceText,Qt::CaseInsensitive)){
m_midResult.append(desktoppath); m_midResult.append(desktoppath);
} }
QString pinyin=chineseCharactersToPinyin::find(appname).toLower(); // 中文转拼音
if(pinyin.contains(m_soureText,Qt::CaseInsensitive)){
m_midResult.append(desktoppath);
}
} }

View File

@ -19,7 +19,7 @@ private:
void appNameMatch(QString appname,QString desktoppath); void appNameMatch(QString appname,QString desktoppath);
private: private:
QString m_soureText; QString m_sourceText;
QStringList m_filePathList; QStringList m_filePathList;
QStringList m_returnResult; QStringList m_returnResult;
QStringList m_midResult; QStringList m_midResult;

View File

@ -1 +1,7 @@
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/app-match.h \
SOURCES += \
$$PWD/app-match.cpp \

View File

@ -1,10 +1,17 @@
#include "setting-match.h" #include "setting-match.h"
#include "file-utils.h"
SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent) SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent)
{ {
xmlElement(); xmlElement();
} }
/**
* @brief SettingsMatch::startMatchApp
*
* @param source
*
* @return
*/
QStringList SettingsMatch::startMatchApp(const QString &source){ QStringList SettingsMatch::startMatchApp(const QString &source){
m_sourceText=source; m_sourceText=source;
// qDebug()<<m_sourceText; // qDebug()<<m_sourceText;
@ -12,6 +19,10 @@ QStringList SettingsMatch::startMatchApp(const QString &source){
return settingList; return settingList;
} }
/**
* @brief SettingsMatch::xmlElement
* xml文件内容读到内存
*/
void SettingsMatch::xmlElement(){ void SettingsMatch::xmlElement(){
QString pinyinIndex; QString pinyinIndex;
QString ChineseIndex; QString ChineseIndex;
@ -39,7 +50,7 @@ void SettingsMatch::xmlElement(){
pinyinIndex=n.toElement().text(); pinyinIndex=n.toElement().text();
} }
if(n.nodeName()==QString::fromLocal8Bit("pinyinfunc")){ if(n.nodeName()==QString::fromLocal8Bit("pinyinfunc")){
pinyinIndex+=QString::fromLocal8Bit(":")+n.toElement().text(); pinyinIndex+=QString::fromLocal8Bit("/")+n.toElement().text();
m_pinyin_searchResult.append(pinyinIndex); m_pinyin_searchResult.append(pinyinIndex);
} }
@ -62,6 +73,11 @@ void SettingsMatch::xmlElement(){
// qDebug()<<chine_searchlist; // qDebug()<<chine_searchlist;
} }
/**
* @brief SettingsMatch::matching
*
* @return
*/
QStringList SettingsMatch::matching(){ QStringList SettingsMatch::matching(){
QStringList returnresult; QStringList returnresult;
QStringList regmatch; QStringList regmatch;
@ -79,6 +95,16 @@ QStringList SettingsMatch::matching(){
str=key+"/"+str; str=key+"/"+str;
returnresult.append(str);//中文名 returnresult.append(str);//中文名
} }
QString pinyin=FileUtils::findMultiToneWords(str).at(0);// 中文转拼音
if(pinyin.contains(m_sourceText,Qt::CaseInsensitive)){
str=key+"/"+str;
returnresult.append(str);
}
QString shouzimu=FileUtils::findMultiToneWords(str).at(1);// 中文转首字母
if(shouzimu.contains(m_sourceText,Qt::CaseInsensitive)){
str=key+"/"+str;
returnresult.append(str);
}
} }
} }
// qDebug()<<returnresult; // qDebug()<<returnresult;