<commit_before><?php

require __DIR__ . '/../vendor/autoload.php';

use Pragmatist\Regel\Action\CallableAction;
use Pragmatist\Regel\Action\CallableActionExecutor;
use Pragmatist\Regel\Condition\ExpressionLanguageCondition;
use Pragmatist\Regel\Condition\ExpressionLanguageEvaluator;
use Pragmatist\Regel\Engine\ActionEngine;
use Pragmatist\Regel\Rule\ActionableRule;
use Pragmatist\Regel\RuleSet\ArrayRuleSet;
use Pragmatist\Regel\RuleSetProvider\InMemoryRuleSetProvider;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

// Our example domain object
class EmailMessage
{
    public $subject = 'My message';
    public $body = 'My very IMPORTANT message';
}


// Set up our RuleSet and provider. Normally in your DI container.
$ruleSetProvider = new InMemoryRuleSetProvider();
$ruleSetProvider->addRuleSet(
    'email-ruleset',
    new ArrayRuleSet(
        [
            new ActionableRule(
                ExpressionLanguageCondition::fromString("subject.body matches '/IMPORTANT/'"),
                new CallableAction(
                    function ($subject) {
                        echo "E-mail '{$subject->subject}' is important!'\n";
                    }
                )
            )
        ]
    )
);


// Set up the RuleEngine. Also normally in your DI container.
$engine = new ActionEngine(
    $ruleSetProvider,
    new ExpressionLanguageEvaluator(new ExpressionLanguage()),
    new CallableActionExecutor()
);


// Apply the ruleset to a subject
$subject = new EmailMessage();
$engine->applyRuleSetToSubject('email-ruleset', $subject);<commit_msg>Removed Symfony Expression Language from example<commit_after><?php

require __DIR__ . '/../vendor/autoload.php';

use Pragmatist\Regel\Action\CallableAction;
use Pragmatist\Regel\Action\CallableActionExecutor;
use Pragmatist\Regel\Condition\CallableCondition;
use Pragmatist\Regel\Condition\CallableEvaluator;
use Pragmatist\Regel\Engine\ActionEngine;
use Pragmatist\Regel\Rule\ActionableRule;
use Pragmatist\Regel\RuleSet\ArrayRuleSet;
use Pragmatist\Regel\RuleSetProvider\InMemoryRuleSetProvider;

// Our example domain object
class EmailMessage
{
    public $subject = 'My message';
    public $body = 'My very IMPORTANT message';
}


// Set up our RuleSet provider. Normally in your DI container.
$ruleSetProvider = new InMemoryRuleSetProvider();
$ruleSetProvider->addRuleSet(
    'email-ruleset',
    new ArrayRuleSet(
        [
            new ActionableRule(
                new CallableCondition(function($subject) { return preg_match('/important/i', $subject->body); }),
                new CallableAction(
                    function ($subject) {
                        echo "E-mail '{$subject->subject}' is important!'\n";
                    }
                )
            )
        ]
    )
);


// Set up the RuleEngine. Also normally in your DI container.
$engine = new ActionEngine(
    $ruleSetProvider,
    new CallableEvaluator(),
    new CallableActionExecutor()
);


// Apply the ruleset to a subject
$subject = new EmailMessage();
$engine->applyRuleSetToSubject('email-ruleset', $subject);
{'fraction_non_alphanumeric': 0.10313611380536696, 'fraction_numerical': 0.0, 'mean_word_length': 3.175438596491228, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '6788776', 'n_tokens_mistral': 893, 'n_tokens_neox': 876, 'n_words': 202}