C++ (Qt)struct CData { ... QHash <QStringRef, int> mFrequency; // возможно строить по запросу};
C++ (Qt) originalText.replace(QRegExp("[а-я]"), "");
C++ (Qt) originalText.replace(QRegExp("[a-z]"), "");
C++ (Qt)struct CTextAnalyzer { // имя посочнее ...private: QString mSource; QVector <QStringRef> mWord; // слова по порядку QVector <QStringRef> mFreqWord; // слова по частоте QVector <int> mFreqEntry; // индекс слова в mFreqWord};
C++ (Qt)void MainWindow::bufferButtonSave(){ QClipboard *clipboard = QApplication::clipboard(); QString originalText = clipboard->text(); QString countItemFullString; QString countItemString; QStringList itemList; int countItem(0); int countItemFull(0); originalText = originalText.toLower(); originalText.replace(QRegExp("\\W"), " "); originalText.replace(QRegExp("\\d"), " "); originalText.replace(QRegExp("_"), " "); // УБИРАЕМ РУССКИЙ originalText.replace(QRegExp(QString::fromUtf8("[а-яё]")), ""); textory.clear(); itemList = originalText.split(QRegExp("\\s+"),QString::SkipEmptyParts); QMap <QString, int> frequencyMap; foreach (QString Item, itemList) ++frequencyMap[Item]; QList<QString> frequencyList; QMapIterator<QString,int> Iter(frequencyMap); while(Iter.hasNext()) { Iter.next(); countItem = Iter.value(); countItemString.setNum(countItem); // ОРГАНИЗОВЫВАЕМ СОРТИРОВКУ if(countItem <10 )countItemString = "0000" + countItemString; if(countItem >9 && countItem <100 )countItemString = "000" + countItemString; if(countItem >99 && countItem <1000 )countItemString = "00" + countItemString; if(countItem >999 && countItem <10000 )countItemString = "0" + countItemString; countItemFull = countItemFull + countItem; frequencyList.append(countItemString + "_" + Iter.key() ); } qSort(frequencyList); textory.enableAdd( true ); QString wordItem, wordCount; foreach (QString itm, frequencyList) { wordItem = itm; wordCount = itm; wordItem.remove(0,6); wordCount.remove(5,100); wordCount.remove(QRegExp("^[0]")); wordCount.remove(QRegExp("^[0]")); wordCount.remove(QRegExp("^[0]")); wordCount.remove(QRegExp("^[0]")); textory.addItem( Textory::Item( 1, wordItem + "\t" + wordCount ) ); } countItemFullString.setNum(countItemFull); ui.textoryPaneWidget->getTextoryLabel().setText( "Frequency list (" + countItemFullString + ")" );}
C++ (Qt) // УБИРАЕМ ВСЕ КРОМЕ АНГЛИЙСКОГО originalText.replace(QRegExp(QString::fromUtf8("[a-z]")), " ");
C++ (Qt) originalText = originalText.toLower(); qDebug() << tm.elapsed(); tm.start(); // УБИРАЕМ РУССКИЙ originalText.replace(QRegExp("[^a-z]"), " "); originalText.replace(QRegExp("_"), " "); qDebug() << tm.elapsed(); tm.start(); textory.clear(); itemList = originalText.split(QRegExp("\\s+"),QString::SkipEmptyParts); QMap <QString, int> frequencyMap; foreach (QString Item, itemList) ++frequencyMap[Item]; qDebug() << tm.elapsed(); tm.start(); QList<QString> frequencyList; QMapIterator<QString,int> Iter(frequencyMap); while(Iter.hasNext()) { Iter.next(); countItem = Iter.value(); countItemString.setNum(countItem); // ОРГАНИЗОВЫВАЕМ СОРТИРОВКУ if(countItem <10 )countItemString = "0000" + countItemString; if(countItem >9 && countItem <100 )countItemString = "000" + countItemString; if(countItem >99 && countItem <1000 )countItemString = "00" + countItemString; if(countItem >999 && countItem <10000 )countItemString = "0" + countItemString; countItemFull = countItemFull + countItem; frequencyList.append(countItemString + "_" + Iter.key() ); } qDebug() << tm.elapsed(); tm.start(); qSort(frequencyList); textory.enableAdd( true ); QString wordItem, wordCount; qDebug() << tm.elapsed(); tm.start(); foreach (QString itm, frequencyList) { wordItem = itm; wordCount = itm; wordItem.remove(0,6); wordCount.remove(5,100); wordCount.remove(QRegExp("^[0]")); wordCount.remove(QRegExp("^[0]")); wordCount.remove(QRegExp("^[0]")); wordCount.remove(QRegExp("^[0]")); textory.addItem( Textory::Item( 1, wordItem + "\t" + wordCount ) ); } qDebug() << tm.elapsed();
C++ (Qt) itemList = originalText.split(QRegExp("[^a-z]"),QString::SkipEmptyParts);