示例#1
0
extern void reference_create(reference_map *map, chunk *label, chunk *url, chunk *title)
{
	reference *ref;
	unsigned char *reflabel = normalize_reference(label);

	/* empty reference name, or composed from only whitespace */
	if (reflabel == NULL)
		return;

	ref = calloc(1, sizeof(*ref));
	if(ref != NULL) {
		ref->label = reflabel;
		ref->hash = refhash(ref->label);
		ref->url = clean_url(url);
		ref->title = clean_title(title);
		ref->next = NULL;

		add_reference(map, ref);
	}
}
示例#2
0
bool KeywordFinder::findNextElement(const std::string& title, Element& foundElement) const {

	int foundPower = 0;
	std::string::size_type keywordsSize = 0;
	std::string::size_type index;

	if(title.size() < min_title_length)
	{
		return false;
	}

	std::string clean_title(title);
	clean_text(clean_title);

	for (TokenArray::const_iterator itKeywords = tokens.begin(); itKeywords != tokens.end(); ++itKeywords) {

		if ((index = clean_title.find(*itKeywords)) != std::string::npos
				&& points_to_word(clean_title, index, itKeywords->size())) {

			foundPower++;
			keywordsSize += itKeywords->length();
		}
	}

	if (foundPower > 0 && keywordsSize >= min_title_length) {

		const std::string::size_type max_length = myKeyword.length() < title.length() ? title.length() : myKeyword.length();

		keywordsSize = 100 - max_length + keywordsSize + foundPower - 1;

		if (foundElement.power < foundPower
				|| (foundElement.power == foundPower && keywordsSize > foundElement.KeywordsDiff)) {

			foundElement.power = foundPower;
			foundElement.KeywordsDiff = keywordsSize;
			return true;
		}
	}

	return false;
}