Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<string> SplitIntoWords(const string_view text) {
- vector<string> words;
- string word;
- for (const char c : text) {
- if (c == ' ') {
- if (!word.empty()) {
- words.push_back(word);
- word.clear();
- }
- } else {
- word += c;
- }
- }
- if (!word.empty()) {
- words.push_back(word);
- }
- return words;
- }
- vector<string_view> SearchServer::SplitIntoWordsNoStop(const string_view text) const {
- vector<string_view> words;
- for (const string_view word : SplitIntoWords(text)) {
- if (!IsStopWord(word)) {
- words.push_back(word);
- }
- cout << "word_SplitIntoWordsNoStop = " << word << endl;
- }
- return words;
- }
- void SearchServer::AddDocument(int document_id, const string_view document, DocumentStatus status,
- const vector<int>& ratings) {
- if (documents_.count(document_id) > 0) {
- throw invalid_argument("Документ с таким id уже существует."s);
- }
- else if (document_id < 0) {
- throw invalid_argument("Документ не может иметь отрицательный id."s);
- }
- else if (!IsValidWord(document)) {
- throw invalid_argument("Содержимое документа содержит недопустимые символы"s);
- }
- const vector<string_view> words = SplitIntoWordsNoStop(document);
- //words_in_documents_[document_id] = words;
- const double inv_word_count = 1.0 / words.size();
- for (const string_view word : words) {
- cout << "word_ADD = " << word << endl;
- word_to_document_freqs_[string(word)][document_id] += inv_word_count;
- //words_in_documents_[document_id].push_back(word);
- word_frequencies_in_document_[document_id][word] += inv_word_count;
- }
- documents_.emplace(document_id, DocumentData{ ComputeAverageRating(ratings), status });
- order_addition_document_.insert(document_id);
- }
Advertisement
Add Comment
Please, Sign In to add comment