140 |
|
|
141 |
|
void Ranker::setSample() |
142 |
|
{ |
143 |
< |
map<unsigned, unsigned>::iterator itor; |
144 |
< |
multimap<unsigned, map<unsigned, unsigned>::iterator> distances; |
143 |
> |
map<size_t, size_t>::iterator itor; |
144 |
> |
multimap<size_t, map<size_t, size_t>::iterator> distances; |
145 |
|
|
146 |
|
for (itor = occurrencesText.begin(); itor != occurrencesText.end(); itor++) |
147 |
|
{ |
148 |
< |
unsigned distance; |
148 |
> |
size_t distance; |
149 |
|
|
150 |
|
if (++itor != occurrencesText.end()) |
151 |
|
{ |
152 |
< |
unsigned next(itor->first); |
152 |
> |
size_t next(itor->first); |
153 |
|
|
154 |
|
itor--; |
155 |
|
|
162 |
|
itor--; |
163 |
|
} |
164 |
|
|
165 |
< |
distances.insert(pair<unsigned, map<unsigned, |
166 |
< |
unsigned>::iterator>(distance, itor)); |
165 |
> |
distances.insert(pair<size_t, map<size_t, |
166 |
> |
size_t>::iterator>(distance, itor)); |
167 |
|
} |
168 |
|
|
169 |
|
if (distances.begin() != distances.end()) |
176 |
|
|
177 |
|
while (sampleLength < sampleMax && itor != occurrencesText.end()) |
178 |
|
{ |
179 |
< |
unsigned found(itor->first), length(itor->second); |
179 |
> |
size_t found(itor->first), length(itor->second); |
180 |
|
|
181 |
< |
for (unsigned index(found); index > begin; index--) |
181 |
> |
for (size_t index(found); index > begin; index--) |
182 |
|
{ |
183 |
|
if (found - index >= sampleMax - sampleLength - length) |
184 |
|
{ |
328 |
|
string title, portion; |
329 |
|
size_t begin(0); |
330 |
|
|
331 |
< |
for (map<unsigned, unsigned>::iterator itor = occurrencesTitle.begin(); |
331 |
> |
for (map<size_t, size_t>::iterator itor = occurrencesTitle.begin(); |
332 |
|
itor != occurrencesTitle.end(); itor++) |
333 |
|
{ |
334 |
< |
unsigned found(itor->first), length(itor->second); |
334 |
> |
size_t found(itor->first), length(itor->second); |
335 |
|
|
336 |
|
portion = Page::getTitle().substr(begin, found - begin); |
337 |
|
|
369 |
|
string Ranker::getDescription() |
370 |
|
{ |
371 |
|
string description, portion; |
372 |
< |
unsigned begin(0); |
372 |
> |
size_t begin(0); |
373 |
|
|
374 |
< |
for (map<unsigned, unsigned>::iterator itor = |
374 |
> |
for (map<size_t, size_t>::iterator itor = |
375 |
|
occurrencesDescription.begin(); itor != occurrencesDescription.end(); |
376 |
|
itor++) |
377 |
|
{ |
378 |
< |
unsigned found(itor->first), length(itor->second); |
378 |
> |
size_t found(itor->first), length(itor->second); |
379 |
|
|
380 |
|
portion = Page::getDescription().substr(begin, found - begin); |
381 |
|
|
410 |
|
return description; |
411 |
|
} |
412 |
|
|
413 |
< |
bool Ranker::operator==(const unsigned number) const |
413 |
> |
bool Ranker::operator==(const size_t number) const |
414 |
|
{ |
415 |
|
return value == number; |
416 |
|
} |
420 |
|
return value == ranker.value; |
421 |
|
} |
422 |
|
|
423 |
< |
bool Ranker::operator!=(const unsigned number) const |
423 |
> |
bool Ranker::operator!=(const size_t number) const |
424 |
|
{ |
425 |
|
return value != number; |
426 |
|
} |
430 |
|
return value != ranker.value; |
431 |
|
} |
432 |
|
|
433 |
< |
bool Ranker::operator<(const unsigned number) const |
433 |
> |
bool Ranker::operator<(const size_t number) const |
434 |
|
{ |
435 |
|
return value < number; |
436 |
|
} |
440 |
|
return value < ranker.value; |
441 |
|
} |
442 |
|
|
443 |
< |
bool Ranker::operator>(const unsigned number) const |
443 |
> |
bool Ranker::operator>(const size_t number) const |
444 |
|
{ |
445 |
|
return value > number; |
446 |
|
} |
503 |
|
{ |
504 |
|
string lowerDescription(tolower(Page::getDescription())); |
505 |
|
|
506 |
< |
for (unsigned index(0); index < required.size(); index++) |
506 |
> |
for (size_t index(0); index < required.size(); index++) |
507 |
|
{ |
508 |
|
if (required[index].find("URL ") == 0) |
509 |
|
{ |
527 |
|
} |
528 |
|
} |
529 |
|
|
530 |
< |
for (unsigned index1(0); index1 < eitherOr.size(); index1++) |
530 |
> |
for (size_t index1(0); index1 < eitherOr.size(); index1++) |
531 |
|
{ |
532 |
|
vector<string> words; |
533 |
< |
unsigned begin(0), found; |
533 |
> |
size_t begin(0), found; |
534 |
|
|
535 |
|
do |
536 |
|
{ |
551 |
|
while (begin < eitherOr[index1].length() && found != |
552 |
|
string::npos); |
553 |
|
|
554 |
< |
for (unsigned number(0); number < words.size(); number++) |
554 |
> |
for (size_t number(0); number < words.size(); number++) |
555 |
|
{ |
556 |
|
if (words[index1].find("URL ") == 0) |
557 |
|
{ |
576 |
|
} |
577 |
|
} |
578 |
|
|
579 |
< |
for (unsigned index2(0); index2 < getHeadings().size(); index2++) |
579 |
> |
for (size_t index2(0); index2 < getHeadings().size(); index2++) |
580 |
|
{ |
581 |
|
string lowerHeading = string(getHeadings()[index2].length(), |
582 |
|
' '); |
583 |
|
|
584 |
< |
for (unsigned number(0); number < |
584 |
> |
for (size_t number(0); number < |
585 |
|
getHeadings()[index2].length(); number++) |
586 |
|
{ |
587 |
|
lowerHeading[number] = tolower( |
588 |
|
getHeadings()[index2][number]); |
589 |
|
} |
590 |
|
|
591 |
< |
for (unsigned number0(0); number0 < required.size(); number0++) |
591 |
> |
for (size_t number0(0); number0 < required.size(); number0++) |
592 |
|
{ |
593 |
|
if (required[number0].find("URL ") == 0) |
594 |
|
{ |
611 |
|
} |
612 |
|
} |
613 |
|
|
614 |
< |
for (unsigned number1(0); number1 < eitherOr.size(); number1++) |
614 |
> |
for (size_t number1(0); number1 < eitherOr.size(); number1++) |
615 |
|
{ |
616 |
|
vector<string> words; |
617 |
< |
unsigned begin(0), found; |
617 |
> |
size_t begin(0), found; |
618 |
|
|
619 |
|
do |
620 |
|
{ |
635 |
|
while (begin < eitherOr[number1].length() && found != |
636 |
|
string::npos); |
637 |
|
|
638 |
< |
for (unsigned number(0); number < words.size(); number++) |
638 |
> |
for (size_t number(0); number < words.size(); number++) |
639 |
|
{ |
640 |
|
if (words[number].find("URL ") == 0) |
641 |
|
{ |
665 |
|
|
666 |
|
void Ranker::checkRequired() |
667 |
|
{ |
668 |
< |
vector<unsigned> inURLs, inTitles, inTexts; |
668 |
> |
vector<size_t> inURLs, inTitles, inTexts; |
669 |
|
|
670 |
< |
for (unsigned index(0); index < required.size(); index++) |
670 |
> |
for (size_t index(0); index < required.size(); index++) |
671 |
|
{ |
672 |
< |
unsigned inURL(0), inTitle(0), inText(0); |
672 |
> |
size_t inURL(0), inTitle(0), inText(0); |
673 |
|
|
674 |
|
if (required[index].find("URL ") == 0) |
675 |
|
{ |
728 |
|
inTexts.push_back(inText); |
729 |
|
} |
730 |
|
|
731 |
< |
unsigned inURL(evaluate(inURLs)), inTitle(evaluate(inTitles)), |
731 |
> |
size_t inURL(evaluate(inURLs)), inTitle(evaluate(inTitles)), |
732 |
|
inText(evaluate(inTexts)); |
733 |
|
|
734 |
|
requiredValue += (inURL && (allIn == url)) || (inTitle && (allIn == title)) |
738 |
|
|
739 |
|
void Ranker::checkExcluded() |
740 |
|
{ |
741 |
< |
vector<unsigned> inURLs, inTitles, inTexts; |
741 |
> |
vector<size_t> inURLs, inTitles, inTexts; |
742 |
|
|
743 |
< |
for (unsigned index(0); index < excluded.size(); index++) |
743 |
> |
for (size_t index(0); index < excluded.size(); index++) |
744 |
|
{ |
745 |
< |
unsigned inURL(0), inTitle(0), inText(0); |
745 |
> |
size_t inURL(0), inTitle(0), inText(0); |
746 |
|
|
747 |
|
inURL = find(excluded[index], lowerURL.substr(7)); |
748 |
|
inTitle = find(excluded[index], lowerTitle); |
753 |
|
inTexts.push_back(inText); |
754 |
|
} |
755 |
|
|
756 |
< |
unsigned inURL(evaluate(inURLs)), inTitle = evaluate(inTitles), |
756 |
> |
size_t inURL(evaluate(inURLs)), inTitle = evaluate(inTitles), |
757 |
|
inText(evaluate(inTexts)); |
758 |
|
|
759 |
|
excludedValue += (inURL && (allIn == url)) || (inTitle && (allIn == title)) |
763 |
|
|
764 |
|
void Ranker::checkEitherOr() |
765 |
|
{ |
766 |
< |
vector<unsigned> inURLs, inTitles, inTexts; |
766 |
> |
vector<size_t> inURLs, inTitles, inTexts; |
767 |
|
|
768 |
< |
for (unsigned index(0); index < eitherOr.size(); index++) |
768 |
> |
for (size_t index(0); index < eitherOr.size(); index++) |
769 |
|
{ |
770 |
< |
vector<unsigned> inURLz, inTitlez, inTextz; |
771 |
< |
unsigned inURL(0), inTitle(0), inText(0); |
770 |
> |
vector<size_t> inURLz, inTitlez, inTextz; |
771 |
> |
size_t inURL(0), inTitle(0), inText(0); |
772 |
|
vector<string> words; |
773 |
< |
unsigned begin(0), found; |
773 |
> |
size_t begin(0), found; |
774 |
|
|
775 |
|
do |
776 |
|
{ |
789 |
|
} |
790 |
|
while (begin < eitherOr[index].length() && found != string::npos); |
791 |
|
|
792 |
< |
for (unsigned number(0); number < words.size(); number++) |
792 |
> |
for (size_t number(0); number < words.size(); number++) |
793 |
|
{ |
794 |
< |
unsigned inURL(0), inTitle(0), inText(0); |
794 |
> |
size_t inURL(0), inTitle(0), inText(0); |
795 |
|
|
796 |
|
if (words[number].find("URL ") == 0) |
797 |
|
{ |
850 |
|
inTextz.push_back(inText); |
851 |
|
} |
852 |
|
|
853 |
< |
for (unsigned number0(0); number0 < inURLz.size(); number0++) |
853 |
> |
for (size_t number0(0); number0 < inURLz.size(); number0++) |
854 |
|
{ |
855 |
|
inURL += inURLz[number0]; |
856 |
|
} |
857 |
|
|
858 |
< |
for (unsigned number1(0); number1 < inTitlez.size(); number1++) |
858 |
> |
for (size_t number1(0); number1 < inTitlez.size(); number1++) |
859 |
|
{ |
860 |
|
inTitle += inTitlez[number1]; |
861 |
|
} |
862 |
|
|
863 |
< |
for (unsigned number2(0); number2 < inTextz.size(); number2++) |
863 |
> |
for (size_t number2(0); number2 < inTextz.size(); number2++) |
864 |
|
{ |
865 |
|
inText += inTextz[number2]; |
866 |
|
} |
875 |
|
words.clear(); |
876 |
|
} |
877 |
|
|
878 |
< |
unsigned inURL(evaluate(inURLs)), inTitle = evaluate(inTitles), |
878 |
> |
size_t inURL(evaluate(inURLs)), inTitle = evaluate(inTitles), |
879 |
|
inText(evaluate(inTexts)); |
880 |
|
|
881 |
|
eitherOrValue += (inURL && (allIn == url)) || (inTitle && (allIn == title)) |
883 |
|
inText : 0; |
884 |
|
} |
885 |
|
|
886 |
< |
unsigned Ranker::find(string word, const string& where) |
886 |
> |
size_t Ranker::find(string word, const string& where) |
887 |
|
{ |
888 |
< |
unsigned value(0); |
888 |
> |
size_t value(0); |
889 |
|
|
890 |
|
decrap(word); |
891 |
|
|
896 |
|
} |
897 |
|
else if (word.find_first_of(" \n\t") == string::npos) |
898 |
|
{ |
899 |
< |
unsigned begin(0), found; |
899 |
> |
size_t begin(0), found; |
900 |
|
|
901 |
|
do |
902 |
|
{ |
930 |
|
return value; |
931 |
|
} |
932 |
|
|
933 |
< |
unsigned Ranker::find(string word, const string& where, map<unsigned, |
934 |
< |
unsigned>& occurrences) |
933 |
> |
size_t Ranker::find(string word, const string& where, map<size_t, |
934 |
> |
size_t>& occurrences) |
935 |
|
{ |
936 |
< |
unsigned value(0); |
936 |
> |
size_t value(0); |
937 |
|
|
938 |
|
decrap(word); |
939 |
|
|
944 |
|
} |
945 |
|
else if (word.find_first_of(" \n ") == string::npos) |
946 |
|
{ |
947 |
< |
unsigned begin(0), found; |
947 |
> |
size_t begin(0), found; |
948 |
|
|
949 |
|
do |
950 |
|
{ |
964 |
|
{ |
965 |
|
value++; |
966 |
|
|
967 |
< |
occurrences.insert(pair<unsigned, unsigned>(found, |
967 |
> |
occurrences.insert(pair<size_t, size_t>(found, |
968 |
|
word.length())); |
969 |
|
} |
970 |
|
} |
981 |
|
return value; |
982 |
|
} |
983 |
|
|
984 |
< |
unsigned Ranker::phrase(const string& phrase, const string& where) |
984 |
> |
size_t Ranker::phrase(const string& phrase, const string& where) |
985 |
|
{ |
986 |
< |
unsigned value(0); |
986 |
> |
size_t value(0); |
987 |
|
vector<string> words; |
988 |
< |
unsigned begin(0), space; |
988 |
> |
size_t begin(0), space; |
989 |
|
|
990 |
|
do |
991 |
|
{ |
999 |
|
|
1000 |
|
begin = 0; |
1001 |
|
|
1002 |
< |
unsigned counter(0); |
1002 |
> |
size_t counter(0); |
1003 |
|
|
1004 |
|
do |
1005 |
|
{ |
1010 |
|
return value; |
1011 |
|
} |
1012 |
|
|
1013 |
< |
unsigned Ranker::phrase(const string& phrase, const string& where, |
1014 |
< |
map<unsigned, unsigned>& occurrences) |
1013 |
> |
size_t Ranker::phrase(const string& phrase, const string& where, |
1014 |
> |
map<size_t, size_t>& occurrences) |
1015 |
|
{ |
1016 |
< |
unsigned value(0); |
1016 |
> |
size_t value(0); |
1017 |
|
vector<string> words; |
1018 |
< |
unsigned begin(0), space; |
1018 |
> |
size_t begin(0), space; |
1019 |
|
|
1020 |
|
do |
1021 |
|
{ |
1038 |
|
return value; |
1039 |
|
} |
1040 |
|
|
1041 |
< |
unsigned Ranker::phrase(const vector<string>& words, unsigned word, unsigned& |
1041 |
> |
size_t Ranker::phrase(const vector<string>& words, size_t word, size_t& |
1042 |
|
begin, bool start, const string& where) |
1043 |
|
{ |
1044 |
< |
unsigned value(0); |
1044 |
> |
size_t value(0); |
1045 |
|
bool end(!(word + 1 < words.size())); |
1046 |
< |
unsigned found(where.find(words[word], begin)), newBegin(found + |
1046 |
> |
size_t found(where.find(words[word], begin)), newBegin(found + |
1047 |
|
words[word].length()); |
1048 |
|
|
1049 |
|
if (found != string::npos) |
1062 |
|
|
1063 |
|
if (!start) |
1064 |
|
{ |
1065 |
< |
for (unsigned index = begin + 1; index < found - 1; index++) |
1065 |
> |
for (size_t index = begin + 1; index < found - 1; index++) |
1066 |
|
{ |
1067 |
|
if (isalnum(where[index])) |
1068 |
|
{ |
1102 |
|
return value; |
1103 |
|
} |
1104 |
|
|
1105 |
< |
unsigned Ranker::phrase(const vector<string>& words, unsigned word, unsigned& |
1106 |
< |
begin, bool start, const string& where, map<unsigned, unsigned>& |
1105 |
> |
size_t Ranker::phrase(const vector<string>& words, size_t word, size_t& |
1106 |
> |
begin, bool start, const string& where, map<size_t, size_t>& |
1107 |
|
occurrences) |
1108 |
|
{ |
1109 |
< |
unsigned value(0); |
1109 |
> |
size_t value(0); |
1110 |
|
bool end(!(word + 1 < words.size())); |
1111 |
< |
unsigned found(where.find(words[word], begin)), newBegin(found + |
1111 |
> |
size_t found(where.find(words[word], begin)), newBegin(found + |
1112 |
|
words[word].length()); |
1113 |
|
|
1114 |
|
if (found != string::npos) |
1127 |
|
|
1128 |
|
if (!start) |
1129 |
|
{ |
1130 |
< |
for (unsigned index = begin + 1; index < found - 1; index++) |
1130 |
> |
for (size_t index = begin + 1; index < found - 1; index++) |
1131 |
|
{ |
1132 |
|
if (isalnum(where[index])) |
1133 |
|
{ |
1139 |
|
|
1140 |
|
if (between) |
1141 |
|
{ |
1142 |
< |
occurrences.insert(pair<unsigned, unsigned>(found, |
1142 |
> |
occurrences.insert(pair<size_t, size_t>(found, |
1143 |
|
words[word].length())); |
1144 |
|
|
1145 |
|
if (end) |
1171 |
|
return value; |
1172 |
|
} |
1173 |
|
|
1174 |
< |
unsigned Ranker::evaluate(vector<unsigned>& ins) |
1174 |
> |
size_t Ranker::evaluate(vector<size_t>& ins) |
1175 |
|
{ |
1176 |
< |
unsigned in(0); |
1176 |
> |
size_t in(0); |
1177 |
|
|
1178 |
< |
for (unsigned index(0); index < ins.size(); index++) |
1178 |
> |
for (size_t index(0); index < ins.size(); index++) |
1179 |
|
{ |
1180 |
|
if (ins[index] > 0) |
1181 |
|
{ |
1193 |
|
|
1194 |
|
void Ranker::decrap(string& crap) |
1195 |
|
{ |
1196 |
< |
unsigned begin(0), found; |
1196 |
> |
size_t begin(0), found; |
1197 |
|
|
1198 |
|
do |
1199 |
|
{ |