<commit_before><?php

namespace allejo\stakx\Twig;

use Twig_Environment;
use Twig_Extension;
use Twig_SimpleFilter;

/**
 * This file is part of Twig.
 *
 * (c) 2009 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author <NAME> <<EMAIL>>
 */
class TextExtension extends Twig_Extension
{
    /**
     * Returns a list of filters.
     *
     * @return Twig_SimpleFilter[]
     */
    public function getFilters()
    {
        return array(
            new Twig_SimpleFilter('summary', array($this, 'twig_summary_filter')),
            new Twig_SimpleFilter('truncate', array($this, 'twig_truncate_filter'), array('needs_environment' => true)),
            new Twig_SimpleFilter('wordwrap', array($this, 'twig_wordwrap_filter'), array('needs_environment' => true)),
        );
    }

    /**
     * Name of this extension.
     *
     * @return string
     */
    public function getName()
    {
        return 'Text';
    }

    public function twig_summary_filter($value, $paragraphCount = 1)
    {
        if (function_exists('simplexml_load_string'))
        {
            $content = simplexml_load_string('<html>' . $value . '</html>');
            $count = min($paragraphCount, $content->count());
            $children = $content->children();

            $summary = '';

            for ($i = 0; $i < $count; ++$i)
            {
                $summary .= $children[$i]->asXml();
            }

            return $summary;
        }

        return $value;
    }
<commit_msg>SummaryFilter: Fix when XML parsing fails<commit_after><?php

namespace allejo\stakx\Twig;

use Twig_Environment;
use Twig_Extension;
use Twig_SimpleFilter;

/**
 * This file is part of Twig.
 *
 * (c) 2009 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author <NAME> <<EMAIL>>
 */
class TextExtension extends Twig_Extension
{
    /**
     * Returns a list of filters.
     *
     * @return Twig_SimpleFilter[]
     */
    public function getFilters()
    {
        return array(
            new Twig_SimpleFilter('summary', array($this, 'twig_summary_filter')),
            new Twig_SimpleFilter('truncate', array($this, 'twig_truncate_filter'), array('needs_environment' => true)),
            new Twig_SimpleFilter('wordwrap', array($this, 'twig_wordwrap_filter'), array('needs_environment' => true)),
        );
    }

    /**
     * Name of this extension.
     *
     * @return string
     */
    public function getName()
    {
        return 'Text';
    }

    public function twig_summary_filter($value, $paragraphCount = 1)
    {
        if (function_exists('simplexml_load_string'))
        {
            $content = simplexml_load_string('<html>' . $value . '</html>');

            if ($content === false)
            {
                return $value;
            }

            $count = min($paragraphCount, $content->count());
            $children = $content->children();

            $summary = '';

            for ($i = 0; $i < $count; ++$i)
            {
                $summary .= $children[$i]->asXml();
            }

            return $summary;
        }

        return $value;
    }

{'fraction_non_alphanumeric': 0.1329479768786127, 'fraction_numerical': 0.0036507453605111044, 'mean_word_length': 2.186046511627907, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '117527', 'n_tokens_mistral': 976, 'n_tokens_neox': 941, 'n_words': 234}