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 <glib.h>
#include "chinesecharacterstopinyin.h"
#include "file-utils.h"
AppMatch::AppMatch(QObject *parent) : QObject(parent)
{
this->getDesktopFilePath();
@ -8,7 +8,7 @@ AppMatch::AppMatch(QObject *parent) : QObject(parent)
QStringList AppMatch::startMatchApp(QString input){
input.replace(" ","");
m_soureText=input;
m_sourceText=input;
m_returnResult.clear();
if(input.isEmpty()){
return m_returnResult;
@ -19,6 +19,10 @@ QStringList AppMatch::startMatchApp(QString input){
return m_returnResult;
}
/**
* @brief AppMatch::getAllDesktopFilePath desktop文件
* @param path desktop文件夹
*/
void AppMatch::getAllDesktopFilePath(QString path){
GKeyFileFlags flags=G_KEY_FILE_NONE;
@ -110,10 +114,13 @@ void AppMatch::getAllDesktopFilePath(QString path){
i++;
} while(i < list.size());
g_key_file_free(keyfile);
}
/**
* @brief AppMatch::getDesktopFilePath
*
*/
void AppMatch::getDesktopFilePath()
{
m_filePathList.clear();
@ -164,6 +171,10 @@ void AppMatch::getDesktopFilePath()
m_filePathList.removeAll("/usr/share/applications/wps-office-misc.desktop");
}
/**
* @brief AppMatch::getAppName
*
*/
void AppMatch::getAppName()
{
GKeyFileFlags flags=G_KEY_FILE_NONE;
@ -188,13 +199,26 @@ void AppMatch::getAppName()
g_key_file_free(keyfile);
}
/**
* @brief AppMatch::appNameMatch
*
* @param appname
*
* @param desktoppath
* desktop路径
*/
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);
}
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);
private:
QString m_soureText;
QString m_sourceText;
QStringList m_filePathList;
QStringList m_returnResult;
QStringList m_midResult;

View File

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

View File

@ -1,10 +1,17 @@
#include "setting-match.h"
#include "file-utils.h"
SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent)
{
xmlElement();
}
/**
* @brief SettingsMatch::startMatchApp
*
* @param source
*
* @return
*/
QStringList SettingsMatch::startMatchApp(const QString &source){
m_sourceText=source;
// qDebug()<<m_sourceText;
@ -12,6 +19,10 @@ QStringList SettingsMatch::startMatchApp(const QString &source){
return settingList;
}
/**
* @brief SettingsMatch::xmlElement
* xml文件内容读到内存
*/
void SettingsMatch::xmlElement(){
QString pinyinIndex;
QString ChineseIndex;
@ -39,7 +50,7 @@ void SettingsMatch::xmlElement(){
pinyinIndex=n.toElement().text();
}
if(n.nodeName()==QString::fromLocal8Bit("pinyinfunc")){
pinyinIndex+=QString::fromLocal8Bit(":")+n.toElement().text();
pinyinIndex+=QString::fromLocal8Bit("/")+n.toElement().text();
m_pinyin_searchResult.append(pinyinIndex);
}
@ -62,6 +73,11 @@ void SettingsMatch::xmlElement(){
// qDebug()<<chine_searchlist;
}
/**
* @brief SettingsMatch::matching
*
* @return
*/
QStringList SettingsMatch::matching(){
QStringList returnresult;
QStringList regmatch;
@ -79,6 +95,16 @@ QStringList SettingsMatch::matching(){
str=key+"/"+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;