Ejemplo n.º 1
0
void gc_paragraph_to_cache(voikko_options_t * voikkoOptions, const wchar_t * text, size_t textlen) {
	gc_clear_cache(voikkoOptions);
	voikkoOptions->gc_cache.paragraph = new wchar_t[textlen + 1];
	if (!voikkoOptions->gc_cache.paragraph) {
		return;
	}
	memcpy(voikkoOptions->gc_cache.paragraph, text, textlen * sizeof(wchar_t));
	voikkoOptions->gc_cache.paragraph[textlen] = L'\0';
	Paragraph * para = gc_analyze_paragraph(voikkoOptions, text, textlen);
	if (!para) {
		return;
	}
	
	// If paragraph is a single sentence without any whitespace, do not try to
	// do grammar checking on it. This could be an URL or something equally
	// strange.
	if (para->sentenceCount == 1) {
		Sentence * sentence = para->sentences[0];
		bool hasWhitespace = false;
		for (size_t i = 0; i < sentence->tokenCount; i++) {
			if (sentence->tokens[i].type == TOKEN_WHITESPACE) {
				hasWhitespace = true;
				break;
			}
		}
		if (!hasWhitespace) {
			// If this is a single word sentence, we should check it, otherwise
			// it makes no sense to try.
			if (sentence->tokenCount > 2 || sentence->tokenCount == 0 ||
			    sentence->tokens[0].type != TOKEN_WORD) {
				delete para;
				return;
			}
		}
	}
	
	check::CapitalizationCheck capitalizationCheck;
	check::NegativeVerbCheck negativeVerbCheck;
	check::CompoundVerbCheck compoundVerbCheck;
	check::SidesanaCheck sidesanaCheck;
	check::MissingVerbCheck missingVerbCheck;
	for (size_t i = 0; i < para->sentenceCount; i++) {
#ifdef HAVE_MALAGA
		// TODO: Autocorrect data should be moved to a separate data file (VFST) in
		// later format revisions. Old implementation is only available to support
		// v2 dictionary format.
		AutoCorrect::autoCorrect(voikkoOptions, para->sentences[i]);
#endif
		gc_local_punctuation(voikkoOptions, para->sentences[i]);
		gc_punctuation_of_quotations(voikkoOptions, para->sentences[i]);
		gc_repeating_words(voikkoOptions, para->sentences[i]);
		negativeVerbCheck.check(voikkoOptions, para->sentences[i]);
		compoundVerbCheck.check(voikkoOptions, para->sentences[i]);
		sidesanaCheck.check(voikkoOptions, para->sentences[i]);
		missingVerbCheck.check(voikkoOptions, para->sentences[i]);
	}
	capitalizationCheck.check(voikkoOptions, para);
	gc_end_punctuation(voikkoOptions, para);
	delete para;
}
Ejemplo n.º 2
0
void FinnishRuleEngine::check(const Paragraph * paragraph) {
	std::list<check::SentenceCheck *>::const_iterator sentenceCheckIt;
	for (size_t i = 0; i < paragraph->sentenceCount; i++) {
#ifdef HAVE_MALAGA
		if (voikkoOptions->dictionary.getGrammarBackend().getBackend() == "finnish") {
			libvoikko::autocorrect::AutoCorrect::autoCorrect(voikkoOptions, paragraph->sentences[i]);
		}
#endif
		gc_local_punctuation(voikkoOptions, paragraph->sentences[i]);
		gc_punctuation_of_quotations(voikkoOptions, paragraph->sentences[i]);
		gc_repeating_words(voikkoOptions, paragraph->sentences[i]);
		sentenceCheckIt = sentenceChecks.begin();
		for (; sentenceCheckIt != sentenceChecks.end(); ++sentenceCheckIt) {
			(*sentenceCheckIt)->check(voikkoOptions, paragraph->sentences[i]);
		}

	}


	capitalizationCheck.check(voikkoOptions, paragraph);
	gc_end_punctuation(voikkoOptions, paragraph);

}