<commit_before><?php
use \Httpful\Request;

class WikipediaArticle {
    const WIKIPEDIA_ENDPOINT = "%s/wikipedia/article?q=%s&lang=%s";

    private $article, $title, $lang;

    function __construct($title, $lang) {
        $this->title = $title;
        $this->lang = $lang;
        $this->article = $this->getArticle();
    }

    public function getArticleData() {
        return $this->article;
    }

    private function getArticle() {
        $url = sprintf(
            self::WIKIPEDIA_ENDPOINT,
            API_ENDPOINT,
            urlencode($this->title),
            $this->lang
        );

        $res = Request::get($url)->send();

        if (!isset($res->body->response)) {
            throw new Exception("No article available for this id");
        }

        $article = $res->body->response;

        if ($article->images) {
            $article->images = array_filter($article->images, function($img) {
                $path = pathinfo($img->title);
                $ext = strtolower($path['extension']);
                return $ext == "jpg" || $ext == "png" || $ext == "gif";
            });

            $article->images = array_values($article->images);
            $article->firstimage = !empty($article->images) ? $article->images[0] : false;
        }

        return $article;
    }
}<commit_msg>Fixed a problem for articles with images that do not have an extension<commit_after><?php
use \Httpful\Request;

class WikipediaArticle {
    const WIKIPEDIA_ENDPOINT = "%s/wikipedia/article?q=%s&lang=%s";

    private $article, $title, $lang;

    function __construct($title, $lang) {
        $this->title = $title;
        $this->lang = $lang;
        $this->article = $this->getArticle();
    }

    public function getArticleData() {
        return $this->article;
    }

    private function getArticle() {
        $url = sprintf(
            self::WIKIPEDIA_ENDPOINT,
            API_ENDPOINT,
            urlencode($this->title),
            $this->lang
        );

        $res = Request::get($url)->send();

        if (!isset($res->body->response)) {
            throw new Exception("No article available for this id");
        }

        $article = $res->body->response;

        if ($article->images) {
            $article->images = array_filter($article->images, function($img) {
                $path = pathinfo($img->title);

                if (!isset($path['extension'])) {
                    return false;
                }

                $ext = strtolower($path['extension']);

                return $ext == "jpg" || $ext == "png" || $ext == "gif";
            });

            $article->images = array_values($article->images);
            $article->firstimage = !empty($article->images) ? $article->images[0] : false;
        }

        return $article;
    }
}
{'fraction_non_alphanumeric': 0.15813788201847903, 'fraction_numerical': 0.0007107320540156361, 'mean_word_length': 1.9883227176220806, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '1346892', 'n_tokens_mistral': 822, 'n_tokens_neox': 778, 'n_words': 162}