1274 lines
34 KiB
C++
1274 lines
34 KiB
C++
#include "ychildrenthread.h"
|
|
#include <QDebug>
|
|
#include "mecab.h"
|
|
#include <QLibrary>
|
|
#include <QDate>
|
|
|
|
YMorphereThread* ThreadFactory::getThread(QMap<QString, QString> mapParam)
|
|
{
|
|
if(mapParam.value("Algorithm").trimmed().compare("basic", Qt::CaseInsensitive) == 0)
|
|
{
|
|
return new YBasicMThread();
|
|
}
|
|
else if(mapParam.value("Algorithm").trimmed().compare("onedepth", Qt::CaseInsensitive) == 0)
|
|
{
|
|
return new YOneDepthMThread();
|
|
}
|
|
else if(mapParam.value("Algorithm").trimmed().compare("twodepth", Qt::CaseInsensitive) == 0)
|
|
{
|
|
return new YTwoDepthMThread();
|
|
}
|
|
else if(mapParam.value("Algorithm").trimmed().compare("platform", Qt::CaseInsensitive) == 0)
|
|
{
|
|
return new YPlatformMThread();
|
|
}
|
|
else if(mapParam.value("Algorithm").trimmed().compare("id", Qt::CaseInsensitive) == 0)
|
|
{
|
|
return new YIDMThread();
|
|
}
|
|
else if(mapParam.value("Algorithm").trimmed().compare("nxnmatrix", Qt::CaseInsensitive) == 0)
|
|
{
|
|
return new YNNMatrixMThread();
|
|
}
|
|
else
|
|
{
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
void YBasicMThread::run()
|
|
{
|
|
typedef mecab_t* (*mecab_new_fun)(int,char**);
|
|
typedef const char* (*mecab_sparse_tostr_fun)(mecab_t *mecab, const char *str);
|
|
typedef void (*mecab_destroy_fun)(mecab_t *mecab);
|
|
|
|
mecab_t *mecab;
|
|
mecab_new_fun mecab_new = (mecab_new_fun)QLibrary::resolve("libmecab.dll","mecab_new");
|
|
mecab_sparse_tostr_fun mecab_sparse_tostr = (mecab_sparse_tostr_fun)QLibrary::resolve("libmecab.dll","mecab_sparse_tostr");
|
|
|
|
parseParam();
|
|
|
|
if(userdict.length() < 1)
|
|
{
|
|
/*
|
|
char *t[] = {"RRR","-d","dic"};
|
|
int int_t = 3;
|
|
*/
|
|
|
|
char a[] = "RRR";
|
|
char b[] = "-d";
|
|
char c[] = "dic";
|
|
char *t[3];
|
|
t[0] = a;
|
|
t[1] = b;
|
|
t[2] = c;
|
|
int int_t = 3;
|
|
|
|
mecab = mecab_new(int_t, t);
|
|
}
|
|
else
|
|
{
|
|
char *cstr = new char[userdict.toStdString().length() + 1];
|
|
strcpy(cstr, userdict.toStdString().c_str());
|
|
/*
|
|
char **t = {"RRR","-d","dic","-u",cstr};
|
|
int int_t = 5;
|
|
*/
|
|
char a[] = "RRR";
|
|
char b[] = "-d";
|
|
char c[] = "dic";
|
|
char d[] = "-u";
|
|
|
|
char *t[5];
|
|
t[0] = a;
|
|
t[1] = b;
|
|
t[2] = c;
|
|
t[3] = d;
|
|
t[4] = cstr;
|
|
int int_t = 5;
|
|
|
|
mecab = mecab_new(int_t, t);
|
|
delete[] cstr;
|
|
}
|
|
mecab_destroy_fun mecab_destroy = (mecab_destroy_fun)QLibrary::resolve("libmecab.dll","mecab_destroy");
|
|
|
|
|
|
|
|
//qDebug() << num;
|
|
|
|
int nDate = 0;
|
|
while(true)
|
|
{
|
|
QString strTitle;
|
|
QString strBody;
|
|
QString strDate;
|
|
QString strData;
|
|
QString strPlatformTitle;
|
|
{
|
|
mutex->lock();
|
|
if(!m_pDAInterface->hasNext())
|
|
{
|
|
mutex->unlock();
|
|
break;
|
|
}
|
|
strTitle = m_pDAInterface->getArticleTitle();
|
|
strDate = m_pDAInterface->getArticleDate();
|
|
strPlatformTitle = m_pDAInterface->getPlatformTitle();
|
|
strBody = m_pDAInterface->getArticleData();
|
|
m_pDAInterface->next();
|
|
mutex->unlock();
|
|
}
|
|
|
|
{
|
|
switch(m_nTitleBody)
|
|
{
|
|
case 0:
|
|
{
|
|
strData = strTitle;
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
strData = strBody;
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
strData = strTitle + "\n" + strBody;
|
|
break;
|
|
}
|
|
case 3:
|
|
strData = strPlatformTitle;
|
|
break;
|
|
}
|
|
strTitle.clear();
|
|
strBody.clear();
|
|
strPlatformTitle.clear();
|
|
}
|
|
|
|
if(strDate.length() < 11)
|
|
continue;
|
|
|
|
strDate = strDate.left(11);
|
|
if(strDate.trimmed().length()<10)
|
|
{
|
|
nDate = 0;
|
|
}
|
|
else
|
|
{
|
|
strDate = strDate.replace("-","").trimmed();
|
|
if(strDate.length() < 8)
|
|
{
|
|
nDate = 0;
|
|
}
|
|
else
|
|
nDate = strDate.toInt();
|
|
}
|
|
|
|
if(!m_bDateAll)
|
|
{
|
|
if(nDate < m_nDateStart || m_nDateEnd < nDate)
|
|
continue;
|
|
}
|
|
|
|
QString m_strDate;
|
|
QString m_strKeyword;
|
|
QString m_strMorphere;
|
|
|
|
switch(m_nPeriod)
|
|
{
|
|
case 0:
|
|
{
|
|
m_strDate = "ALL";
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
m_strDate = "D" + QString::number(nDate);
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
/*
|
|
QDate tempdate = QDate(nDate/10000, (nDate%10000)/100, nDate%100);
|
|
mapkey.strDate = "W" + QString::number(nDate/10000);
|
|
if(tempdate.weekNumber() < 10)
|
|
mapkey.strDate += "0";
|
|
mapkey.strDate += QString::number(tempdate.weekNumber());
|
|
*/
|
|
m_strDate = getWeeksInMonth(nDate);
|
|
break;
|
|
}
|
|
case 3:
|
|
{
|
|
m_strDate = "M";
|
|
if((nDate/100) < 10)
|
|
m_strDate += "0";
|
|
m_strDate += QString::number(nDate/100);
|
|
break;
|
|
}
|
|
}
|
|
|
|
QString strAnalyzedLine = QString::fromStdString(mecab_sparse_tostr(mecab, strData.toStdString().c_str())) + "\n";
|
|
QStringList strListAll = strAnalyzedLine.split("\n",QString::SkipEmptyParts);
|
|
|
|
foreach(QString strLine, strListAll)
|
|
{
|
|
QStringList strListLine = strLine.split("\t");
|
|
if(strListLine.size() < 2)
|
|
continue;
|
|
QStringList strpumsa = strListLine.at(1).trimmed().split(",");
|
|
foreach(QString strMorphere, m_slMorphereList)
|
|
{
|
|
if(strpumsa.at(0).trimmed().contains(strMorphere,Qt::CaseInsensitive))
|
|
{
|
|
m_strKeyword = strListLine.at(0).toLower();
|
|
m_strMorphere = strMorphere;
|
|
QString strkey = m_strDate + "~!@" + m_strMorphere + "~!@" + m_strKeyword;
|
|
if(m_mapResult.contains(strkey))
|
|
{
|
|
(m_mapResult)[strkey]++;
|
|
}
|
|
|
|
else
|
|
{
|
|
m_mapResult.insert(strkey,1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//if(m_bDateAll)
|
|
|
|
//qDebug() << num << " : " << strData;
|
|
}
|
|
|
|
mecab_destroy(mecab);
|
|
|
|
}
|
|
|
|
void YBasicMThread::parseParam()
|
|
{
|
|
userdict = m_mapParam.value("UserDict");
|
|
|
|
m_nTitleBody = m_mapParam.value("TitleBody").toInt();
|
|
m_nPeriod = m_mapParam.value("Period").toInt();
|
|
|
|
m_nDateStart = m_mapParam.value("DateStart").toInt();
|
|
m_nDateEnd = m_mapParam.value("DateEnd").toInt();
|
|
|
|
m_bDateAll = true;
|
|
|
|
if(m_mapParam.value("DateALL") == "true")
|
|
m_bDateAll = true;
|
|
else
|
|
m_bDateAll = false;
|
|
|
|
m_slMorphereList = m_mapParam.value("MorphereList").split(" ");
|
|
|
|
}
|
|
|
|
QString YBasicMThread::getWeeksInMonth(unsigned int _nDate)
|
|
{
|
|
|
|
QDate qToday(_nDate/10000, (_nDate/100)%100, _nDate%100);
|
|
if(!qToday.isValid())
|
|
return "inVaildDate";
|
|
|
|
QDate qTodayFirstDay = QDate(qToday.year(), qToday.month(), 1);
|
|
QDate qTodayLastDay = QDate(qToday.year(), qToday.month(), qToday.daysInMonth());
|
|
|
|
int thisFirstDayofWeek = qTodayFirstDay.dayOfWeek();
|
|
int thisLastDayofWeek = qTodayLastDay.dayOfWeek();
|
|
int thisLastDay = qTodayLastDay.daysInMonth();
|
|
int week = 0;
|
|
int firstWeekDays = (WEEK - thisFirstDayofWeek) + 1;
|
|
QString strWeek = "W";
|
|
|
|
if(thisFirstDayofWeek < FRIDAY)
|
|
{
|
|
week = 1;
|
|
}
|
|
else
|
|
{
|
|
week = 0;
|
|
}
|
|
|
|
if((firstWeekDays < qToday.day()) && (qToday.day() <= (thisLastDay - thisLastDayofWeek)))
|
|
{
|
|
week = week + ((qToday.day() - firstWeekDays + WEEK - 1)/WEEK);
|
|
}
|
|
else if((firstWeekDays >= qToday.day()))
|
|
{
|
|
if(thisFirstDayofWeek >= FRIDAY)
|
|
{
|
|
|
|
const int DAYS_IN_WEEK = 7;
|
|
qToday = qToday.addMonths(-1);
|
|
int DaysInMonth = qToday.daysInMonth();
|
|
QDate FirstDayOfMonth = qToday;
|
|
FirstDayOfMonth.setDate(qToday.year(), qToday.month(), 1);
|
|
|
|
int WeekCount = DaysInMonth / DAYS_IN_WEEK;
|
|
int DaysLeft = DaysInMonth % DAYS_IN_WEEK;
|
|
if (DaysLeft > 0) {
|
|
WeekCount++;
|
|
// Check if the remaining days are split on two weeks
|
|
if (FirstDayOfMonth.dayOfWeek() + DaysLeft - 1 > DAYS_IN_WEEK)
|
|
WeekCount++;
|
|
}
|
|
week = WeekCount;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(thisLastDayofWeek < THURSDAY)
|
|
{
|
|
week = 1;
|
|
qToday = qToday.addMonths(1);
|
|
}
|
|
else
|
|
{
|
|
week = week + ((qToday.day() - firstWeekDays + WEEK - 1)/WEEK);
|
|
}
|
|
}
|
|
|
|
strWeek += qToday.toString("yyyyMM");
|
|
strWeek += QString::number(week);
|
|
return strWeek;
|
|
|
|
}
|
|
|
|
|
|
void YOneDepthMThread::run()
|
|
{
|
|
typedef mecab_t* (*mecab_new_fun)(int,char**);
|
|
typedef const char* (*mecab_sparse_tostr_fun)(mecab_t *mecab, const char *str);
|
|
typedef void (*mecab_destroy_fun)(mecab_t *mecab);
|
|
|
|
mecab_t *mecab;
|
|
mecab_new_fun mecab_new = (mecab_new_fun)QLibrary::resolve("libmecab.dll","mecab_new");
|
|
mecab_sparse_tostr_fun mecab_sparse_tostr = (mecab_sparse_tostr_fun)QLibrary::resolve("libmecab.dll","mecab_sparse_tostr");
|
|
|
|
parseParam();
|
|
|
|
if(userdict.length() < 1)
|
|
{
|
|
/*
|
|
char *t[] = {"RRR","-d","dic"};
|
|
int int_t = 3;
|
|
*/
|
|
|
|
char a[] = "RRR";
|
|
char b[] = "-d";
|
|
char c[] = "dic";
|
|
char *t[3];
|
|
t[0] = a;
|
|
t[1] = b;
|
|
t[2] = c;
|
|
int int_t = 3;
|
|
|
|
mecab = mecab_new(int_t, t);
|
|
}
|
|
else
|
|
{
|
|
char *cstr = new char[userdict.toStdString().length() + 1];
|
|
strcpy(cstr, userdict.toStdString().c_str());
|
|
/*
|
|
char **t = {"RRR","-d","dic","-u",cstr};
|
|
int int_t = 5;
|
|
*/
|
|
char a[] = "RRR";
|
|
char b[] = "-d";
|
|
char c[] = "dic";
|
|
char d[] = "-u";
|
|
|
|
char *t[5];
|
|
t[0] = a;
|
|
t[1] = b;
|
|
t[2] = c;
|
|
t[3] = d;
|
|
t[4] = cstr;
|
|
int int_t = 5;
|
|
|
|
mecab = mecab_new(int_t, t);
|
|
delete[] cstr;
|
|
}
|
|
mecab_destroy_fun mecab_destroy = (mecab_destroy_fun)QLibrary::resolve("libmecab.dll","mecab_destroy");
|
|
|
|
|
|
|
|
//qDebug() << num;
|
|
|
|
int nDate = 0;
|
|
while(true)
|
|
{
|
|
QString strTitle;
|
|
QString strBody;
|
|
QString strDate;
|
|
QString strData;
|
|
QString strPlatformTitle;
|
|
{
|
|
mutex->lock();
|
|
if(!m_pDAInterface->hasNext())
|
|
{
|
|
mutex->unlock();
|
|
break;
|
|
}
|
|
strTitle = m_pDAInterface->getArticleTitle();
|
|
strDate = m_pDAInterface->getArticleDate();
|
|
strPlatformTitle = m_pDAInterface->getPlatformTitle();
|
|
strBody = m_pDAInterface->getArticleData();
|
|
m_pDAInterface->next();
|
|
mutex->unlock();
|
|
}
|
|
|
|
{
|
|
switch(m_nTitleBody)
|
|
{
|
|
case 0:
|
|
{
|
|
strData = strTitle;
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
strData = strBody;
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
strData = strTitle + "\n" + strBody;
|
|
break;
|
|
}
|
|
case 3:
|
|
strData = strPlatformTitle;
|
|
break;
|
|
}
|
|
strTitle.clear();
|
|
strBody.clear();
|
|
strPlatformTitle.clear();
|
|
}
|
|
|
|
//if(!strData.contains(m_strCKeyword, Qt::CaseInsensitive))
|
|
if(!strData.contains(m_strCKeyword, Qt::CaseInsensitive))
|
|
continue;
|
|
|
|
if(strDate.length() < 11)
|
|
continue;
|
|
|
|
strDate = strDate.left(11);
|
|
if(strDate.trimmed().length()<10)
|
|
{
|
|
nDate = 0;
|
|
}
|
|
else
|
|
{
|
|
strDate = strDate.replace("-","").trimmed();
|
|
if(strDate.length() < 8)
|
|
{
|
|
nDate = 0;
|
|
}
|
|
else
|
|
nDate = strDate.toInt();
|
|
}
|
|
|
|
if(!m_bDateAll)
|
|
{
|
|
if(nDate < m_nDateStart || m_nDateEnd < nDate)
|
|
continue;
|
|
}
|
|
|
|
QString m_strDate;
|
|
QString m_strKeyword;
|
|
QString m_strMorphere;
|
|
|
|
switch(m_nPeriod)
|
|
{
|
|
case 0:
|
|
{
|
|
m_strDate = "ALL";
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
m_strDate = "D" + QString::number(nDate);
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
/*
|
|
QDate tempdate = QDate(nDate/10000, (nDate%10000)/100, nDate%100);
|
|
mapkey.strDate = "W" + QString::number(nDate/10000);
|
|
if(tempdate.weekNumber() < 10)
|
|
mapkey.strDate += "0";
|
|
mapkey.strDate += QString::number(tempdate.weekNumber());
|
|
*/
|
|
m_strDate = getWeeksInMonth(nDate);
|
|
break;
|
|
}
|
|
case 3:
|
|
{
|
|
m_strDate = "M";
|
|
if((nDate/100) < 10)
|
|
m_strDate += "0";
|
|
m_strDate += QString::number(nDate/100);
|
|
break;
|
|
}
|
|
}
|
|
|
|
QString strAnalyzedLine = QString::fromStdString(mecab_sparse_tostr(mecab, strData.toStdString().c_str())) + "\n";
|
|
QStringList strListAll = strAnalyzedLine.split("\n",QString::SkipEmptyParts);
|
|
|
|
foreach(QString strLine, strListAll)
|
|
{
|
|
QStringList strListLine = strLine.split("\t");
|
|
if(strListLine.size() < 2)
|
|
continue;
|
|
QStringList strpumsa = strListLine.at(1).trimmed().split(",");
|
|
foreach(QString strMorphere, m_slMorphereList)
|
|
{
|
|
if(strpumsa.at(0).trimmed().contains(strMorphere,Qt::CaseInsensitive))
|
|
{
|
|
m_strKeyword = strListLine.at(0).toLower();
|
|
m_strMorphere = strMorphere;
|
|
QString strkey = m_strDate + "~!@" + m_strMorphere + "~!@" + m_strKeyword;
|
|
if(m_mapResult.contains(strkey))
|
|
{
|
|
(m_mapResult)[strkey]++;
|
|
}
|
|
|
|
else
|
|
{
|
|
m_mapResult.insert(strkey,1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//if(m_bDateAll)
|
|
|
|
//qDebug() << num << " : " << strData;
|
|
}
|
|
|
|
mecab_destroy(mecab);
|
|
|
|
}
|
|
|
|
void YOneDepthMThread::parseParam()
|
|
{
|
|
|
|
userdict = m_mapParam.value("UserDict");
|
|
|
|
m_nTitleBody = m_mapParam.value("TitleBody").toInt();
|
|
m_nPeriod = m_mapParam.value("Period").toInt();
|
|
|
|
m_nDateStart = m_mapParam.value("DateStart").toInt();
|
|
m_nDateEnd = m_mapParam.value("DateEnd").toInt();
|
|
|
|
m_bDateAll = true;
|
|
|
|
if(m_mapParam.value("DateALL") == "true")
|
|
m_bDateAll = true;
|
|
else
|
|
m_bDateAll = false;
|
|
|
|
m_slMorphereList = m_mapParam.value("MorphereList").split(" ");
|
|
|
|
m_strCKeyword = m_mapParam.value("CenterKeyword").trimmed();
|
|
}
|
|
|
|
QString YOneDepthMThread::getWeeksInMonth(unsigned int _nDate)
|
|
{
|
|
|
|
QDate qToday(_nDate/10000, (_nDate/100)%100, _nDate%100);
|
|
if(!qToday.isValid())
|
|
return "inVaildDate";
|
|
|
|
QDate qTodayFirstDay = QDate(qToday.year(), qToday.month(), 1);
|
|
QDate qTodayLastDay = QDate(qToday.year(), qToday.month(), qToday.daysInMonth());
|
|
|
|
int thisFirstDayofWeek = qTodayFirstDay.dayOfWeek();
|
|
int thisLastDayofWeek = qTodayLastDay.dayOfWeek();
|
|
int thisLastDay = qTodayLastDay.daysInMonth();
|
|
int week = 0;
|
|
int firstWeekDays = (WEEK - thisFirstDayofWeek) + 1;
|
|
QString strWeek = "W";
|
|
|
|
if(thisFirstDayofWeek < FRIDAY)
|
|
{
|
|
week = 1;
|
|
}
|
|
else
|
|
{
|
|
week = 0;
|
|
}
|
|
|
|
if((firstWeekDays < qToday.day()) && (qToday.day() <= (thisLastDay - thisLastDayofWeek)))
|
|
{
|
|
week = week + ((qToday.day() - firstWeekDays + WEEK - 1)/WEEK);
|
|
}
|
|
else if((firstWeekDays >= qToday.day()))
|
|
{
|
|
if(thisFirstDayofWeek >= FRIDAY)
|
|
{
|
|
|
|
const int DAYS_IN_WEEK = 7;
|
|
qToday = qToday.addMonths(-1);
|
|
int DaysInMonth = qToday.daysInMonth();
|
|
QDate FirstDayOfMonth = qToday;
|
|
FirstDayOfMonth.setDate(qToday.year(), qToday.month(), 1);
|
|
|
|
int WeekCount = DaysInMonth / DAYS_IN_WEEK;
|
|
int DaysLeft = DaysInMonth % DAYS_IN_WEEK;
|
|
if (DaysLeft > 0) {
|
|
WeekCount++;
|
|
// Check if the remaining days are split on two weeks
|
|
if (FirstDayOfMonth.dayOfWeek() + DaysLeft - 1 > DAYS_IN_WEEK)
|
|
WeekCount++;
|
|
}
|
|
week = WeekCount;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(thisLastDayofWeek < THURSDAY)
|
|
{
|
|
week = 1;
|
|
qToday = qToday.addMonths(1);
|
|
}
|
|
else
|
|
{
|
|
week = week + ((qToday.day() - firstWeekDays + WEEK - 1)/WEEK);
|
|
}
|
|
}
|
|
|
|
strWeek += qToday.toString("yyyyMM");
|
|
strWeek += QString::number(week);
|
|
return strWeek;
|
|
|
|
}
|
|
|
|
|
|
|
|
void YTwoDepthMThread::run()
|
|
{
|
|
typedef mecab_t* (*mecab_new_fun)(int,char**);
|
|
typedef const char* (*mecab_sparse_tostr_fun)(mecab_t *mecab, const char *str);
|
|
typedef void (*mecab_destroy_fun)(mecab_t *mecab);
|
|
|
|
mecab_t *mecab;
|
|
mecab_new_fun mecab_new = (mecab_new_fun)QLibrary::resolve("libmecab.dll","mecab_new");
|
|
mecab_sparse_tostr_fun mecab_sparse_tostr = (mecab_sparse_tostr_fun)QLibrary::resolve("libmecab.dll","mecab_sparse_tostr");
|
|
|
|
parseParam();
|
|
|
|
if(userdict.length() < 1)
|
|
{
|
|
/*
|
|
char *t[] = {"RRR","-d","dic"};
|
|
int int_t = 3;
|
|
*/
|
|
|
|
char a[] = "RRR";
|
|
char b[] = "-d";
|
|
char c[] = "dic";
|
|
char *t[3];
|
|
t[0] = a;
|
|
t[1] = b;
|
|
t[2] = c;
|
|
int int_t = 3;
|
|
|
|
mecab = mecab_new(int_t, t);
|
|
}
|
|
else
|
|
{
|
|
char *cstr = new char[userdict.toStdString().length() + 1];
|
|
strcpy(cstr, userdict.toStdString().c_str());
|
|
/*
|
|
char **t = {"RRR","-d","dic","-u",cstr};
|
|
int int_t = 5;
|
|
*/
|
|
char a[] = "RRR";
|
|
char b[] = "-d";
|
|
char c[] = "dic";
|
|
char d[] = "-u";
|
|
|
|
char *t[5];
|
|
t[0] = a;
|
|
t[1] = b;
|
|
t[2] = c;
|
|
t[3] = d;
|
|
t[4] = cstr;
|
|
int int_t = 5;
|
|
|
|
mecab = mecab_new(int_t, t);
|
|
delete[] cstr;
|
|
}
|
|
mecab_destroy_fun mecab_destroy = (mecab_destroy_fun)QLibrary::resolve("libmecab.dll","mecab_destroy");
|
|
|
|
|
|
|
|
//qDebug() << num;
|
|
|
|
int nDate = 0;
|
|
while(true)
|
|
{
|
|
QString strTitle;
|
|
QString strBody;
|
|
QString strDate;
|
|
QString strData;
|
|
QString strPlatformTitle;
|
|
{
|
|
mutex->lock();
|
|
if(!m_pDAInterface->hasNext())
|
|
{
|
|
mutex->unlock();
|
|
break;
|
|
}
|
|
strTitle = m_pDAInterface->getArticleTitle();
|
|
strDate = m_pDAInterface->getArticleDate();
|
|
strPlatformTitle = m_pDAInterface->getPlatformTitle();
|
|
strBody = m_pDAInterface->getArticleData();
|
|
m_pDAInterface->next();
|
|
mutex->unlock();
|
|
}
|
|
|
|
{
|
|
switch(m_nTitleBody)
|
|
{
|
|
case 0:
|
|
{
|
|
strData = strTitle;
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
strData = strBody;
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
strData = strTitle + "\n" + strBody;
|
|
break;
|
|
}
|
|
case 3:
|
|
strData = strPlatformTitle;
|
|
break;
|
|
}
|
|
strTitle.clear();
|
|
strBody.clear();
|
|
strPlatformTitle.clear();
|
|
}
|
|
|
|
//if(!strData.contains(m_strCKeyword, Qt::CaseInsensitive))
|
|
if(!strData.contains(m_strCKeyword, Qt::CaseInsensitive))
|
|
continue;
|
|
|
|
if(strDate.length() < 11)
|
|
continue;
|
|
|
|
strDate = strDate.left(11);
|
|
if(strDate.trimmed().length()<10)
|
|
{
|
|
nDate = 0;
|
|
}
|
|
else
|
|
{
|
|
strDate = strDate.replace("-","").trimmed();
|
|
if(strDate.length() < 8)
|
|
{
|
|
nDate = 0;
|
|
}
|
|
else
|
|
nDate = strDate.toInt();
|
|
}
|
|
|
|
if(!m_bDateAll)
|
|
{
|
|
if(nDate < m_nDateStart || m_nDateEnd < nDate)
|
|
continue;
|
|
}
|
|
|
|
QString m_strDate;
|
|
QString m_strKeyword;
|
|
QString m_strMorphere;
|
|
|
|
switch(m_nPeriod)
|
|
{
|
|
case 0:
|
|
{
|
|
m_strDate = "ALL";
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
m_strDate = "D" + QString::number(nDate);
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
/*
|
|
QDate tempdate = QDate(nDate/10000, (nDate%10000)/100, nDate%100);
|
|
mapkey.strDate = "W" + QString::number(nDate/10000);
|
|
if(tempdate.weekNumber() < 10)
|
|
mapkey.strDate += "0";
|
|
mapkey.strDate += QString::number(tempdate.weekNumber());
|
|
*/
|
|
m_strDate = getWeeksInMonth(nDate);
|
|
break;
|
|
}
|
|
case 3:
|
|
{
|
|
m_strDate = "M";
|
|
if((nDate/100) < 10)
|
|
m_strDate += "0";
|
|
m_strDate += QString::number(nDate/100);
|
|
break;
|
|
}
|
|
}
|
|
|
|
QString strAnalyzedLine = QString::fromStdString(mecab_sparse_tostr(mecab, strData.toStdString().c_str())) + "\n";
|
|
QStringList strListAll = strAnalyzedLine.split("\n",QString::SkipEmptyParts);
|
|
|
|
QMap<QString, int> tempResult;
|
|
|
|
foreach(QString strLine, strListAll)
|
|
{
|
|
QStringList strListLine = strLine.split("\t");
|
|
if(strListLine.size() < 2)
|
|
continue;
|
|
QStringList strpumsa = strListLine.at(1).trimmed().split(",");
|
|
foreach(QString strMorphere, m_slMorphereList)
|
|
{
|
|
if(strpumsa.at(0).trimmed().contains(strMorphere,Qt::CaseInsensitive))
|
|
{
|
|
m_strKeyword = strListLine.at(0).toLower();
|
|
m_strMorphere = strMorphere;
|
|
QString strkey = m_strDate + "~!@" + m_strMorphere + "~!@" + m_strKeyword;
|
|
if(tempResult.contains(strkey))
|
|
{
|
|
(tempResult)[strkey]++;
|
|
}
|
|
|
|
else
|
|
{
|
|
tempResult.insert(strkey,1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach(QString str, m_slOneDepthKeys)
|
|
{
|
|
if(tempResult.contains(str))
|
|
{
|
|
for(QMap<QString, int>::iterator iterPos = tempResult.begin(); iterPos != tempResult.end(); iterPos++)
|
|
{
|
|
if(iterPos.key() == str)
|
|
continue;
|
|
QString key = iterPos.key();
|
|
QStringList slkey = key.split("~!@", QString::SkipEmptyParts);
|
|
int nLength = slkey.length();
|
|
QString strkey = str + "~!@" + slkey.at(nLength - 2) + "~!@" + slkey.at(nLength - 1);
|
|
if(m_mapResult.contains(strkey))
|
|
{
|
|
m_mapResult[strkey] += iterPos.value();
|
|
}
|
|
else
|
|
{
|
|
m_mapResult.insert(strkey, iterPos.value());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
mecab_destroy(mecab);
|
|
}
|
|
|
|
void YTwoDepthMThread::parseParam()
|
|
{
|
|
userdict = m_mapParam.value("UserDict");
|
|
|
|
m_nTitleBody = m_mapParam.value("TitleBody").toInt();
|
|
m_nPeriod = m_mapParam.value("Period").toInt();
|
|
|
|
m_nDateStart = m_mapParam.value("DateStart").toInt();
|
|
m_nDateEnd = m_mapParam.value("DateEnd").toInt();
|
|
|
|
m_bDateAll = true;
|
|
|
|
if(m_mapParam.value("DateALL") == "true")
|
|
m_bDateAll = true;
|
|
else
|
|
m_bDateAll = false;
|
|
|
|
m_slMorphereList = m_mapParam.value("MorphereList").split(" ");
|
|
|
|
m_strCKeyword = m_mapParam.value("CenterKeyword").trimmed();
|
|
|
|
m_slOneDepthKeys = m_mapParam.value("OneDepthKeys").split(" ");
|
|
}
|
|
|
|
|
|
QString YTwoDepthMThread::getWeeksInMonth(unsigned int _nDate)
|
|
{
|
|
|
|
QDate qToday(_nDate/10000, (_nDate/100)%100, _nDate%100);
|
|
if(!qToday.isValid())
|
|
return "inVaildDate";
|
|
|
|
QDate qTodayFirstDay = QDate(qToday.year(), qToday.month(), 1);
|
|
QDate qTodayLastDay = QDate(qToday.year(), qToday.month(), qToday.daysInMonth());
|
|
|
|
int thisFirstDayofWeek = qTodayFirstDay.dayOfWeek();
|
|
int thisLastDayofWeek = qTodayLastDay.dayOfWeek();
|
|
int thisLastDay = qTodayLastDay.daysInMonth();
|
|
int week = 0;
|
|
int firstWeekDays = (WEEK - thisFirstDayofWeek) + 1;
|
|
QString strWeek = "W";
|
|
|
|
if(thisFirstDayofWeek < FRIDAY)
|
|
{
|
|
week = 1;
|
|
}
|
|
else
|
|
{
|
|
week = 0;
|
|
}
|
|
|
|
if((firstWeekDays < qToday.day()) && (qToday.day() <= (thisLastDay - thisLastDayofWeek)))
|
|
{
|
|
week = week + ((qToday.day() - firstWeekDays + WEEK - 1)/WEEK);
|
|
}
|
|
else if((firstWeekDays >= qToday.day()))
|
|
{
|
|
if(thisFirstDayofWeek >= FRIDAY)
|
|
{
|
|
|
|
const int DAYS_IN_WEEK = 7;
|
|
qToday = qToday.addMonths(-1);
|
|
int DaysInMonth = qToday.daysInMonth();
|
|
QDate FirstDayOfMonth = qToday;
|
|
FirstDayOfMonth.setDate(qToday.year(), qToday.month(), 1);
|
|
|
|
int WeekCount = DaysInMonth / DAYS_IN_WEEK;
|
|
int DaysLeft = DaysInMonth % DAYS_IN_WEEK;
|
|
if (DaysLeft > 0) {
|
|
WeekCount++;
|
|
// Check if the remaining days are split on two weeks
|
|
if (FirstDayOfMonth.dayOfWeek() + DaysLeft - 1 > DAYS_IN_WEEK)
|
|
WeekCount++;
|
|
}
|
|
week = WeekCount;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(thisLastDayofWeek < THURSDAY)
|
|
{
|
|
week = 1;
|
|
qToday = qToday.addMonths(1);
|
|
}
|
|
else
|
|
{
|
|
week = week + ((qToday.day() - firstWeekDays + WEEK - 1)/WEEK);
|
|
}
|
|
}
|
|
|
|
strWeek += qToday.toString("yyyyMM");
|
|
strWeek += QString::number(week);
|
|
return strWeek;
|
|
|
|
}
|
|
|
|
|
|
|
|
void YPlatformMThread::run()
|
|
{
|
|
|
|
}
|
|
|
|
void YPlatformMThread::parseParam()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void YIDMThread::run()
|
|
{
|
|
|
|
}
|
|
|
|
void YIDMThread::parseParam()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void YNNMatrixMThread::run()
|
|
{
|
|
parseParam();
|
|
|
|
|
|
int nDate = 0;
|
|
while(true)
|
|
{
|
|
QString strTitle;
|
|
QString strBody;
|
|
QString strDate;
|
|
QString strData;
|
|
QString strPlatformTitle;
|
|
{
|
|
mutex->lock();
|
|
if(!m_pDAInterface->hasNext())
|
|
{
|
|
mutex->unlock();
|
|
break;
|
|
}
|
|
strTitle = m_pDAInterface->getArticleTitle();
|
|
strDate = m_pDAInterface->getArticleDate();
|
|
strPlatformTitle = m_pDAInterface->getPlatformTitle();
|
|
strBody = m_pDAInterface->getArticleData();
|
|
m_pDAInterface->next();
|
|
mutex->unlock();
|
|
}
|
|
|
|
{
|
|
switch(m_nTitleBody)
|
|
{
|
|
case 0:
|
|
{
|
|
strData = strTitle;
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
strData = strBody;
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
strData = strTitle + "\n" + strBody;
|
|
break;
|
|
}
|
|
case 3:
|
|
strData = strPlatformTitle;
|
|
break;
|
|
}
|
|
strTitle.clear();
|
|
strBody.clear();
|
|
strPlatformTitle.clear();
|
|
}
|
|
|
|
if(strDate.length() < 11)
|
|
continue;
|
|
|
|
strDate = strDate.left(11);
|
|
if(strDate.trimmed().length()<10)
|
|
{
|
|
nDate = 0;
|
|
}
|
|
else
|
|
{
|
|
strDate = strDate.replace("-","").trimmed();
|
|
if(strDate.length() < 8)
|
|
{
|
|
nDate = 0;
|
|
}
|
|
else
|
|
nDate = strDate.toInt();
|
|
}
|
|
|
|
if(!m_bDateAll)
|
|
{
|
|
if(nDate < m_nDateStart || m_nDateEnd < nDate)
|
|
continue;
|
|
}
|
|
|
|
QString m_strDate;
|
|
|
|
switch(m_nPeriod)
|
|
{
|
|
case 0:
|
|
{
|
|
m_strDate = "ALL";
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
m_strDate = "D" + QString::number(nDate);
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
m_strDate = getWeeksInMonth(nDate);
|
|
break;
|
|
}
|
|
case 3:
|
|
{
|
|
m_strDate = "M";
|
|
if((nDate/100) < 10)
|
|
m_strDate += "0";
|
|
m_strDate += QString::number(nDate/100);
|
|
break;
|
|
}
|
|
}
|
|
|
|
QMap<QString, int> mapTemp;
|
|
|
|
foreach(QString strtmp, m_strMKeyword)
|
|
{
|
|
QString strkeyword = strtmp.trimmed();
|
|
mapTemp.insert(strkeyword, 0);
|
|
mapTemp[strkeyword] = strData.count(strkeyword, Qt::CaseInsensitive);
|
|
}
|
|
|
|
|
|
if(!m_bDuplicate)
|
|
{
|
|
for(QMap<QString, int>::iterator iterPos = mapTemp.begin(); iterPos != mapTemp.end(); iterPos++)
|
|
{
|
|
if(iterPos.value() > 0)
|
|
{
|
|
mapTemp[iterPos.key()] = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
for(QMap<QString, int>::iterator iterPos1 = mapTemp.begin(); iterPos1 != mapTemp.end(); iterPos1++)
|
|
{
|
|
for(QMap<QString, int>::iterator iterPos2 = mapTemp.begin(); iterPos2 != mapTemp.end(); iterPos2++)
|
|
{
|
|
if((iterPos1.value() > 0) && (iterPos2.value() > 0))
|
|
{
|
|
QString strkey = m_strDate + "~!@" + iterPos1.key() + "~!@" + iterPos2.key();
|
|
if(m_mapResult.contains(strkey))
|
|
{
|
|
m_mapResult[strkey] += iterPos2.value();
|
|
}
|
|
else
|
|
{
|
|
m_mapResult.insert(strkey, iterPos2.value());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QString strkey = m_strDate + "~!@" + iterPos1.key() + "~!@" + iterPos2.key();
|
|
if(m_mapResult.contains(strkey))
|
|
{
|
|
m_mapResult[strkey] += 0;
|
|
}
|
|
else
|
|
{
|
|
m_mapResult.insert(strkey, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void YNNMatrixMThread::parseParam()
|
|
{
|
|
userdict = m_mapParam.value("UserDict");
|
|
|
|
m_nTitleBody = m_mapParam.value("TitleBody").toInt();
|
|
m_nPeriod = m_mapParam.value("Period").toInt();
|
|
|
|
m_nDateStart = m_mapParam.value("DateStart").toInt();
|
|
m_nDateEnd = m_mapParam.value("DateEnd").toInt();
|
|
|
|
m_bDateAll = true;
|
|
|
|
if(m_mapParam.value("DateALL") == "true")
|
|
m_bDateAll = true;
|
|
else
|
|
m_bDateAll = false;
|
|
|
|
QRegExp re("[\\s,.;]");
|
|
|
|
m_strMKeyword = m_mapParam.value("MatrixKeyword").trimmed().split(re, QString::SkipEmptyParts);
|
|
if(m_mapParam.value("CountMethod") == "Duplicate")
|
|
m_bDuplicate = true;
|
|
else
|
|
m_bDuplicate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString YNNMatrixMThread::getWeeksInMonth(unsigned int _nDate)
|
|
{
|
|
|
|
QDate qToday(_nDate/10000, (_nDate/100)%100, _nDate%100);
|
|
if(!qToday.isValid())
|
|
return "inVaildDate";
|
|
|
|
QDate qTodayFirstDay = QDate(qToday.year(), qToday.month(), 1);
|
|
QDate qTodayLastDay = QDate(qToday.year(), qToday.month(), qToday.daysInMonth());
|
|
|
|
int thisFirstDayofWeek = qTodayFirstDay.dayOfWeek();
|
|
int thisLastDayofWeek = qTodayLastDay.dayOfWeek();
|
|
int thisLastDay = qTodayLastDay.daysInMonth();
|
|
int week = 0;
|
|
int firstWeekDays = (WEEK - thisFirstDayofWeek) + 1;
|
|
QString strWeek = "W";
|
|
|
|
if(thisFirstDayofWeek < FRIDAY)
|
|
{
|
|
week = 1;
|
|
}
|
|
else
|
|
{
|
|
week = 0;
|
|
}
|
|
|
|
if((firstWeekDays < qToday.day()) && (qToday.day() <= (thisLastDay - thisLastDayofWeek)))
|
|
{
|
|
week = week + ((qToday.day() - firstWeekDays + WEEK - 1)/WEEK);
|
|
}
|
|
else if((firstWeekDays >= qToday.day()))
|
|
{
|
|
if(thisFirstDayofWeek >= FRIDAY)
|
|
{
|
|
|
|
const int DAYS_IN_WEEK = 7;
|
|
qToday = qToday.addMonths(-1);
|
|
int DaysInMonth = qToday.daysInMonth();
|
|
QDate FirstDayOfMonth = qToday;
|
|
FirstDayOfMonth.setDate(qToday.year(), qToday.month(), 1);
|
|
|
|
int WeekCount = DaysInMonth / DAYS_IN_WEEK;
|
|
int DaysLeft = DaysInMonth % DAYS_IN_WEEK;
|
|
if (DaysLeft > 0) {
|
|
WeekCount++;
|
|
// Check if the remaining days are split on two weeks
|
|
if (FirstDayOfMonth.dayOfWeek() + DaysLeft - 1 > DAYS_IN_WEEK)
|
|
WeekCount++;
|
|
}
|
|
week = WeekCount;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(thisLastDayofWeek < THURSDAY)
|
|
{
|
|
week = 1;
|
|
qToday = qToday.addMonths(1);
|
|
}
|
|
else
|
|
{
|
|
week = week + ((qToday.day() - firstWeekDays + WEEK - 1)/WEEK);
|
|
}
|
|
}
|
|
|
|
strWeek += qToday.toString("yyyyMM");
|
|
strWeek += QString::number(week);
|
|
return strWeek;
|
|
|
|
}
|
|
|