<commit_before><?php
/**
 * PHP Speller
 *
 * @copyright 2017, <NAME> <<EMAIL>>
 * @author    <NAME> <<EMAIL>>
 * @license   http://opensource.org/licenses/MIT MIT
 */

namespace Mekras\Speller\Source;

use Mekras\Speller\Source\Filter\HtmlFilter;

/**
 * HTML document as a text source.
 *
 * @since 1.6 derived from StringSource.
 * @since 1.5
 */
class HtmlSource extends StringSource
{
    /**
     * Create text source from HTML.
     *
     * @param string $html
     *
     * @since 1.5
     */
    public function __construct($html)
    {
        $document = new \DOMDocument('1.0');
        $document->loadHTML($html);
        $filter = new HtmlFilter();
        parent::__construct($filter->filter($html), $document->encoding);
    }
}<commit_msg>HtmlSource should be derived from MetaSource<commit_after><?php
/**
 * PHP Speller
 *
 * @copyright 2017, <NAME> <<EMAIL>>
 * @author    <NAME> <<EMAIL>>
 * @license   http://opensource.org/licenses/MIT MIT
 */

namespace Mekras\Speller\Source;

use Mekras\Speller\Source\Filter\HtmlFilter;

/**
 * HTML document as a text source.
 *
 * @since x.x derived from MetaSource.
 * @since 1.6 derived from StringSource.
 * @since 1.5
 */
class HtmlSource extends MetaSource
{
    /**
     * Source text.
     *
     * @var string
     */
    private $text;

    /**
     * Text encoding.
     *
     * @var string
     */
    private $encoding;

    /**
     * Create text source from HTML.
     *
     * @param EncodingAwareSource|string $source
     *
     * @throws \Mekras\Speller\Exception\SourceException
     *
     * @since x.x Accepts EncodingAwareSource
     * @since 1.5
     *
     * @todo  deprecate string $source in version 2.0
     */
    public function __construct($source)
    {
        if (!$source instanceof EncodingAwareSource) {
            $source = new StringSource($source);
        }
        parent::__construct($source);
        $html = $this->source->getAsString();
        $document = new \DOMDocument('1.0');
        $document->loadHTML($html);
        $this->encoding = $document->encoding;
        $filter = new HtmlFilter();
        $this->text = $filter->filter($html);
    }

    /**
     * Return text as one string
     *
     * @return string
     *
     * @since 1.0
     */
    public function getAsString()
    {
        return (string) $this->text;
    }

    /**
     * Return source text encoding.
     *
     * @return string
     *
     * @since x.x
     */
    public function getEncoding()
    {
        return $this->encoding;
    }
}
{'fraction_non_alphanumeric': 0.14077287066246058, 'fraction_numerical': 0.011041009463722398, 'mean_word_length': 2.163341645885287, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, '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': '6783093', 'n_tokens_mistral': 810, 'n_tokens_neox': 791, 'n_words': 187}