<commit_before><?php

namespace QueryTranslator\Tests\Galach\Tokenizer;

use PHPUnit\Framework\TestCase;
use QueryTranslator\Languages\Galach\TokenExtractor;
use QueryTranslator\Languages\Galach\Tokenizer;

/**
 * Text case for TokenExtractor.
 */
class TokenExtractorTest extends TestCase
{
    /**
     * @expectedException \RuntimeException
     * @expectedExceptionMessage PCRE regex error code: 2
     */
    public function testExtractThrowsException()
    {
        /** @var \QueryTranslator\Languages\Galach\TokenExtractor|\PHPUnit_Framework_MockObject_MockObject $extractor */
        $extractor = $this->getMockBuilder(TokenExtractor::class)
            ->setMethods(['getExpressionTypeMap'])
            ->getMockForAbstractClass();

        $extractor->expects($this->once())
            ->method('getExpressionTypeMap')
            ->willReturn(
                [
                    '/(?:\D+|<\d+>)*[!?]/' => Tokenizer::TOKEN_WHITESPACE,
                ]
            );

        $extractor->extract('foobar foobar foobar', 0);
    }
}
<commit_msg>Test exception on creating term Token<commit_after><?php

namespace QueryTranslator\Tests\Galach\Tokenizer;

use PHPUnit\Framework\TestCase;
use QueryTranslator\Languages\Galach\TokenExtractor;
use QueryTranslator\Languages\Galach\TokenExtractor\Full;
use QueryTranslator\Languages\Galach\TokenExtractor\Text;
use QueryTranslator\Languages\Galach\Tokenizer;

/**
 * Text case for TokenExtractor.
 */
class TokenExtractorTest extends TestCase
{
    /**
     * @expectedException \RuntimeException
     * @expectedExceptionMessage PCRE regex error code: 2
     */
    public function testExtractThrowsExceptionPCRE()
    {
        /** @var \QueryTranslator\Languages\Galach\TokenExtractor|\PHPUnit_Framework_MockObject_MockObject $extractor */
        $extractor = $this->getMockBuilder(TokenExtractor::class)
            ->setMethods(['getExpressionTypeMap'])
            ->getMockForAbstractClass();

        $extractor->expects($this->once())
            ->method('getExpressionTypeMap')
            ->willReturn(
                [
                    '/(?:\D+|<\d+>)*[!?]/' => Tokenizer::TOKEN_WHITESPACE,
                ]
            );

        $extractor->extract('foobar foobar foobar', 0);
    }

    /**
     * @expectedException \RuntimeException
     * @expectedExceptionMessage Could not extract term token from the given data
     */
    public function testFullExtractTermTokenThrowsException()
    {
        $extractor = new Full();
        $reflectedClass = new \ReflectionClass($extractor);
        $reflectedProperty = $reflectedClass->getProperty('expressionTypeMap');
        $reflectedProperty->setAccessible(true);
        $reflectedProperty->setValue(
            [
                '/(?<lexeme>foobar)/' => Tokenizer::TOKEN_TERM,
            ]
        );

        $extractor->extract('foobar', 0);
    }

    /**
     * @expectedException \RuntimeException
     * @expectedExceptionMessage Could not extract term token from the given data
     */
    public function testTextExtractTermTokenThrowsException()
    {
        $extractor = new Text();
        $reflectedClass = new \ReflectionClass($extractor);
        $reflectedProperty = $reflectedClass->getProperty('expressionTypeMap');
        $reflectedProperty->setAccessible(true);
        $reflectedProperty->setValue(
            [
                '/(?<lexeme>foobar)/' => Tokenizer::TOKEN_TERM,
            ]
        );

        $extractor->extract('foobar', 0);
    }
}

{'fraction_non_alphanumeric': 0.1217985202048947, 'fraction_numerical': 0.001707455890722823, 'mean_word_length': 2.7393617021276597, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, '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': '2358669', 'n_tokens_mistral': 1004, 'n_tokens_neox': 973, 'n_words': 155}