<commit_before><?php

namespace Gdbots\QueryParser\Visitor;

use Gdbots\QueryParser\Node;

class QueryItemPrinter implements QueryItemVisitorinterface
{
    /**
     * @var integer depth
     */
    private $depth = 0;

    /**
     * @return string
     */
    private function indent()
    {
        return sprintf('%s ', str_repeat('>', $this->depth));
    }

    /**
     * @return void
     */
    private function increaseIndent()
    {
        $this->depth +=1;
    }

    /**
     * @return void
     */
    private function decreaseIndent()
    {
        if ($this->depth > 0) {
            $this->depth -=1;
        }
    }

    /**
     * @param string $line
     */
    private function printIndentedLine($line)
    {
        echo sprintf("%s%s\n", $this->indent(), $line);
    }

    /**
     * {@inheritDoc}
     */
    public function visitWord(Node\Word $word)
    {
        $this->printIndentedLine(sprintf('Word: %s', $word->getToken()));
    }

    /**
     * {@inheritDoc}
     */
    public function visitText(Node\Text $text)
    {
        $this->printIndentedLine(sprintf('Text: %s', $text->getToken()));
    }

    /**
     * {@inheritDoc}
     */
    public function visitExplicitTerm(Node\ExplicitTerm $term)
    {
        if ($term->getNominator() instanceof Node\SimpleTerm) {
            $this->printIndentedLine(sprintf('Term: %s %s %s', $term->getNominator()->getToken(), $term->getTokenTypeText(), $term->getTerm()->getToken()));

        } else {
            $this->printIndentedLine(sprintf('Term: %s %s', $term->getTokenTypeText(), $term->getTerm()->getToken()));
            $this->increaseIndent();

            if ($term->getNominator() instanceof Node\SubExpression) {
                $this->visitSubExpression($term->getNominator());
            } elseif ($term->getNominator() instanceof Node\ExcludeTerm) {
                $this->visitExcludeTerm($term->getNominator());
            } elseif ($term->getNominator() instanceof Node\IncludeTerm) {
                $this->visitIncludeTerm($term->getNominator());
            } elseif ($term->getNominator() instanceof Node\Hashtag) {
                $this->visitHashtag($term->getNominator());
            } elseif ($term->getNominator() instanceof Node\Mention) {
                $this->visitMention($term->getNominator());
            } elseif ($term->getNominator() instanceof Node\ExplicitTerm) {
                $this->visitExplicitTerm($term->getNominator());
            }

            $this->decreaseIndent();
        }
    }

    /**
     * {@inheritDoc}
     */
    public function visitSubExpression(Node\SubExpression $sub)
    {
        $this->printIndentedLine('Subexpression');
        $this->increaseIndent();
        $sub->getExpression()->accept($this);
        $this->decreaseIndent();
    }
<commit_msg>Simplified the print of ExplicitTerm nominator<commit_after><?php

namespace Gdbots\QueryParser\Visitor;

use Gdbots\QueryParser\Node;

class QueryItemPrinter implements QueryItemVisitorinterface
{
    /**
     * @var integer depth
     */
    private $depth = 0;

    /**
     * @return string
     */
    private function indent()
    {
        return sprintf('%s ', str_repeat('>', $this->depth));
    }

    /**
     * @return void
     */
    private function increaseIndent()
    {
        $this->depth +=1;
    }

    /**
     * @return void
     */
    private function decreaseIndent()
    {
        if ($this->depth > 0) {
            $this->depth -=1;
        }
    }

    /**
     * @param string $line
     */
    private function printIndentedLine($line)
    {
        echo sprintf("%s%s\n", $this->indent(), $line);
    }

    /**
     * {@inheritDoc}
     */
    public function visitWord(Node\Word $word)
    {
        $this->printIndentedLine(sprintf('Word: %s', $word->getToken()));
    }

    /**
     * {@inheritDoc}
     */
    public function visitText(Node\Text $text)
    {
        $this->printIndentedLine(sprintf('Text: %s', $text->getToken()));
    }

    /**
     * {@inheritDoc}
     */
    public function visitExplicitTerm(Node\ExplicitTerm $term)
    {
        if ($term->getNominator() instanceof Node\SimpleTerm) {
            $this->printIndentedLine(sprintf('Term: %s %s %s', $term->getNominator()->getToken(), $term->getTokenTypeText(), $term->getTerm()->getToken()));

        } else {
            $this->printIndentedLine(sprintf('Term: %s %s', $term->getTokenTypeText(), $term->getTerm()->getToken()));
            $this->increaseIndent();

            $method = sprintf('visit%s', ucfirst(substr(get_class($term->getNominator()), 24)));
            if (method_exists($this, $method)) {
                $this->$method($term->getNominator());
            }

            $this->decreaseIndent();
        }
    }

    /**
     * {@inheritDoc}
     */
    public function visitSubExpression(Node\SubExpression $sub)
    {
        $this->printIndentedLine('Subexpression');
        $this->increaseIndent();
        $sub->getExpression()->accept($this);
        $this->decreaseIndent();
    }

{'fraction_non_alphanumeric': 0.16825396825396827, 'fraction_numerical': 0.001984126984126984, 'mean_word_length': 2.2314102564102565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 82, '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': '1189183', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1513, 'n_words': 243}