<commit_before>//! \file Article.cpp

#include "Article.h"

#include <algorithm>

#include "WalkerException.h"

namespace WikiWalker
{
  size_t Article::countLinks() const
  {
    if(!analyzed_ && links_.empty()) {
      throw WalkerException("Article not analyzed yet!");
    }

    return links_.size();
  }

  Article::ArticleLinkConstIterator Article::linkBegin() const
  {
    return links_.cbegin();
  }

  Article::ArticleLinkConstIterator Article::linkEnd() const
  {
    return links_.cend();
  }

  bool Article::addLink(const std::weak_ptr<const Article> article)
  {
    auto newTitle = article.lock()->title();

    // check for duplicates using title
    //! \todo Or rather compare pointers again?
    bool isNewLink =
        std::none_of(links_.cbegin(),
                     links_.cend(),
                     [&newTitle](const std::weak_ptr<const Article> x) {
                       return x.lock()->title() == newTitle;
                     });

    if(isNewLink) {
      links_.push_back(article);
      analyzed_ = true;
    }

    return isNewLink;
  }

  void Article::analyzed(bool analyzed)
  {
    analyzed_ = analyzed;
  }

  bool Article::analyzed() const
  {
    return analyzed_;
  }

  void Article::marked(bool marked)
  {
    marked_ = marked;
  }

  bool Article::marked() const
  {
    return marked_;
  }
}  // namespace WikiWalker<commit_msg>Fix nullptr access in article class<commit_after>//! \file Article.cpp

#include "Article.h"

#include <algorithm>

#include "WalkerException.h"

namespace WikiWalker
{
  size_t Article::countLinks() const
  {
    if(!analyzed_ && links_.empty()) {
      throw WalkerException("Article not analyzed yet!");
    }

    return links_.size();
  }

  Article::ArticleLinkConstIterator Article::linkBegin() const
  {
    return links_.cbegin();
  }

  Article::ArticleLinkConstIterator Article::linkEnd() const
  {
    return links_.cend();
  }

  bool Article::addLink(const std::weak_ptr<const Article> article)
  {
    auto newTitle = article.lock()->title();

    // check for duplicates using title
    //! \todo Or rather compare pointers again?
    bool isNewLink =
        std::none_of(links_.cbegin(),
                     links_.cend(),
                     [&newTitle](const std::weak_ptr<const Article> x) {
                       auto p = x.lock();
                       return p == nullptr ? false : p->title() == newTitle;
                     });

    if(isNewLink) {
      links_.push_back(article);
      analyzed_ = true;
    }

    return isNewLink;
  }

  void Article::analyzed(bool analyzed)
  {
    analyzed_ = analyzed;
  }

  bool Article::analyzed() const
  {
    return analyzed_;
  }

  void Article::marked(bool marked)
  {
    marked_ = marked;
  }

  bool Article::marked() const
  {
    return marked_;
  }
}  // namespace WikiWalker
{'fraction_non_alphanumeric': 0.12517580872011252, 'fraction_numerical': 0.0, 'mean_word_length': 2.4907975460122698, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1252167', 'n_tokens_mistral': 888, 'n_tokens_neox': 830, 'n_words': 192}