C++ (Qt)void MainWindow::textoryFromBuffer(){ QClipboard *clipboard = QApplication::clipboard(); QString originalBuffer = clipboard->text(); QTextStream bufferStream( & originalBuffer ); QString itemBufStr, itemTextStr; QStringList textList; textory.clear(); do { itemBufStr = bufferStream.readLine(); itemTextStr = itemBufStr.trimmed(); if ( itemTextStr.isEmpty() ) continue; textList.prepend( itemTextStr ); } while ( !bufferStream.atEnd() ); textory.enableAdd( true ); foreach (QString itm, textList) textory.addItem( Textory::Item( 1, itm ) ); cfg.textoryName = "From Buffer"; ui.textoryPaneWidget->getTextoryLabel().setText( cfg.textoryName );}
C++ (Qt)enum { sort_None = 0, sort_Freq = 1, sort_Crazy = 2, // даете имена по смыслу, этл для примера};
C++ (Qt)void MainWindow::wordStat(){ QTime tm; tm.start(); const Config::Preferences & pref = cfg.preferences; QClipboard *clipboard = QApplication::clipboard(); QString originalText = clipboard->text(); QString addZero; QStringList listFull; QStringList frequencyList; qDebug() << "Reade Data: " << tm.elapsed(); tm.start(); textory.clear(); textory.enableAdd( true ); // ОСТАВЛЯЕМ: ВЕСЬ ТЕКСТ/АНГЛИЙСКИЙ/РУССКИЙ const QString mask[3] = { QString("[\\s\\W\\d_]+"), QString("[^a-z]+"), QString::fromUtf8("[^а-яё]+"), }; QRegExp rexp(mask[pref.langStatSort]); listFull = originalText.toLower().split(rexp, QString::SkipEmptyParts); qDebug() << "Data split: " << tm.elapsed(); tm.start(); // ПОСТРОЕНИЕ СПИСКА QRegExp rx(muRegExp); rx.setPatternSyntax(QRegExp::Wildcard); enum { sort_Amount = 0, sort_Alphabet = 1, sort_None = 2 }; QHash<QString, int> freqHash; foreach (QString s, listFull) ++freqHash[s]; frequencyList.reserve(listFull.size()); foreach (QString s, listFull) { if (s.size() < pref.minSizeWord || s.size() > pref.maxSizeWord )continue; if (!muRegExp.isEmpty() && !rx.exactMatch(s))continue; int & num = freqHash[s]; if (num < 0) continue; if (num >= pref.minRepeats ) { if (pref.typeOfSort != sort_Amount) frequencyList.prepend(s + '\t' + QString::number(long(num))); else { addZero = QString::number(long(num)).rightJustified(6, '0'); frequencyList.prepend(addZero + s + '\t' + QString::number(long(num))); } } num = -num; } qDebug() << "Count: " << tm.elapsed(); tm.start(); if (pref.typeOfSort != sort_None)qSort(frequencyList); // ВЫВОД СПИСКА qDebug() << "Data sort: " << tm.elapsed(); tm.start(); if (pref.typeOfSort == sort_Amount || pref.typeOfSort == sort_None) { foreach (QString itm, frequencyList) { if(pref.typeOfSort == 0)itm.remove(0,6); textory.addItem( Textory::Item( 1, itm ) ); } } if (pref.typeOfSort == sort_Alphabet) { QListIterator<QString>itm(frequencyList); itm.toBack(); while (itm.hasPrevious()) textory.addItem( Textory::Item( 1, itm.previous() ) ); } qDebug() << "Out list: " << tm.elapsed(); tm.start(); // ПРОЦЕНТ ОСТАВЛЕННЫХ СЛОВ ОТ КОЛИЧЕСТВА ОРИГИНАЛЬНЫХ double full(freqHash.size()); double real(textory.size()); QString freqStat = "/" + QString::number(long(freqHash.size())) + "/" + QString::number(double(real * 100 / full), 'f', 2).remove(QRegExp("\\.00")) + "%"; cfg.textoryName = "Frequency list (" + QString::number(long(listFull.size())) + freqStat + ")"; ui.textoryPaneWidget->getTextoryLabel().setText( cfg.textoryName ); qDebug() << "Write name: " << tm.elapsed();}
C++ (Qt) enum { sort_Amount = 0, sort_Alphabet = 1, sort_None = 2 };
C++ (Qt) if (pref.typeOfSort == sort_Amount || pref.typeOfSort == sort_None) { foreach (QString itm, frequencyList) { if(pref.typeOfSort == 0)itm.remove(0,6); textory.addItem( Textory::Item( 1, itm ) ); } } if (pref.typeOfSort == sort_Alphabet) { QListIterator<QString>itm(frequencyList); itm.toBack(); while (itm.hasPrevious()) textory.addItem( Textory::Item( 1, itm.previous() ) ); }
C++ (Qt)QStringList & lst = frequencyList;const int ilimit = lst.size();for (int i = 0; i < limit; ++i) { switch (pref.typeOfSort) { case sort_None: textory.addItem(Textory::Item(1, lst[i]); break; case sort_Amount: textory.addItem(Textory::Item(1, lst[i].remove(0, 6))); breakl; case sort_Alphabet: textory.addItem(Textory::Item(1, lst[limit - 1 - i]); break; }}
C++ (Qt)void MainWindow::wordStat(){ QTime tm; tm.start(); const Config::Preferences & pref = cfg.preferences; QClipboard *clipboard = QApplication::clipboard(); QString originalText = clipboard->text(); QString addZero; QStringList listFull; QStringList frequencyList; qDebug() << "Reade Data: " << tm.elapsed(); tm.start(); textory.clear(); textory.enableAdd( true ); // ОСТАВЛЯЕМ: ВЕСЬ ТЕКСТ/АНГЛИЙСКИЙ/РУССКИЙ const QString mask[3] = { QString("[\\s\\W\\d_]+"), QString("[^a-z]+"), QString::fromUtf8("[^а-яё]+"), }; QRegExp rexp(mask[pref.langStatSort]); listFull = originalText.toLower().split(rexp, QString::SkipEmptyParts); qDebug() << "Data split: " << tm.elapsed(); tm.start(); // ПОСТРОЕНИЕ СПИСКА QRegExp rx(muRegExp); rx.setPatternSyntax(QRegExp::Wildcard); enum { sort_Amount = 0, sort_Alphabet = 1, sort_None = 2 }; QHash<QString, int> freqHash; foreach (QString s, listFull) ++freqHash[s]; frequencyList.reserve(listFull.size()); foreach (QString s, listFull) { if (s.size() < pref.minSizeWord || s.size() > pref.maxSizeWord )continue; if (!muRegExp.isEmpty() && !rx.exactMatch(s))continue; int & num = freqHash[s]; if (num < 0) continue; if (num >= pref.minRepeats && num <= pref.maxRepeats) { if (pref.typeOfSort != sort_Amount) frequencyList.prepend(s + '\t' + QString::number(long(num))); else { addZero = QString::number(long(num)).rightJustified(6, '0'); frequencyList.prepend(addZero + s + '\t' + QString::number(long(num))); } } num = -num; } qDebug() << "Count: " << tm.elapsed(); tm.start(); if (pref.typeOfSort != sort_None)qSort(frequencyList); // ВЫВОД СПИСКА qDebug() << "Data sort: " << tm.elapsed(); tm.start(); QStringList & lst = frequencyList; const int ilimit = lst.size(); for (int i = 0; i < ilimit; ++i) { switch (pref.typeOfSort) { case sort_None: textory.addItem(Textory::Item(1, lst[i])); break; case sort_Amount: textory.addItem(Textory::Item(1, lst[i].remove(0, 6))); break; case sort_Alphabet: textory.addItem(Textory::Item(1, lst[ilimit - 1 - i])); break; } } qDebug() << "Out list: " << tm.elapsed(); tm.start(); // ПРОЦЕНТ ОСТАВЛЕННЫХ СЛОВ ОТ КОЛИЧЕСТВА ОРИГИНАЛЬНЫХ double full(freqHash.size()); double real(textory.size()); QString freqStat = "/" + QString::number(long(freqHash.size())) + "/" + QString::number(double(real * 100 / full), 'f', 2).remove(QRegExp("\\.00")) + "%"; cfg.textoryName += " (" + QString::number(long(listFull.size())) + freqStat + ")"; ui.textoryPaneWidget->getTextoryLabel().setText( cfg.textoryName ); qDebug() << "Write name: " << tm.elapsed();}
C++ (Qt) // ОСТАВЛЯЕМ: ВЕСЬ ТЕКСТ/АНГЛИЙСКИЙ/РУССКИЙ const QString mask[3] = { QString("[\\s\\W\\d_]+"), QString("[^a-z]+"), QString::fromUtf8("[^а-яё]+"), };
C++ (Qt) const QString mask[4] = {... QString("\n[\\t].*\n[^\\t]"), }; QRegExp rexp(mask[pref.langStatSort]); rexp.setMinimal(true); listFull = originalText.toLower().split(rexp, QString::SkipEmptyParts);
C++ (Qt)void MainWindow::wordStat(){ QTime tm; tm.start(); const Config::Preferences & pref = cfg.preferences; QClipboard *clipboard = QApplication::clipboard(); QString originalText = clipboard->text(); QString addZero; QStringList listFull; QStringList frequencyList; int xlsCountFull(0); qDebug() << "Reade Data: " << tm.elapsed(); tm.start(); textory.clear(); textory.enableAdd( true ); // ОСТАВЛЯЕМ: ВЕСЬ ТЕКСТ/АНГЛИЙСКИЙ/РУССКИЙ const QString mask[4] = { QString("[\\s\\W\\d_]+"), QString("[^a-z]+"), QString::fromUtf8("[^а-яё]+"), QString("\n"), }; QRegExp rexp(mask[pref.langStatSort]); rexp.setMinimal(true); listFull = originalText.toLower().split(rexp, QString::SkipEmptyParts); qDebug() << "Data split: " << tm.elapsed(); tm.start(); // ПОСТРОЕНИЕ СПИСКА QRegExp rx(muRegExp); rx.setPatternSyntax(QRegExp::Wildcard); enum { sort_Amount = 0, sort_Alphabet = 1, sort_None = 2 }; QHash<QString, int> freqHash; foreach (QString s, listFull) { if (pref.langStatSort == 3 && (s.startsWith("\t") || s.startsWith(" ") || s.startsWith("#") || s.startsWith("{{")))continue; ++freqHash[s]; } frequencyList.reserve(listFull.size()); foreach (QString s, listFull) { if (pref.langStatSort == 3 && (s.startsWith("\t") || s.startsWith(" ") || s.startsWith("#") || s.startsWith("{{")))continue; ++xlsCountFull; if (s.size() < pref.minSizeWord || s.size() > pref.maxSizeWord )continue; if (!muRegExp.isEmpty() && !rx.exactMatch(s))continue; int & num = freqHash[s];// if (num < 0) continue; if (num >= pref.minRepeats && num <= pref.maxRepeats) { if (pref.typeOfSort != sort_Amount) frequencyList.prepend(s + '\t' + QString::number(long(num))); else { addZero = QString::number(long(num)).rightJustified(6, '0'); frequencyList.prepend(addZero + s + '\t' + QString::number(long(num))); } }// num = -num; } qDebug() << "Count: " << tm.elapsed(); tm.start(); if (pref.typeOfSort != sort_None)qSort(frequencyList); // ВЫВОД СПИСКА qDebug() << "Data sort: " << tm.elapsed(); tm.start(); QStringList & lst = frequencyList; const int ilimit = lst.size(); for (int i = 0; i < ilimit; ++i) { switch (pref.typeOfSort) { case sort_None: textory.addItem(Textory::Item(1, lst[i])); break; case sort_Amount: textory.addItem(Textory::Item(1, lst[i].remove(0, 6))); break; case sort_Alphabet: textory.addItem(Textory::Item(1, lst[ilimit - 1 - i])); break; } } qDebug() << "Out list: " << tm.elapsed(); tm.start(); // ПРОЦЕНТ ОСТАВЛЕННЫХ СЛОВ ОТ КОЛИЧЕСТВА ОРИГИНАЛЬНЫХ double realSort(textory.size()); double sortWithDoubles (xlsCountFull); double sortNoDoubles (freqHash.size()); QString freqStat = "/" + QString::number(long(sortNoDoubles)) + "/" + QString::number(double(realSort * 100 / sortNoDoubles), 'f', 2).remove(QRegExp("\\.00")) + "%"; cfg.textoryName += " (" + QString::number(long(sortWithDoubles)) + freqStat + ")"; ui.textoryPaneWidget->getTextoryLabel().setText( cfg.textoryName ); qDebug() << "Write name: " << tm.elapsed();}
C++ (Qt) rx.setPatternSyntax(QRegExp::Wildcard); enum { sort_Amount = 0, sort_Alphabet = 1, sort_None = 2 }; QHash<QString, int> freqHash; foreach (QString s, listFull) { if (pref.langStatSort == 3 && (s.startsWith("\t") || s.startsWith(" ") || s.startsWith("#") || s.startsWith("
C++ (Qt) QFile file( texFilename ); if ( file.open( QFile::ReadOnly | QIODevice::Text ) ) { QByteArray text = file.readAll(); Qstring originalText = text;...