Example #1
0
int main( int argc, char * argv[] )
{
    if( argc != 3 ){
        std::cerr << "Usage: " << argv[ 0 ] << " dictionary_file text_file"
            << std::endl;
        return 1;
    }

    AhoCorasick ac;

    auto const print = []( size_t const pos, std::string const & word ){
        std::cout << "> " << std::string( pos, ' ' ) << word << std::endl;
    };

    std::string line;
    std::ifstream dictFile( argv[ 1 ] );
    std::ifstream textFile( argv[ 2 ] );

    while( std::getline( dictFile, line ) ){
        ac.insert( line );
    }

    while( std::getline( textFile, line ) ){
        std::cout << "> " << line << "\n";
        ac.search( line, print );
        std::cout << std::string( 80, '-' ) << "\n";
    }
}
Example #2
0
//構築したルールを音声認識エンジンにコミットします。
xreturn::r<bool> JuliusPlus::CommitRule()
{
	if (! this->IsNeedUpdateRule )
	{//アップデートする必要なし
		return true;
	}

	//マイクから入力用
	std::ofstream dfa("__temp__regexp_test.dfa");
	std::ofstream dict("__temp__regexp_test.dict");
	this->MakeJuliusRule(this->Grammer,false, &dfa,&dict);

	//ディクテーションフィルター用
	std::ofstream dfaFile("__temp__regexp_test_file.dfa");
	std::ofstream dictFile("__temp__regexp_test_file.dict");
	this->MakeJuliusRule(this->YobikakeRuleHandle,true,&dfaFile,&dictFile);

	this->JuliusStop();
	this->JuliusFileStart();
	this->JuliusStart();

	//アップデートが終わったので再びルールに変更が加わるまではアップデートしない。
	this->IsNeedUpdateRule = false;

	return true;
}
Example #3
0
int main() {
	/*
	 * Build a lextree from text;
	 * Read the input;
	 */
	ifstream dictFile("dict_1.txt");
	root = buildTrieFromDict(dictFile);
	dictFile.close();
	cout << "正在建树..."<<endl;

	ifstream inputFile("unsegmented.txt");
	string word = "";
	string input;
	while (!inputFile.eof()) {
		getline(inputFile, input);
		word += input;
	}
	inputFile.close();
	cout << "正在分析文本....精度可到仅2个替换错误,花费时间稍微多点" <<endl;

	for (int i = 0; i < LENGTH; i++) {
		root.costTrellis[i] = INF;
		previousLength[i] = INF;
	}
	root.next[0] = NULL;
	for (int i = 0; i < (int) word.length(); i++)
		buildTrellisCol(root, word, i);

	cout << "输出到Segmented.txt" <<endl;
	string segmented;
	getSegmentedCor(transition, word, segmented);

	return 0;
}
Example #4
0
int main(int argc, char const *argv[])
{
    
    if(argc < 3 || !argv || !argv[1] || !argv[2])
    {
        std::cout << "invalid args" << std::endl;
        std::cout << "start self tests" << std::endl;
        if(!PathFinderTest())
            std::cout << "test error!" << std::endl;
        if(!ReadDataTest())
            std::cout << "test error!" << std::endl;
        return 1;
    }

    Dict dict;
    std::ifstream taskFile(argv[1]);
    std::ifstream dictFile(argv[2]);
    std::pair<unsigned, unsigned> sourceTarget = readData(taskFile, dictFile, &dict);
    if(sourceTarget.first == sourceTarget.second)
    {
        std::cout << "read files error" << std::endl;
        return 2;
    }
    
    PathFinder finder(dict);
    if(finder.find(sourceTarget.first, sourceTarget.second))
        finder.print();
    else
        std::cout << "no way from source to target" << std::endl;

    return 0;
}
Example #5
0
ASpellChecker::ASpellChecker (QTextDocument* parent) : QSyntaxHighlighter (parent)
{
	QFile file(dictFile());

	if (file.open(QIODevice::ReadOnly) == true)
	{
		QDataStream in(&file);
		in >> m_stop_words;
		file.close();
	}
int main( int argc, char **argv ) {
	if ( argc <= 1 ) {
		return EXIT_FAILURE;
	}

	// Read the word list file
	std::ifstream dictFile("/var/tmp/twl06.txt");
	std::vector<std::string> dictWordVector;
	dictWordVector.reserve(178691);
	std::string line; 
	if (dictFile.is_open()) {
		while (! dictFile.eof() ) {               
			std::getline (dictFile,line);
			trim(line);
			std::transform(line.begin(), line.end(), line.begin(), ::tolower);
			dictWordVector.push_back(line);
		}
		dictFile.close();
	} else {
		return EXIT_FAILURE;
	}

	BkTree *pDictionary = new BkTree();
	std::vector<std::string>::const_iterator itr;
	for ( itr = dictWordVector.begin(); itr != dictWordVector.end(); ++itr) {
		pDictionary->insert(*itr);
	}

	std::ifstream inHandle(argv[1]);
	std::vector<std::string> wordVector;
	while (getline(inHandle, line, '\n')) {                     
		std::istringstream iss(line);
		std::copy( std::istream_iterator<std::string>(iss), 
				std::istream_iterator<std::string>(),  
				std::back_inserter<std::vector<std::string> >(wordVector));    
	}
	inHandle.close();

	std::vector<std::string>::iterator wVecIter;
	int totalDistance = 0;
	for ( wVecIter = wordVector.begin(); wVecIter != wordVector.end(); ++wVecIter ) {
		int startDistance = 0;
		while ( true ) {
			int result = pDictionary->getWithinDistance( *wVecIter, startDistance );
			if ( result != 0 ) {
				totalDistance += startDistance;
				break;
			}
			startDistance++;
		}
	}
	std::cout << totalDistance << std::endl;
	delete pDictionary;
	return EXIT_SUCCESS;
}
Example #7
0
Web::DictInfo Web::dictInfo(const QString &dict)
{
    QString filename = workPath() + "/" + dict + ".webdict";
    if (! QFile::exists(filename))
        return DictInfo();
    QSettings dictFile(filename, QSettings::IniFormat);
    DictInfo info(name(), dict,
            dictFile.value("author").toString(),
            dictFile.value("description").toString());
    return info;
}
Example #8
0
File: web.cpp Project: KDE/mula
Web::DictionaryInfo Web::dictionaryInfo(const QString &dictionary)
{
    QString filename = pluginDataPath() + '/' + dict + ".webdict";
    if (!QFile::exists(filename))
        return DictionaryInfo();

    QSettings dictFile(filename, QSettings::IniFormat);
    DictionaryInfo info(name(), dictionary, dictionaryFile.value("author").toString(),
            dictionaryFile.value("description").toString());

    return info;
}